A delay when using this command.
#1

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.
Reply
#2

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

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?
Reply
#4

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

Код:
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..
Reply
#6

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..
Reply
#7

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)