Game Development Community

dev|Pro Game Development Curriculum

Implementing a simple cheat system

by Steve Howson · 11/13/2006 (4:42 pm) · 2 comments

Please note: This is only for one cheat as that's all I've done in my testing so far. Should be very simple to have it check for multiple values and call functions or run code as needed.

I created a new server script called cheats.cs in the /server/scripts directory. In it I have the following code for my one cheat:

function ServerCmdcheater(%client, %code)
{
    if (%code $= "ammo")
    {
        %client.player.setInventory(SnowballAmmo, 100);
    }
    else
    {
        echo(%code);
    }
}

After that I added the following into game.cs:
exec("./cheats.cs");

Then I created a new gui interface (called 'cheat') with a guiTextEdit control and and two guiButtonCtrls on it. One button is a close button that does a Canvas.popDialog(cheat);, the other button calls the cheat function above and passes the value typed into the guiTextEdit control:

commandToServer('cheater', cheatText.getValue());

I then set up a key in default.bind.cs to push the dialog:

function activateCheat(%val)
{
    if (%val)
        Canvas.pushDialog(cheat);
}

moveMap.bind(keyboard, semicolon, activateCheat);

That's all I have so far, very simple but should be easy enough to modify as needed.

I hope that helps someone! :)

#1
04/02/2007 (2:07 am)
Great resouce, thanks Steve
#2
10/05/2009 (8:12 am)
thank u man... this source is very helpful