"GM" Tags before player names

13 replies [Last post]
Posts: 1030

I'd like to add a [GM] tag in front of characters who are GMs (red for admin, purple for lesser, etc)

How exactly should I do this? I'm guessing the client doesn't know the privileges level of a character so I guess I'll have to send some extra information for each character so the client knows if it should draw the tags?

Anyone care to explain a bit how I can do this? (How do I add the extra information to a packet, how to process it with the client, where to add the extra drawing code, ..)

Posts: 1691

You can probably do it with [SyncValue]. Just put the property in DemoGame.Character instead of Server.User so both the client and server see it. NetGore should handle the rest.

Posts: 1030

Okay, I'll give it a go tomorrow or so. Where's the code that draws character names?

Posts: 95

O.k I'm doing this as I go along so bare with me

server packets add the following:

       public static PacketWriter SetAdmin(int admin)
        {
            var pw = GetWriter(ServerPacketID.SetAdmin);
            pw.Write(faction);
            return pw;
        }

ServerPacketID add the following
SetAdmin,

ClientPacketHandler

        [MessageHandler((uint)ServerPacketID.SetFaction)]
        void RecvSetFaction(IIPSocket conn, BitStream r)
        {
            var faction = r.ReadInt();
            UserInfo.faction = faction;
        }

DemoGame.Server.User
find // Send the initial information
Add

 using (var pw = ServerPacket.SetAdmin(Permissions))
            {
                Send(pw, ServerMessageType.GUIUserStats);
            }

UserInfo
Add public static int Admin { get; set; }

your client will now have what admin level your player is from this we can do some stuff like the following

Go to public void Draw(ISpriteBatch sb) in Demogame.client.character
Remove
DrawName(sb, NameFont)

Add in the following

if (UserInfo.admin == 1)
                    DrawName(sb, NameFont, Color.Red);
if (UserInfo.admin == 2)
                  DrawName(sb, NameFont, Color.Aqua);

then find protected virtual void DrawName(ISpriteBatch sb, Font font)
Change to protected virtual void DrawName(ISpriteBatch sb, Font font, Color colorName)

Find // Draw players name
change line below to
sb.DrawStringShaded(font, Name, namePos, colorName, Color.Black);

that should be everything

EDIT
or you could do it spodi's way which seems easier >.< now if you'll excuse me I'm going to crawl back into my hole that is cataclysm yay for WoW

Posts: 1030

Spodi wrote:
You can probably do it with [SyncValue]. Just put the property in DemoGame.Character instead of Server.User so both the client and server see it. NetGore should handle the rest.

Could you specify where that is? Because I can't seem to find any Character folder or cs file in the DemoGame project.

Posts: 1691

\NetGore\DemoGame.Client\World\Map\Entities\Character.cs

Or could just search for "class Character". Wink

Posts: 1030

Yeah I found those eventually, so... what do I do there? >_> Don't see any other examples I can follow.

EDIT:

Thanks to Zidsal I found it I think. It was CharacterEntity.cs and User.cs, was looking in Character.cs >_>

EDIT2:
It's throwing an error:
No PropertySyncHandler exists for type `DemoGame.UserPermissions`. You must define a class to handle this type (preferably derived from PropertySyncBase) and give it the PropertySyncHandlerAttribute.

Posts: 1030

Bump in case you didn't see the edit :3

Posts: 1691

You have to define a class for each type the PropertySync is used on so it knows how to serialize. Just copy PropertySyncSpriteEffects and rename accordingly.

Posts: 1030

So I need a typeof(UserPermissions) in the class, problem is UserPermissions is in the Demogame namespace but I can't seem to do "using Demogame;"

Any ideas?

Posts: 1691

Don't put it in the NetGore project, then? Tongue

Define it in the same scope as the enum itself. So, define it in DemoGame.

Posts: 1030

Kind of confused here, you want me to make the PropertySyncUserPermissions.cs file in the Demogame folder?

Posts: 1691

Yep. The class is automatically discovered and instantiated through reflection, so by placing it in the same project with the same visibility of the type you are defining it for, you can use the [PropertySync] anywhere that the type is accessible. Its one of those things that "just work".

Posts: 1030

Sigh I give up. After getting rid of a dozen more errors popping up it doesn't do anything >_>
Also I couldn't delete the part in the User.cs of the server because it starts whining about it not finding the Permissions method.

I'm going to spend my first 500 CP on this one, hopefully you can fulfill it then since you practically said what to do (besides some stuff you probably didn't think of unless you code it yourself).

Someone go get a bounty Tongue http://www.netgore.com/cp