Save Guild Enemies/Allies

08/28/2010 06:06 Arcо#1
First and foremost this is for 5165 Tanel source. NewestCOServer.

Well first define this in features/guilds.cs under public class Guild
Code:
        public Dictionary<uint, string> Allies = new Dictionary<uint, string>();
        public Dictionary<uint, string> Enemies = new Dictionary<uint, string>();
Code:
        public static void CreateNewGuild(string GName, ushort GID, Character Creator)
And at the bottom of this void, put this
Code:
            G.Allies.Add(0, "");
            G.Enemies.Add(0, "");
Scroll down you should see this
Code:
        public void SaveThis(BinaryWriter BW)
At the bottom, under BW.Write(Wins);
insert this,
Code:
            BW.Write((int)Allies.Count);
            foreach (KeyValuePair<uint, string> kvp in Allies)
            {
                BW.Write(Convert.ToUInt32(kvp.Key));
                BW.Write(Convert.ToString(kvp.Value));
            }
            BW.Write((int)Enemies.Count);
            foreach (KeyValuePair<uint, string> kvp in Enemies)
            {
                BW.Write(Convert.ToUInt32(kvp.Key));
                BW.Write(Convert.ToString(kvp.Value));
            }
Next scroll down to public Guild(BinaryReader BR) and under
Wins = BR.ReadUInt32();
insert this
Code:
            int a = BR.ReadInt32();
            {
                for (int i = 0; i < a; i++)
                    Allies.Add(BR.ReadUInt32(), BR.ReadString());
            }
            int e = BR.ReadInt32();
            {
                for (int i = 0; i < e; i++)
                    Enemies.Add(BR.ReadUInt32(), BR.ReadString());
            }
And bam, loading and saving.
To add to the dictionary it is GuildID then GuildName.
08/28/2010 06:49 koko425#2
thanks but i get this error
[Only registered and activated users can see links. Click Here To Register...]

and how to add it in npc to make Enemies
08/28/2010 07:01 Arcо#3
Make sure your server is off, delete guilds.dat. and then start the server, create a guild, and see if it works.

And as of adding the enemies via npc, just make the npc add the enemy ID and Name.
08/28/2010 10:49 2087#4
Ye it works :)
You'll just have to delete your Guilds.dat

Well, i'll try ( bet i wont get it omg ^^ ) to write the code for the npc - i'll let you know if it works.

BIG THANKS! (Y)
08/28/2010 11:52 NukingFuts#5
booooo @ arco rofl jks great work bro :)
08/28/2010 13:10 nTL3fTy#6
Quote:
Originally Posted by .Arco View Post
At the bottom, under BW.Write(Wins);
insert this,
Code:
            BW.Write((int)Allies.Count);
            foreach (KeyValuePair<uint, string> kvp in Allies)
            {
                BW.Write(Convert.ToUInt32(kvp.Key));
                BW.Write(Convert.ToString(kvp.Value));
            }
            BW.Write((int)Enemies.Count);
            foreach (KeyValuePair<uint, string> kvp in Enemies)
            {
                BW.Write(Convert.ToUInt32(kvp.Key));
                BW.Write(Convert.ToString(kvp.Value));
            }
Why convert uint to uint and string to string? I don't get it.
Code:
            BW.Write((int)Allies.Count);
            foreach (KeyValuePair<uint, string> kvp in Allies)
            {
                BW.Write(kvp.Key);
                BW.Write(kvp.Value);
            }
            BW.Write((int)Enemies.Count);
            foreach (KeyValuePair<uint, string> kvp in Enemies)
            {
                BW.Write(kvp.Key);
                BW.Write(kvp.Value);
            }
08/28/2010 15:44 Arcо#7
Quote:
Originally Posted by nTL3fTy View Post
Why convert uint to uint and string to string? I don't get it.
Code:
            BW.Write((int)Allies.Count);
            foreach (KeyValuePair<uint, string> kvp in Allies)
            {
                BW.Write(kvp.Key);
                BW.Write(kvp.Value);
            }
            BW.Write((int)Enemies.Count);
            foreach (KeyValuePair<uint, string> kvp in Enemies)
            {
                BW.Write(kvp.Key);
                BW.Write(kvp.Value);
            }
I don't know either man :/
But it didn't work till I did that.
I would keep getting "Cannot read to end of stream." error.
But once I did that, it worked.
08/28/2010 16:08 killersub#8
so....what would be a good example of how it might look like in an npc :rolleyes:?
08/28/2010 16:17 dowhatuwant#9
I think u just won :P
08/28/2010 16:23 .Beatz#10
The NPC you already have should be fine for the allys/enemys just add this code into the NPC under Disband. Not sure if this will work for you but it works for me and has done for a while now. All you should need to do is change a few things.
NOTE! : This is JUST Allys you should be able to work out enemys for yourself.
Code:
#region Ally
                                    if (option == 20)
                                    {
                                        Say("Who would you like to ally?", GC);
                                        Link2("Ally", 21, GC);
                                        Done(30, GC);

                                    }
                                    if (option == 21)
                                        if (GC.MyChar.MyGuild != null && GC.MyChar.GuildRank == MayaCo.Features.GuildRank.GuildLeader)
                                        {
                                            string Ally = ReadString(Data);
                                            foreach (Features.Guild g in Features.Guilds.AllTheGuilds.Values)
                                            {
                                                if (g.GuildName == Ally)
                                                {
                                                    if (g.Creator.Info != null)
                                                    {
                                                        if (g.Creator.Info.MyTeam.Members.Contains(GC.MyChar.EntityID))
                                                        {
                                                            if (!GC.MyChar.MyGuild.Allies.ContainsValue(Ally))
                                                            {
                                                                GC.MyChar.MyGuild.AddAlly(Ally);
                                                                GC.AddSend(Packets.String(g.GuildID, 21, Ally));
                                                                Say(g.GuildName + " is now your ally!", GC);
                                                                Link("Thanks.", 255, GC);
                                                            }
                                                            else
                                                            {
                                                                Say(g.GuildName + " is already your ally.", GC);
                                                                Link("Damn.", 255, GC);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            Say("Make sure the guild leader of the Features guild is in your team.", GC);
                                                            Link("Okay", 255, GC);
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    #endregion
If this doesn't work for you I will recode it using Tanels source.
08/28/2010 16:26 Arcо#11
@Matty
Haha straight out of my source I gave you >.<
08/28/2010 16:31 killersub#12
Quote:
Originally Posted by .Arco View Post
@Matty
Haha straight out of my source I gave you >.<
dont worry >.< hes a very good friend and trust me he doesnt leech LOL...
08/28/2010 16:36 .Beatz#13
Quote:
Originally Posted by .Arco View Post
@Matty
Haha straight out of my source I gave you >.<
Whoops posted the wrong one lmao. Got one in my other source that I use lol.
08/28/2010 17:00 copz1337#14
I get an error on these 2 lines:
Code:
            G.Allies.Add(0, "");
            G.Enemies.Add(0, "");
The error is "Cannot use local variable 'G' before it is declared".
08/28/2010 17:01 Arcо#15
Quote:
Originally Posted by copz1337 View Post
I get an error on these 2 lines:
Code:
            G.Allies.Add(0, "");
            G.Enemies.Add(0, "");
The error is "Cannot use local variable 'G' before it is declared".
o.o Where are you putting it?
Are you putting in inside of the void?