Carfixing vehiclespeed
#1

i made a carfix command and i wanna know how to make it only work if vehicle is stopped but how? i cant find it
Reply
#2

You can use GetVehicleVelocity function to find the x,y and z components of the velocity and check if they are zero or not.
Reply
#3

new Float:Velocity[3], output[80];
GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[0], Velocity[0]);
so like this? pls give a example!
Reply
#4

Under your carfix command:

Код:
new Float:Velocity[3];
GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[1], Velocity[2]);
if(Velocity[0] != 0 || Velocity[1] != 0 || Velocity[2] != 0) return SendClientMessage(playerid,0xffffffaa,"Your car needs to be stationary in order to use this command");
Gives you an idea.
Reply
#5

But now if i do it and it says im not stopped it doesnt checks anymore..

i want something like:
if the car isnt stopped send that message then check again if it's stopped if yes repair the car
Reply
#6

If you have a command like /fix, everytime the player enter the command, it will check if the vehicle is stationary. If you don't and have a checkpoint or are using IsPlayerInRangeOfPoint instead, you can use a timer.

EDIT:

This goes under OnPlayerCommandText callback:
Код:
if(!strcmp(cmdtext,"/repair",true,7))
{
	if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xffffffaa,"You need to be in a vehicle");
	new Float:Velocity[3];
	GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[1], Velocity[2]);
	if(Velocity[0] != 0 || Velocity[1] != 0 || Velocity[2] != 0) return SendClientMessage(playerid,0xffffffaa,"Your car needs to be stationary in order to use this command");
	
	RepairVehicle(GetPlayerVehicleID(playerid));
        SendClientMessage(playerid,0xffffffaa,"Vehicle Repaired");
	return 1;
}
Reply
#7

Example? i dont understand lol

EDIT!
EDIT!
EDIT!
EDIT!
EDIT!
But what you made doesnt re-check it what about that thing with the timer? :S
Reply
#8

You don't need a timer if you have command. And yes, it does check if the vehicle is static everytime you type in that command.
Reply
#9

Yes it does but i mean that you typ /carfix then sendclientmessage(playerid, COLOR_KGAG, "Stop vehicle first"); then it gotta check again in like 2 secs if its stopped if yes -> repairvehicle
Reply
#10

You can use SetTimerEx for that. Just make a new function called Repair Vehicle and call this function using this timer. This timer code goes after the user gets a message "Your car needs to be stationary in order to use this command".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)