SA-MP Forums Archive
Help with Code (commands) - 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: Help with Code (commands) (/showthread.php?tid=394897)



Help with Code (commands) - jakejohnsonusa - 24.11.2012

What did I do wrong with the following code, when I do /detectoron everything works fine. If I do /detector off it does the same things as detector on. Can someone tell me how to fix this?

Here is the code:
pawn Код:
new DetectorTimer[MAX_PLAYERS];
    if (strcmp("/detectoron", cmdtext, true, 10) == 0)
    {
        if(PlayerInfo[playerid][pDetector])
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                if(DetectorTimer[playerid] != -1) KillTimer(DetectorTimer[playerid]);//
                SetTimerEx("RunDetector", 2000, true, "i", playerid);
                SendClientMessage(playerid,-1,"Detector On");
                return 1;
            }
            SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
            return 1;
        }
        SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
        return 1;
    }
    if (strcmp("/detectoroff", cmdtext, true, 10) == 0)
    {
        if(PlayerInfo[playerid][pDetector])
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                SendClientMessage(playerid,-1,"Detector OFF");
                KillTimer(DetectorTimer[playerid]);
                return 1;
            }
            SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
            return 1;
        }
        SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
        return 1;
 }
***The indentation is correct in the first lines, the site is not displaying it right***


Re: Help with Code (commands) - [HK]Ryder[AN] - 24.11.2012

try this
pawn Код:
new DetectorTimer[MAX_PLAYERS];
    if (strcmp("/detectoron", cmdtext, true, 10) == 0)
    {
        if(PlayerInfo[playerid][pDetector])
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                if(DetectorTimer[playerid] != -1) KillTimer(DetectorTimer[playerid]);//
                DetectorTimer[playerid] = SetTimerEx("RunDetector", 2000, true, "i", playerid);
                SendClientMessage(playerid,-1,"Detector On");
                return 1;
            }
            SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
            return 1;
        }
        SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
        return 1;
    }
    if (strcmp("/detectoroff", cmdtext, true, 10) == 0)
    {
        if(PlayerInfo[playerid][pDetector])
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                SendClientMessage(playerid,-1,"Detector OFF");
                KillTimer(DetectorTimer[playerid]);
                return 1;
            }
            SendClientMessage(playerid, COLOR_GREY, "** You aren't in a vehicle!");
            return 1;
        }
        SendClientMessage(playerid, COLOR_GREY, "** You don't have a Radar Detector!");
        return 1;
 }



Re: Help with Code (commands) - Vince - 24.11.2012

Код:
if (strcmp("/detectoroff", cmdtext, true, 10) == 0)
Learn your parameters!


Re: Help with Code (commands) - jakejohnsonusa - 24.11.2012

Wait I'm new to this... what does that do?

Would it be set to 11 because there are 11 letters in it?


Re: Help with Code (commands) - jakejohnsonusa - 24.11.2012

-IGNORE THIS-