1 - function servercmdeat(%client,%object)
{
2 - switch(%object)
3 - {
4 - case "pizza":
5 - messageAll('','\c3%1\c5 has eaten a slice of pizza.',%client.name);
//perhaps do other things e.g. restore health
6 - default:
7 - messageClient(%client,'','\c3%1\c5 isn't one of the available food types. Type \c3/eathelp\c5 for a list of food.',%object);
}
}
1 - %object is set to the first word of whatever the client types
2 - A switch statement can be used to check a variable against several different 'cases'.
3 - The switch statement is contained in a 'block' of code in these braces. { }
4 - This part will be called if they use "/eat pizza". Add other 'cases' for different food types.
5 - This will message everyone in the server with that. %1 is in yellow (due to the \cX colours) is replaced with the client's name.
6 - This will be called if they say anything which isn't in a case.
7 - This messages the client with an error. %1 is replaced with the what they typed.