SA-MP Forums Archive
always checking vehicle? - 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: always checking vehicle? (/showthread.php?tid=359140)



always checking vehicle? - oblexive - 13.07.2012

Hey im trying to do a driving mission involving some trailers. I know how to check if a trailer is attached to the truck etc, but only through a command or stuff like that.
How can i check always if a trailer is attached or detached from the vehicle?
So while the player is in a certain vehicle, if at any point in time they attach a trailer of certain ID it continues with some script.
Thanks guys, Im just not sure where to check for this information without using commands. So it always checks. Cheers!


Re: always checking vehicle? - Yuryfury - 13.07.2012

You will need to use the same function but just have a timer check every second or so.


Re: always checking vehicle? - [MM]RoXoR[FS] - 13.07.2012

When player enters a vehicle check if the vehicle is a truck.
If yes, then,
SetTimerEx("YOUR_FUNCTION_NAME",1000,true,"i",playerid);
of maybe interval 1000 ms.

In Your Function add the code, which checks if the trailer is attached.

When players exit's vehicle use KillTimer


Re: always checking vehicle? - oblexive - 13.07.2012

I apreciate the reply guys! Could I ask for a quick example? The truck types are 403, but they have:
JobInfo[JOB_TRUCKER][jCars][0] through to [4] before them. The trailers are the same but type 435:
JobInfo[JOB_TRUCKER][jTrailers][0]
Could I put:
if(IsTruckerVehicle(vehicleid))
{
SetTimerEx("YOUR_FUNCTION_NAME",1000,true,"i",play erid);
}

on exit:
if(IsTruckerVehicle(vehicleid))
{
KillTimer(YOUR_FUNCTION_NAME);
}

Im quite new to this so i may suck. I also need an explanation on function name? Is that whatever I want? Thanks so much


Re: always checking vehicle? - [MM]RoXoR[FS] - 13.07.2012

UNTESTED

pawn Код:
//On Top
new TruckTimer[MAX_PLAYERS];

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][0] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][1] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][2] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][3] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][4])
    {
       TruckTimer[playerid] = SetTimerEx("IsTrailer",1000,true,"i",playerid);
    }
    return 1;
}

forward IsTrailer(playerid);
public IsTrailer(playerid)
{
    //Check if trailer is attached
    return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
        if(GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][0] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][1] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][2] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][3] || GetPlayerVehicleID(playerid) == JobInfo[JOB_TRUCKER][jCars][4])
        {
        KillTimer(TruckTimer[playerid]);      
        }  
    return 1;
}



Re: always checking vehicle? - oblexive - 13.07.2012

hmm It didnt seem to work, I did it all correct I asume. Nothing seems to happen, I made a message come up when the trailer is attached but it didnt come up. So im not sure if the timer is activating or if its just not reading when the trailer is attached :/
Код:
forward IsTrailer(playerid);
public IsTrailer(playerid)
{
	if(IsTrailerAttachedToVehicle(403))
	{
		SendClientMessage(playerid, COLOR_WHITE, "Trailer Attached");
	}
	//Check if trailer is attached
	return 1;
}
Thats what i did here.


Re: always checking vehicle? - PrawkC - 13.07.2012

You need to have to check if there is a trailer attached to your vehicle, so use GetPlayerVehicleID rather than typing "403", because doing that you're checking if vehicle id 403 has a trailer attached.


Re: always checking vehicle? - oblexive - 13.07.2012

ah my bad, how would I do that then?
edit: My bad again i think i got it now :P Im trying it now will post results.


Re: always checking vehicle? - oblexive - 13.07.2012

I got it all working, thanks guys. Apreciate it alot.
Quick question though. I set up a new timer to be enabled when the trailer gets connected.
I want the timer to check wether theres a trailer attached or not. If there is then do nothing and keep checking
but if it disconects I want it to reset some variables and a message come up saying Youv lost your trailer.

I tried to do this but couldnt get it working. I setup the timer correctly. It enables when the trailer
is connected but I cant check wether the trailers disconected or not properly. Can anyone give me a hand?

Код:
forward IsTrailerOff(playerid);//detach trailer
public IsTrailerOff(playerid)
{
	new vehicleid = GetPlayerVehicleID(playerid);
        if(!IsTrailerAttachedToVehicle(vehicleid))
	{
		PlayerInfo[playerid][pTPackages] = 0;
		SendClientMessageToAll(COLOR_RED, "Trailer Disconected!");
		KillTimer(TrailerTimer[playerid]);
	}
	return 1;
}
This is the function. They didnt work. What do I need to do? Thanks!