SA-MP Forums Archive
A delay when using this command. - 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: A delay when using this command. (/showthread.php?tid=623759)



A delay when using this command. - danielpalade - 04.12.2016

I have this command:

Код:
CMD:ff(playerid, params)
{
	if(playerVariables[playerid][pAdminLevel] > 0)
	{
		new Float:fPX, Float:fPY, Float:fVX, Float:fVY, Float:object_x, Float:object_y, Float:player_x, Float:player_y, Float:player_z;
	 
		const Float:fScale = 20.0;
	 
		GetPlayerCameraPos(playerid, fPX, fPY, player_z); //Ignore player_z here
		GetPlayerCameraFrontVector(playerid, fVX, fVY, player_z); //Ignore player_z here
	 
		object_x = fPX + floatmul(fVX, fScale);
		object_y = fPY + floatmul(fVY, fScale);
	 
		GetPlayerPos(playerid, player_x, player_y, player_z);
		SetPlayerPosEx(playerid, object_x, object_y, player_z);
	}
	else return SendClientMessage(playerid, -1, AdminOnly);
    return 1;
}
This command, should teleport you 10 meters in the direction that you're looking at.
The problem here is, I can't really "spam it". Like after using it, I have to wait 1 second before I can use it again.
I didn't add any timer or something like that that could create the delay, so I don't know what it's causing it.


Re: A delay when using this command. - Swedky - 04.12.2016

Because GetPlayerCameraPos are only updated once a second for every client, that's your issue?


Re: A delay when using this command. - danielpalade - 05.12.2016

Quote:
Originally Posted by Swedky
Посмотреть сообщение
Because GetPlayerCameraPos are only updated once a second for every client, that's your issue?
Ehm, and is there a fix for that?


Re: A delay when using this command. - Threshold - 05.12.2016

Why are you using the player's camera position to update the player's on-foot position? Why not use GetPlayerPos instead?


Re: A delay when using this command. - gurmani11 - 05.12.2016

Код:
CMD:ff(playerid, params)
{
	if(playerVariables[playerid][pAdminLevel] > 0)
	{
	    if(!GetPVarInt(playerid, "SendCmd")) return SetPVarInt(playerid, "SendCmd", true);
		else DeletePVar(playerid, "SendCmd");
	}
	else return SendClientMessage(playerid, -1, AdminOnly);
    return 1;
}
public OnPlayerUpdate(playerid)
{
	if(GetPVarInt(playerid, "SendCmd"))
	{
		new Float:fPX, Float:fPY, Float:fVX, Float:fVY, Float:object_x, Float:object_y, Float:player_x, Float:player_y, Float:player_z;

		const Float:fScale = 20.0;

		GetPlayerCameraPos(playerid, fPX, fPY, player_z); //Ignore player_z here
		GetPlayerCameraFrontVector(playerid, fVX, fVY, player_z); //Ignore player_z here

		object_x = fPX + floatmul(fVX, fScale);
		object_y = fPY + floatmul(fVY, fScale);

		GetPlayerPos(playerid, player_x, player_y, player_z);
		SetPlayerPosEx(playerid, object_x, object_y, player_z);
		DeletePVar(playerid, "SendCmd");
	}
	return 1;
}
Useless..


Re: A delay when using this command. - danielpalade - 06.12.2016

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Why are you using the player's camera position to update the player's on-foot position? Why not use GetPlayerPos instead?
Well, because I can't detect where he is looking at..


Re: A delay when using this command. - Threshold - 06.12.2016

Yes, but you are updating the players position based upon the cameras coordinates, not the players coordinates. That's why you can't spam it..