Game Development Community

Please revise my script.

by Kevin Anonymous · in Torque Developer Network · 03/19/2010 (6:01 pm) · 0 replies

Hi, Im newer to C++, but I made this script that works on Torque. When the user says Jeepbot (Command here) it will carry out the command. BUT, if the user types anything (EX: Jeepbot hi bla), the game will crash. If you could revise my script, that would be great.

Thanks,
Kevin

<--------------Code--------------->

//Bugs:
//-1- Cannot have a word after (--CRASH--)
//-2- Text Color is RED (--ANNOYANCE--)
exec("./commands.cs");
exec("config/server/ATBotATBotPrefs.cs");
function serverCmdmessageSent(%client, %text)
{
if(getWord(%text,0) $= "Jeepbot") //<<There is the big line of the code<<
{
if(%client.lastATBotCommand + 0.01 > $sim::time)
return;

%command = getWord(%text, 1);
%args = getWords(%text, 2, getWordCount(%text)-2);

%lastCommand = %client.lastATBotCommand;
%client.lastATBotCommand = $sim::time;

if(isFunction("ATBot_" @ %command @) == 0)
messageClient(%client, '', "c6<color:F9FF42>Jeep Bot<color:FFFFFF>: Sorry, Im not sure I understand the command 'c3" @ %command @ "c6'.");
else
call("ATBot_" @ %command, %client, %command, %args);
%client.lastATBotCommand = %lastCommand;
}

return;
}

if(isObject(%client.player) && isObject(%client.ATBotTrigger) && isObject(%client.ATBotTrigger.parent) && %client.ATBotTrigger.parent.getDatablock().ATBotBrickType == 2)
{
if(%client.lastATBotCommand + 0.01 > $sim::time)
{
return;

}

%client.ATBotTrigger.parent.getDatablock().parseData(%client.ATBotTrigger.parent, %client, "", %text);

%client.lastATBotCommand = $sim::time;

return;
//Hold

//Took out the fancy Jail Command, its in needed.
}


messageAll('',stripMLControlChars("c3 <color:FBFF00>"@%client.name@"<color:FFFFFF>: "@%text));


return;

}

About the author

Recent Threads