SA-MP Forums Archive
Towing cars - 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: Towing cars (/showthread.php?tid=423268)



Towing cars - siemka321 - 17.03.2013

I need your help. I made that you can tow cars and stuff, but now I need to make it that when you arrive to a checkpoint, the towed car disapears. Is that possible? Because I used to play in a server where you tow a car onto a pickup and it disapears.


Respuesta: Towing cars - JustBored - 17.03.2013

You can use
SetVehicleVirtualWorld (parameters are: vehicleid - virtualworld)


Re: Towing cars - mrtms - 17.03.2013

Yes it is possible. You need to use OnPlayerEnterCheckpoint(playerid) and DestroyVehicle(VehicleID)

Basically you need to make it so that once the player who is towing the vehicle enters a check point, it will then proceed to Destroy the vehicle that the player is towing.


Re: Towing cars - siemka321 - 17.03.2013

Quote:
Originally Posted by mrtms
Посмотреть сообщение
Yes it is possible. You need to use OnPlayerEnterCheckpoint(playerid) and DestroyVehicle(VehicleID)

Basically you need to make it so that once the player who is towing the vehicle enters a check point, it will then proceed to Destroy the vehicle that the player is towing.
Yes, but there is not vehicleid on OnPlayerEnterCheckpoint , so pretty much I get an error undefined symbol "vehicleid".


Re: Towing cars - Denying - 17.03.2013

Well, you will just have to store the vehicle id on a global variable when a player starts to tow it.
Then just use that stored data.


Re: Towing cars - Scofield62 - 17.03.2013

Replace the vehicleid to this-> GetPlayerVehicleID(playerid)
It gives u the vehicle id, or u can do this also int the entercheckpoint:

new vehicleid = GetPlayerVehicleID(playerid);


Re: Towing cars - Denying - 17.03.2013

Quote:
Originally Posted by Scofield62
Посмотреть сообщение
Replace the vehicleid to this-> GetPlayerVehicleID(playerid)
It gives u the vehicle id, or u can do this also int the entercheckpoint:

new vehicleid = GetPlayerVehicleID(playerid);
It will destroy the car the player is driving it, not the one he is towing.


Re: Towing cars - siemka321 - 17.03.2013

Quote:
Originally Posted by Denying
Посмотреть сообщение
It will destroy the car the player is driving it, not the one he is towing.
new towedcar;
GetVehicleTrailer(towedcar);
DestroyVehicle(towedcar);

Would this work? I already made the checkpoint, but when I enter the checkpoint, nothing happens.


Re: Towing cars - Denying - 17.03.2013

Can I see the code where you tow the car? I mean, type /tow to tow the closest car or whatever.

Код:
This forum requires that you wait 120 seconds between posts. Please try again in 46 seconds.
lol this is a bit annoying.


Re: Towing cars - siemka321 - 17.03.2013

Quote:
Originally Posted by Denying
Посмотреть сообщение
Can I see the code where you tow the car? I mean, type /tow to tow the closest car or whatever.

Код:
This forum requires that you wait 120 seconds between posts. Please try again in 46 seconds.
lol this is a bit annoying.
Код:
#define towpickup 1569.2766,-1477.9763,13.5526
new TowTruckers=0;
new IsTowTrucker[MAX_PLAYERS];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate==PLAYER_STATE_DRIVER)
 	{
  	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
    {
    IsTowTrucker[playerid]=1;
    TowTruckers++;
    SendClientMessage(playerid,0xFFFF00AA,"You can use the ACTION KEY to Tow cars");
    }
    }
    if((newstate==PLAYER_STATE_ONFOOT)&&(IsTowTrucker[playerid]==1))
    {
    IsTowTrucker[playerid]=0;
    TowTruckers--;
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if((newkeys==KEY_ACTION)&&(IsPlayerInAnyVehicle(playerid))&&(GetPlayerState(playerid)==PLAYER_STATE_DRIVER))
 	{
  	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
   	{
    new Float:pX,Float:pY,Float:pZ;
    GetPlayerPos(playerid,pX,pY,pZ);
    new Float:vX,Float:vY,Float:vZ;
    new Found=0;
    new vid=0;
    while((vid<MAX_VEHICLES)&&(!Found))
    {
    vid++;
    GetVehiclePos(vid,vX,vY,vZ);
    if((floatabs(pX-vX)<7.0)&&(floatabs(pY-vY)<7.0)&&(floatabs(pZ-vZ)<7.0)&&(vid!=GetPlayerVehicleID(playerid)))
    {
    Found=1;
    if(IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)))
    {
    DetachTrailerFromVehicle(GetPlayerVehicleID(playerid));
    }
    AttachTrailerToVehicle(vid,GetPlayerVehicleID(playerid));
    SendClientMessage(playerid,0xFFFF00AA,"Car towed!");
    SetPlayerCheckpoint(playerid, towpickup , 3.0);
    }
    }
    if(!Found)
    {
    SendClientMessage(playerid,0xFFFF00AA,"There is no car in range.");
    }
    }
    }
}

public OnPlayerEnterCheckpoint(playerid)
{
    DisablePlayerCheckpoint(playerid);
    if (IsPlayerInRangeOfPoint(playerid, 4.0, towpickup))
    {
    if(IsTowTrucker[playerid] == 1)
    {
	new towedcar;
	GetVehicleTrailer(towedcar);
	if(IsTrailerAttachedToVehicle(towedcar))
	{
	DestroyVehicle(towedcar);
   	GameTextForPlayer(playerid, "~g~Car towed!", 3000, 3);
   	GivePlayerMoney(playerid,50);
   	PlayerPlaySound(playerid,1056,0,0,0);
   	}
    }
    }
	return 1;
}
I used some tow truck filterscript, edited a little bit. So everything seems ok, except nothing happens when I enter the checkpoint