How to make a moving checkpoint?
#1

Hello. I would need some help in making a moving checkpoint to use it in a /find command. The idea is that I want to create a checkpoint that moves along with its target, so when I use /find x and X is moving, the checkpoint will go after him, until I use /cancel find.

I tried this:

Код:
CMD:find(playerid,params[]) // /find
{
new pname2[25], id, string[200];
if(sscanf(params, "u",id)) return SendClientMessage(playerid,COL_SYN, "USAGE: /find <player name/ID>");
if(PlayerInfo[playerid][pJob]==2)
{
	if(IsPlayerConnected(id))
	{
		if(id!=INVALID_PLAYER_ID)
		{
			if(id!=playerid)
			{
			    PlayerInfo[playerid][pCheckpointactive]=1;
			    PlayerInfo[playerid][pCPid]=id;
			    GetPlayerName(id,pname2,sizeof(pname2));
			    format(string,sizeof(string),"* Marker set on %s (%d). To clear it type /cancel find.",pname2,id);
			    SendClientMessage(playerid,COL_GREEN,string);
				MovingCheckpoint(playerid);
			}
			else SendClientMessage(playerid,COL_ERROR,"You cannot use this command on yourself.");
		}
		else SendClientMessage(playerid,COL_ERROR,"Player not connected.");
	}
	else SendClientMessage(playerid,COL_ERROR,"Player not connected.");
}
else SendClientMessage(playerid,COL_ERROR,"You are not a Detective.");
return 1;
}
and here is the public:
Код:
public MovingCheckpoint(playerid)
{
	new Float:x,Float:y,Float:z,id;
	id=PlayerInfo[playerid][pCPid];
	while(PlayerInfo[playerid][pCheckpointactive]==1)
	{
		GetPlayerPos(id,x,y,z);
		SetPlayerCheckpoint(playerid,x,y,z,3);
		SetTimer("DisableCheckpoint",1000,0);
	}
}
Код:
public DisableCheckpoint(playerid)
{
DisablePlayerCheckpoint(playerid);
}
The publics are forwarded, but using this will crash my server, because it's an infinite cycle. How should I make it right?
Reply
#2

Check your public.

Tip : "SetTimer".
Another tip : The server doesn't crash because of "the infinite circle".
Reply
#3

Then, how should the public be? And what about the timer? Could you be more specific? I can't figure out.
Reply
#4

Well, your mistake is about this line :

pawn Код:
SetTimer("DisableCheckpoint",1000,0);
Tip : SetTimer works only if you call a function without parameters
Reply
#5

I've put the DisablePlayerCheckpoint in the public itself, so there will be no timer. There is still an infinite loop there and I can't do anything else while that loop goes on. How to make the find continue without a loop? That's what I need to know.

Код:
public MovingCheckpoint(playerid)
{
	new Float:x,Float:y,Float:z,id;
	id=PlayerInfo[playerid][pCPid];
	while(PlayerInfo[playerid][pCheckpointactive]==1)
	{
		GetPlayerPos(id,x,y,z);
		SetPlayerCheckpoint(playerid,x,y,z,3);
		DisablePlayerCheckpoint(playerid);
	}
}
Reply


Forum Jump:


Users browsing this thread: