Cheat codes

so, I have this game with a fully functional chat in multiplayer, and I want to add cheat codes to give the player advantages. i want to be able to input the cheat into chat to initiate the cheat.

Any help is appreciated.

1 Like

Since you have a fully functional chat already I will assume you can take the chat string right before sending it to chat. Generally its on the server where the cheats are applied.

But the basics to creating the cheat command you want is generally like this.

/someCommand someParameter1 someParameter2…

where first you check the first character for the escape character. in this case it would be /

Than you either make a switch statement to call a function or fire off the following command. With the following however you want to enter your parameters.

So it would end up with something like


if(text.charAt(0) == escapeChar); //This is a quick check to not slow down your current chat system.  Since if there is no escape character its not a cheat.
{
   var cheatString = text.slice(1); //Remove escapeChar from processing
   var cheatTokens = cheatString.match(/\S+/g); //match magic to break out the string into tokens
   
 //Option 1 - Have each cheat register to the event Cheats to process the end result based on the remaining token information in the string.
 this.app.fire("Cheats", cheatToken);

//Option 2 - switch statement. to verify that its a valid command otherwise ignore it and send to chat.

switch(cheatTokens[0])
{
    case "someCommand":
       this.someCommand(cheatTokens); 
        break;
    default:
        chat(text);

}

 
}
else
{
    chat(text);
}
3 Likes

if you may, I would like to add you to my project as admin to demonstrate this. i will set a backup save just in case anything goes wrong. that is if you would like to join my team, and help with the development of the game.

If you are willing to join please tell me your username on the website so i can add you as admin. if you are not joining, thank you for your help, and time.

ok. first the username is the one that shows on your profile or by your picture in your post.