How to edit PK Mode System Message like Real Conquer Online .- TQ.Elgahed

04/16/2012 18:11 TQ-Challenger#1
By the name of the god



========================

[Only registered and activated users can see links. Click Here To Register...]

lets open PacketHandler.cs



and search this code :



PHP Code:
        static void ChangePKMode(Data generalDataClient.GameState client)

        {

            
client.Entity.AttackPacket null;

            
client.Entity.PKMode = (Game.Enums.PKMode)(byte)generalData.dwParam;

            
client.Send(generalData);

        } 




Then replace it with this code





PHP Code:
        #region ChangePKMode

        
static void ChangePKMode(Data generalDataClient.GameState client)

        {

            
client.Entity.AttackPacket null;

            
client.Entity.PKMode = (Game.Enums.PKMode)(byte)generalData.dwParam;

            
client.Send(generalData);

            if (
client.Entity.PKMode == Game.Enums.PKMode.PK)

            {

                
client.Send(new Message("Free PK mode. You can attack monster and all players."System.Drawing.Color.RedMessage.Talk));

            }

            if (
client.Entity.PKMode == Game.Enums.PKMode.Capture)

            {

                
client.Send(new Message("Capture PK mode. You can only attack monsters, black-name and blue-name players."System.Drawing.Color.RedMessage.Talk));

            }

            if (
client.Entity.PKMode == Game.Enums.PKMode.Peace)

            {

                
client.Send(new Message("Peace mode. You can only attack monsters."System.Drawing.Color.RedMessage.Talk));

            }

            if (
client.Entity.PKMode == Game.Enums.PKMode.Team)

            {

                
client.Send(new Message("Team PK mode. You can attack monster and all players except your teammates."System.Drawing.Color.RedMessage.Talk));

            }

        }

        
#endregion 


Done .
04/16/2012 18:48 nTL3fTy#2
This is definitely one of those times you use an if-else if (at least):
Code:
if (client.Entity.PKMode == Game.Enums.PKMode.PK) 
{ 
    client.Send(new Message("Free PK mode. You can attack monster and all players.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Capture) 
{ 
    client.Send(new Message("Capture PK mode. You can only attack monsters, black-name and blue-name players.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Peace) 
{ 
    client.Send(new Message("Peace mode. You can only attack monsters.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Team) 
{ 
    client.Send(new Message("Team PK mode. You can attack monster and all players except your teammates.", System.Drawing.Color.Red, Message.Talk)); 
}
04/16/2012 18:58 Mr_PoP#3
Quote:
Originally Posted by nTL3fTy View Post
This is definitely one of those times you use an if-else if (at least):
Code:
if (client.Entity.PKMode == Game.Enums.PKMode.PK) 
{ 
    client.Send(new Message("Free PK mode. You can attack monster and all players.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Capture) 
{ 
    client.Send(new Message("Capture PK mode. You can only attack monsters, black-name and blue-name players.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Peace) 
{ 
    client.Send(new Message("Peace mode. You can only attack monsters.", System.Drawing.Color.Red, Message.Talk)); 
} 
else if (client.Entity.PKMode == Game.Enums.PKMode.Team) 
{ 
    client.Send(new Message("Team PK mode. You can attack monster and all players except your teammates.", System.Drawing.Color.Red, Message.Talk)); 
}
or switch() case{} ?
04/16/2012 19:19 pro4never#4
was just gonna say...

USE SWITCH!

That being said, he did say at LEAST use if/elseif which makes him correct anyways :P
04/16/2012 20:35 Korvacs#5
Don't use a switch, switches perform worse than if/else at lower iterations like this.
04/16/2012 21:13 Spirited#6
Or... just have one statement and use a string array to tell the client what message to display.
04/16/2012 21:37 pro4never#7
Quote:
Originally Posted by Korvacs View Post
Don't use a switch, switches perform worse than if/else at lower iterations like this.
Interesting, at what point does switch become more efficient? or is it one of those things used more for aesthetic appeal then actual performance? I for some reason had it in my mind that switch became more efficient after a fairly low number of if/else if statements but I'm probably wrong.
04/16/2012 22:37 Spirited#8
Quote:
Originally Posted by pro4never View Post
Interesting, at what point does switch become more efficient? or is it one of those things used more for aesthetic appeal then actual performance? I for some reason had it in my mind that switch became more efficient after a fairly low number of if/else if statements but I'm probably wrong.
Here's my opinion on it:
I did a little research, and in the long run (depending on how many cases the statement is checking...) if else statements perform the worst. In situations where there are less than 5 cases being checked, an if-else structure performs the best. However, when you're dealing with that little of a switch, you should always consider how to write it as one statement.

This is how I'd do it:
client.Send(new ClientMessage(PkNotifications[generalAction.PrimaryAction], ChatTone.System).ToPointer());
04/16/2012 22:53 nTL3fTy#9
Quote:
Originally Posted by Fаng View Post
This is how I'd do it:
client.Send(new ClientMessage(PkNotifications[generalAction.PrimaryAction], ChatTone.System).ToPointer());
What happens if I'm on a proxy and send PKMode 50?
04/16/2012 23:13 pro4never#10
Quote:
Originally Posted by nTL3fTy View Post
What happens if I'm on a proxy and send PKMode 50?
While I'm sure he'd account for this... it does make it a less elegant solution when you add in all sorts of error checking.
04/16/2012 23:45 Spirited#11
Quote:
Originally Posted by nTL3fTy View Post
What happens if I'm on a proxy and send PKMode 50?
I check the range before I even assign it. I'm showing you the message line, not how I assign everything.
04/17/2012 00:01 nTL3fTy#12
Quote:
Originally Posted by Fаng View Post
I check the range before I even assign it. I'm showing you the message line, not how I assign everything.
I was going on the assumption that generalData was your packet instance and PrimaryAction was a field in the packet. Considering that, it seemed as though you were just taking the field from the packet with no range checks. If this isn't correct, I'm clearly confused.
04/17/2012 00:08 Mr_PoP#13
well use switch.
In the worst case the compiler will generate the same code as a if-else chain, so you don't lose anything. If in doubt put the most common cases first into the switch statement.

In the best case the optimizer may find a better way to generate the code. Common things a compiler does is to build a binary decision tree (saves compares and jumps in the average case) or simply build a jump-table (works without compares at all).
04/17/2012 00:11 Korvacs#14
Quote:
Originally Posted by pro4never View Post
Interesting, at what point does switch become more efficient? or is it one of those things used more for aesthetic appeal then actual performance? I for some reason had it in my mind that switch became more efficient after a fairly low number of if/else if statements but I'm probably wrong.
Test i've read show that it varies under different circumstance, and your own benchmark will also show this most likely, the general rule of thumb is that if the number of conditions is 5 or more then use a switch as the switch will use a Hashtable which adds a reasonable amount of overhead (lookup + jump), otherwise in basically all cases if/else would be preferred.
04/17/2012 00:31 Spirited#15
Quote:
Originally Posted by nTL3fTy View Post
I was going on the assumption that generalData was your packet instance and PrimaryAction was a field in the packet. Considering that, it seemed as though you were just taking the field from the packet with no range checks. If this isn't correct, I'm clearly confused.
That's correct. I'm using the general packet like everyone else does ... I error check it BEFORE I handle it. If it's correct, I use the data in the packet. Problem? :confused: