Help editing this Radar Detector Command -
jakejohnsonusa - 22.11.2012
Ok so someone helped me put together this Radar Detector command (it will detect Poice Officers in the area).
My question is how can I make it constantly check when they type /detector instead of just doing one check. I want it so that /detector begins checking and /detectoroff stope the detection. I think I need to make a timer for this, but I have no idea how to. I also want it to be on a player message and not a dialoge. Can someone help me finish this code?
Thanks: jakejohnsonusa
Here is what I have:
pawn Код:
if (strcmp("/detector", cmdtext, true, 10) == 0)
{
new counter = 0, player[268];
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
{
counter++;
}
}
if(counter == 0) return SendClientMessage(playerid, 0xFF0000FF, "No one is in your range.");
strdel(string, 0, strlen(string));
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
{
format(player, sizeof(player), "%s (%d)\n", Nick(i), i);
strins(string, player, strlen(string), sizeof(string));
}
}
ShowPlayerDialog(playerid, 1592, DIALOG_STYLE_MSGBOX, "Radar", string, "Okay", "");
strdel(string, 0, strlen(string));
return 1;
}
pawn Код:
stock Nick(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
Re: Help editing this Radar Detector Command -
jakejohnsonusa - 24.11.2012
Anyone know?
Re: Help editing this Radar Detector Command -
park4bmx - 24.11.2012
put the current code into a
public
then just run a
TimerEx calling the callback
edit give me a few mins i will make it.
Re: Help editing this Radar Detector Command -
jakejohnsonusa - 24.11.2012
Ok I will try, but I am a relatively new scripter...
Re: Help editing this Radar Detector Command -
park4bmx - 24.11.2012
EDITED i shorten the code
pawn Код:
//at the top
new DetectorTimer[MAX_PLAYERS];
if (strcmp("/detectoron", cmdtext, true, 10) == 0)
{
if(DetectorTimer[playerid] != -1) KillTimer(DetectorTimer[playerid]);
DetectorTimer[playerid] = SetTimerEx("RunDetector", 2000, true, "i", playerid);
SendClientMessage(playerid,-1,"Detector On");
return 1;
}
if (strcmp("/detectoroff", cmdtext, true, 10) == 0)
{
SendClientMessage(playerid,-1,"Detector OFF");
KillTimer(DetectorTimer[playerid]);
return 1;
}
forward RunDetector(playerid)
public RunDetector(playerid)
{
new counter = 0, string[128];
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30.0, x, y, z) && i != playerid && IsPlayerConnected(i) && IsACop(i))
{
format(string, sizeof(string), "%s (%d)", Nick(i), i);
SendClientMessage(playerid,-1,string);
counter++;
}
}
if(counter == 0) return SendClientMessage(playerid, 0xFF0000FF, "No one is in your range.");
return 1;
}
that should do it
I have not compiled it,but should have no problem!
Re: Help editing this Radar Detector Command -
jakejohnsonusa - 24.11.2012
THANK YOU +1 REP... I will test now and edit this post if it works well or not.
AW: Re: Help editing this Radar Detector Command -
Nero_3D - 24.11.2012
Quote:
Originally Posted by park4bmx
|
1. The "/detectoron" command would always return the message
2. You never assign a value to the variable
DetectorTimer
3. Both commands are missing their returns
Re: Help editing this Radar Detector Command -
jakejohnsonusa - 24.11.2012
What do you mean by "You never assign a value to the variable DetectorTimer"
Re: Help editing this Radar Detector Command -
park4bmx - 24.11.2012
Quote:
Originally Posted by Nero_3D
1. The "/detectoron" command would always return the message
2. You never assign a value to the variable DetectorTimer
3. Both commands are missing their returns
|
Quote:
Originally Posted by jakejohnsonusa
What do you mean by "You never assign a value to the variable DetectorTimer"
|
hes right didnt think about it that way
i edited it
but your prob going on need a new variable to check if its on/off
Re: Help editing this Radar Detector Command -
jakejohnsonusa - 24.11.2012
EDIT:
Sweet, but I just tried it and I did /detectoron and then /detectoroff and I get "Detector Already On" everytime...
To make this be awesome (so it doesn't clutter up the chat messages) is there a way to make this a textdraw under the chat messages?