PDA

View Full Version : Help with Code (commands)


jakejohnsonusa
24/11/2012, 02:15 PM
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:
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***

[HK]Ryder[AN]
24/11/2012, 02:17 PM
try this
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;
}

Vince
24/11/2012, 02:18 PM
if (strcmp("/detectoroff", cmdtext, true, 10) == 0)
Learn your parameters!

jakejohnsonusa
24/11/2012, 02:22 PM
Wait I'm new to this... what does that do?

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

jakejohnsonusa
24/11/2012, 02:25 PM
-IGNORE THIS-