PDA

View Full Version : Chat functions


xAndrewx
05-29-2007, 06:42 PM
function onActionServerside(playersChat)
{
temp.chatTokens = temp.playersChat.tokenize();
switch(temp.chatTokens[0])
{
case "help":
player.displayHelp();
return true;

case "summon":
findplayer(temp.playersChat.substring(7)).setlevel 2(player.level.name, player.x, player.y);
return true;

case "addItem":
player.addItem(temp.chatTokens[1], temp.chatTokens[2]);
break;

case "removeItem":
player.removeItem(temp.chatTokens[1], temp.chatTokens[2]);
break;

case "gani":
setani(temp.playersChat.substring(4), "");
break;

case "clear":
//Place holder [-systemMessages]
break;

default:
temp.displayMessage = "No such command...";
break;
}
if (temp.displayMessage)
{
player.addMessage("No such command!", "-system");
}
}

//#CLIENTSIDE
function onPlayerChats()
{
if (!disableChat)
{
if (player.chat.starts("/"))
{
triggerserver("weapon", this.name, player.chat.substring(1));
player.chat = " ";
}
}
else
{
player.chat = " ";
}
}

Here's a basic chat function thing

cbk1994
05-31-2007, 01:36 AM
Looks like there are a few things that may only work on a certain server ...

addItem, removeItem, disableChat.

Personally, I'd make an array of commands so if someone says /OMGHEHELOLSAKGJHAKSJGHSKDGJHSKDJGHSKGLJHSGJKSGH it wouldn't trigger.

xAndrewx
05-31-2007, 10:38 AM
They're just examples of how it functions.

cbk1994
05-31-2007, 12:36 PM
They're just examples of how it functions.
So all it is is a frame for a trigger? You could just do:


function onActionServerSide( cmd, tokens )
{
switch ( cmd )
{
case "test":
{
// FOO
break;
}
}
}
//#CLIENTSIDE
function onPlayerChats()
{
if ( ! player.chat.starts( "/" ) )
{
return false;
}
tokens = player.chat.tokenize();
triggerServer( "gui", name, tokens );
}

xAndrewx
05-31-2007, 04:00 PM
No, as in it can also be a command line...

Kristi
06-01-2007, 04:07 PM
So all it is is a frame for a trigger? You could just do:


function onActionServerSide( cmd, tokens )
{
switch ( cmd )
{
case "test":
{
// FOO
break;
}
}
}
//#CLIENTSIDE
function onPlayerChats()
{
if ( ! player.chat.starts( "/" ) )
{
return false;
}
tokens = player.chat.tokenize();
triggerServer( "gui", name, tokens );
}


He COULD have done that, or he could have provided his example, which provides a more hands on experience for the learning scripter. With his example, someone can go OH THATS WHY YOU WOULD DO THAT, whereas with yours, someone might miss the reason entirely.

There was really nothing wrong with what he proposed, and it seems like everytime I come to the scripting forum, every thread leads into an argument to boast/destroy e-pride. Play nice k?