Detect if a players moved since /fix
#1

So i've got a command to /fix a players car. I'm wondering how can you check if they have moved from their last position since entering it. By getting out of the vehicle, or driving away. So i enter /fix wait 10 seconds and if i've moved it tells me "you've moved assistance cancelled".

Here's the command

Code:
CMD:fix(playerid,params[])
{
	new Float:health;
	new veh;
	veh = GetPlayerVehicleID(playerid);
	GetVehicleHealth(veh, health);
	if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, red, "You need to be in a vehicle to use this");
	else if(health > 999) return SendClientMessage(playerid,red,"Your vehicles at 100%");
    SetTimer("repairtime",10000,false);
    SendClientMessage(playerid,green,"Help will arrive in 10 seconds. Please wait.");
    return 1;
}
Here's the timer:

Code:
forward repairtime();
public repairtime()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	RepairVehicle(GetPlayerVehicleID(i));
	SendClientMessage(i, COLOR_SKYBLUE, "Vehicle Repaired");
	GivePlayerMoney(i, -500);
	}
return 0;
}
im also having problems with the timer, it spams me after the fix and takes money, hence the return 0. I've set the timer to "false" so its not repeating. Its not tested @ the time of typing so thats why it's like that. Hope you can help guys
Reply
#2

If you want them to stay at one spot, you could just TogglePlayerControllable(playerid, false);.
edit: But I assume that's not what you want. You can get the player's current position as he uses the command, and then define a timer that checks eg. every second, if it's not equal to his initial position, you cancel the command.
Reply
#3

I thought about toggleplayercontrollable, but that's not what i want unfortunately. If i have to. I will

I know ive got to get the players position, but how would i do it so it checks every second? I know how to do timers so thats ok, but its actually saving :P still a noob here

Do i have to use GetPlayerPos(playerid,xyz);?
Reply
#4

Yup, you have to use GetPlayerPos().
You can try defining the old positions as a global variable.
Code:
new Float:OldPos[3]; //under defines


CMD:fix(playerid,params[])
{
    new Float:health;
    new veh;
    GetPlayerPos(playerid, OldPos[0], OldPos[1], OldPos[2]);
    veh = GetPlayerVehicleID(playerid);
    GetVehicleHealth(veh, health);
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, red, "You need to be in a vehicle to use this");
    else if(health > 999) return SendClientMessage(playerid,red,"Your vehicles at 100%");
    SetTimer("repairtime",10000,false);
    SendClientMessage(playerid,green,"Help will arrive in 10 seconds. Please wait.");
    return 1;
}
Then create a timer that checks if OldPos[0], OldPos[1] and OldPos[2] are equal to the players current positon. (Which you get with GetPlayerPos()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)