Ticked off at a looping timer, KillTimer doesn't work........
#1

well I am scripting a GPS locator system for the PD, now everything works as planned, (checkpoint appears and updates to player position every second) but for some reason when I do the command to kill the locator the checkpoint disappears for one second then just comes back I used..... KillTimer(GPStimer); but it just seems to repeat.....and its starting to tick me off ( no pun intended )


code:

Код:
forward pdGPSt(giveplayerid, playerid);

public pdGPSt(giveplayerid, playerid)
{
 for(new i = 0; i < MAX_PLAYERS; i++)
  {
	 new Float:x, Float:y, Float:z;
	 GetPlayerPos(giveplayerid, x, y, z);
	 SetPlayerCheckpoint(playerid, x,y,z, 0);
  }
	return 1;
}

new GPStimer;

if(strcmp(cmd, "/find", true) == 0)
	{
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /find [playerid/PartOfName]");
				return 1;
			}
			giveplayerid = ReturnUser(tmp);
			if(IsPlayerConnected(giveplayerid))
			{
			  if(giveplayerid != INVALID_PLAYER_ID)
			  {
			    //if(giveplayerid == playerid) { SendClientMessage(playerid, COLOR_GREY, "You cannot Find yourself!"); return 1; }
				  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
					new Float:X,Float:Y,Float:Z;
					GetPlayerPos(giveplayerid, X,Y,Z);
					SetPlayerCheckpoint(playerid, X,Y,Z, 0);
					GPStimer = SetTimer("pdGPSt", 1000, 1);
				}
			}
			else
			{
			  SendClientMessage(playerid, COLOR_GREY, "  Invalid Name/ID !");
			}
    return 1;
  }

if(strcmp(cmd, "/endfind", true) == 0)
{
		if(IsPlayerConnected(playerid))
		{
      SendClientMessage(playerid, COLOR_LIGHTGREEN, "The PD Tracking System is now Disabled.");
		  KillTimer(GPStimer);
		  DisablePlayerCheckpoint(playerid);
		}
		else
		{
		SendClientMessage(playerid, COLOR_GREY, "You need to be logged in first.");
		}
  	return 1;
	}
Reply
#2

You are using one timer for more than on player. You can kill timer but someone else can activate it again. Use like

gpstimer[playerid] = SetTimerEx

And

Kill it like KillTimer(gpstimer[playerid);
Reply
#3

Hmm that sounds good but its only myself on the test server so its not possible at this time to have someone else set it off, but I will modify it thanks for the suggestion. But is there a reason why it just would not stop, could it be cuz i was using it on myself?


[edit] Ok so I went back and changed....

new GPStimer[MAX_PLAYERS];

GPStimer[playerid] = SetTimer("pdGPSt", 1000, 1);

and

KillTimer(GPStimer[playerid]);

yet it still doesn't work >.<
Reply
#4

I suggest making a variable for the player that does this (new gpssearch[MAX_PLAYERS] and set that to 1 when you are searching and only allow the search function to show the location when it is 1, and when you disable it, make it 0 and make it so the function doesnt display checkpoints when it is 0.
Reply
#5

Quote:
Originally Posted by Kinetic
I suggest making a variable for the player that does this (new gpssearch[MAX_PLAYERS] and set that to 1 when you are searching and only allow the search function to show the location when it is 1, and when you disable it, make it 0 and make it so the function doesnt display checkpoints when it is 0.
Yes

Remember to kill timer when server restarts and to disable player checkpoint when player leaves game

Reply
#6

LOL guys thanks for the suggestions, I got someone to log in the test server what is happening is the giveplayerid gets the moving blip while the playerid (the one searching) only gets the first blip (which doesn't move) when I /endfind the timer stops for playerid and blip removed but still stays and moves for the giveplayerid.

I will try your suggestions and see if that fixes it.....
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)