Author Topic: Correct Command Check  (Read 1369 times)

Ahmed Abouelnas

  • Newbie
  • *
  • Posts: 39
  • Karma: +2/-11
  • Ahmed Abouelnas
    • View Profile
Correct Command Check
« on: June 26, 2014, 01:04:46 pm »
Anyone Could Help Me
I am Trying To Get A Correct Command Or Incorrect Command Script
Code: [Select]
function onPlayerCommand( pPlayer, szCommand, szText )
{
if ( szCommand == "info" || szCommand == "wanted" || szCommand == "setteam1" || szCommand == "setteam2" || szCommand == "team1" || szCommand == "team2" || szCommand == "spawn" || szCommand == "get200" || szCommand == "pr" || szCommand == "freeze" || szCommand == "wantof" || szCommand == "unfreeze" || szCommand == "mute" || szCommand == "unmute" || szCommand == "setwant1" || szCommand == "setwant2" || szCommand == "setwant3" || szCommand == "setwant4" || szCommand == "setwant5" || szCommand == "setwant6" || szCommand == "setwant0" || szCommand == "1" || szCommand == "mos1" || szCommand == "mos2" || szCommand == "amro1" || szCommand == "amro2" || szCommand == "2" || szCommand == "vehlist" || szCommand == "garages" || szCommand == "srl" || szCommand == "srr" || szCommand == "sfl" || szCommand == "sfr" || szCommand == "exp" || szCommand == "taxion" || szCommand == "taxioff" || szCommand == "open" || szCommand == "close" || szCommand == "busy" || szCommand == "online" || szCommand == "vehghoston" || szCommand == "ghoston" || szCommand == "vehghostoff" || szCommand == "ghostoff" || szCommand == "send" || szCommand == "b+" || szCommand == "bank+" || szCommand == "wire" || szCommand == "sp" || szCommand == "st" || szCommand == "spawnscreen" || szCommand == "addon1" || szCommand == "addon2" || szCommand == "addon3" || szCommand == "want1" || szCommand == "want2" || szCommand == "want3" || szCommand == "want4" || szCommand == "want5" || szCommand == "want6" || szCommand == "saveloc" || szCommand == "gotoloc" || szCommand == "out" || szCommand == "cash" || szCommand == "my+" || szCommand == "bank" || szCommand == "login" || szCommand == "register" || szCommand == "autologin" || szCommand == "logout" || szCommand == "skin" || szCommand == "score" || szCommand == "sc1" || szCommand == "cmds" || szCommand == "mycmds" || szCommand == "stop" || szCommand == "start" || szCommand == "/" || szCommand == "aeroport" || szCommand == "airport" || szCommand == "parc" || szCommand == "rep" || szCommand == "admins" || szCommand == "ann" || szCommand == "l1" || szCommand == "l2" || szCommand == "lock" || szCommand == "lock1" || szCommand == "lock2" || szCommand == "wep" || szCommand == "heal" || szCommand == "arm" || szCommand == "msg" || szCommand == "veh" || szCommand == "mypos" || szCommand == "goto" || szCommand == "speedo" || szCommand == "nogoto" || szCommand == "blipon" || szCommand == "blipoff" || szCommand == "col1" || szCommand == "col2" || szCommand == "anim" || szCommand == "msgs" || szCommand == "kick" || szCommand == "ban" || szCommand == "sun" || szCommand == "fog" || szCommand == "cloud" || szCommand == "storm" || szCommand == "rain" || szCommand == "stm" || szCommand == "se" || szCommand == "wea" )
{
MessagePlayer( "Correct Command", pPlayer, Colour( 0, 255, 0 ) )
}
else
{
MessagePlayer( "Invalid Command Type /cmds or ask for help", pPlayer, Colour( 255, 0, 0 ) )
}

return 1;
}
I've Made This But It's Too Hard To Write Every Command On My Server
Any Suggestions.................

ThNx In Advance

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Re: Correct Command Check
« Reply #1 on: June 26, 2014, 03:07:55 pm »
Hard? Lol?

Why you use many 'onPlayerCommand' and not in only one?
Westwood Studios

The best studios company in strategy videogames.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Correct Command Check
« Reply #2 on: June 26, 2014, 08:29:18 pm »
Make a table of all your commands, like this:
Code: [Select]
Commands <- { "command1" , "command2" , "command3" }
Then, see if the command matches one of them, like this:
Code: [Select]
function onPlayerCommand( player , command , params )
{
if( command in Commands )
{
// Correct Command
}
else
{
// Incorrect Command
}

return 1;
}

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Correct Command Check
« Reply #3 on: June 27, 2014, 12:57:40 pm »
Why on earth would you do it like that?

Just use a switch or lot's of if's, and add an default or else.

Code: [Select]
function onPlayerCommand( pPlayer, szCommand, szText )
{
cmd = szCommand.tolower();
if ( cmd == 'info' )
{
//Some code
}
else if ( cmd == 'wanted' )
{
//Some code
}
else
{
MessagePlayer( 'Invalid command', pPlayer );
}
Code: [Select]
function onPlayerCommand( pPlayer, szCommand, szText )
{
cmd = szCommand.tolower();
switch ( cmd ) {
case 'info':
//Some code
break;
case 'wanted':
//Some code
break;
default:
MessagePlayer( 'Invalid command', pPlayer );
break;
}
}

 

© Liberty Unleashed Team.