SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/02/2020, 08:11 PM   #1
MarikAshtar
Little Clucker
 
Join Date: Mar 2015
Posts: 26
Reputation: 3
Default Multiparam Command

Hello,

Making a command like /vehicle with options: engine, lights, etc..
Do I have to do like:
pawn Code:
if(!strcmp(option, "engine"))
{
    // Engine stuff
}
else if(!strcmp(option, "lights"))
{
    // Lights stuff
}
else if(!strcmp(option, "lock"))
{
    // Lock stuff
}
or can I do it like
pawn Code:
if(!strcmp(option, "engine"))
{
    // Engine stuff
}
if(!strcmp(option, "lights"))
{
    // Lights stuff
}
if(!strcmp(option, "lock"))
{
    // Lock stuff
}
Without the "else"? Both seem to work but in my experience you don't always need an error code to be "wrong"
MarikAshtar is offline   Reply With Quote
Old 16/02/2020, 08:18 PM   #2
Calisthenics
High-roller
 
Join Date: May 2018
Posts: 1,096
Reputation: 175
Default Re: Multiparam Command

If the option given is "engine", each `if` statement will be checked (3 checks). It is unnecessary, so use `else if` to check only once.
__________________
Calisthenics is offline   Reply With Quote
Old 16/02/2020, 08:23 PM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,530
Reputation: 1642
Default Re: Multiparam Command

What Calisthenics said ^
Alternatively, you can add a return; to break the entire function (in this case, the command). For example (note how I return 1 here, otherwise the script most likely assumes it's an unknown command:

Code:
if(!strcmp(option, "engine"))
{
    // Engine stuff
    return 1;
}
if(!strcmp(option, "lights"))
{
    // Lights stuff
    return 1;
}
if(!strcmp(option, "lock"))
{
    // Lock stuff
    return 1;
}
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 16/02/2020, 08:32 PM   #4
MarikAshtar
Little Clucker
 
Join Date: Mar 2015
Posts: 26
Reputation: 3
Default Re: Multiparam Command

Thank you!
MarikAshtar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with YCMD proces command and problem with "Server:Unknown command JoDe Scripting Help 1 20/04/2018 12:12 PM
[Plugin] mcmd Command Engine - Plugin based command processing Mellnik Plugin Development 108 08/05/2016 01:55 PM
i had this command in my gamemode, when i type this in game,it tells server unknow command? Chrisli520 Scripting Help 3 24/11/2013 10:02 AM
Executed ZCMD command returns SERVER: Unknown Command SexTourist Scripting Help 12 03/01/2012 03:38 PM
Slap command returns an Unknown Command when player is not connected HydraX Help Archive 16 01/08/2011 05:19 AM


All times are GMT. The time now is 07:38 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.