SA-MP Forums Archive
switch - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: switch (/showthread.php?tid=293440)



switch - Speed - 28.10.2011

I have this command:

pawn Код:
CMD:test(playerid, params[])
{
    new location;
    if(sscanf(params, "i", location))return SendClientMessage(playerid, -1, "Usage: /test [location]");
Can i do in this command something like this:

pawn Код:
CMD:test(playerid, params[])
{
    new location;
    if(sscanf(params, "i", location))return SendClientMessage(playerid, -1, "Usage: /test [location]");
    switch(location)
    {
        case 0:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        case 1:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        ...
        case 5:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        return 1;
}
Is this coretly and is this gonna work?


Re: switch - park4bmx - 28.10.2011

EDIT:
you got your answer


Re: switch - Speed - 28.10.2011

x,y,z => is coordinat and I didnt publish coordinat i type x,y,z it is easier to explain i will add it leater i dont have this command but i want to do something close to that so i ask is this a good way for "switch" or isnt...


Re: switch - FUNExtreme - 28.10.2011

Yes, it is correct. Although I would add a little check like:

pawn Код:
if(location < 0 && location > YOURMAXIMUMAMOUNOFLOCATIONS)
that way you could send the player a message saying that he is using an incorrect idea. Just a little thing but it might be useful


Re: switch - iggy1 - 28.10.2011

'switch' is faster than 'ifs' if there are more than 2 checks. So your version is fine and is probably the best way to do it.

EDIT: About the above post you can achieve that in a switch with the default case.