Help with the trailer
#1

Greetings, I would like to know how I could do so that when a trailer is attached to a trailer, try to do this but it does not work:

Code:
forward OnPlayerAttachTrailer(playerid, vehicleid, trailerid);

public OnPlayerAttachTrailer(playerid, vehicleid, trailerid)
{
	if(!IsTrailerAttachedToVehicle(vehicleid))
	{
	}
	if(pInfo[playerid][pLevel] > 2)
 	{
			if(GetPVarInt(playerid, "TRUCK_MERCH") == 1)
			{
				new Tipe[20];
				switch(GetVehicleModel(trailerid))
				{
			    	case 435: Tipe = "Cereal";
				}
				SetPlayerCheckpoint(playerid, -2457.8601,2291.7852,5.0990, 7);
				SetPVarInt(playerid, "TRUCK_MERCH", 2);
				DeletePVar(playerid, "TRUCK_GO");
			        c_clvl2_e1_b = false;
				SendClientMessage(playerid, -1, "Go to the checkpoint");
				RemovePlayerMapIcon(playerid, CEREAL_DEPOSIT);
   				SetPVarInt(playerid, "TRUCK_GOING", 2);
			}
	}
	return 1;
}
Reply
#2

Hello!

Where do you call the callback? I think it's isn't a basic callback, isn't it?
Reply
#3

Quote:
Originally Posted by Mencent
View Post
Hello!

Where do you call the callback? I think it's isn't a basic callback, isn't it?
You're right. That's not a default Pawn callback.
Reply
#4

Is there any other way to do the function? :PPP
Reply
#5

I think an option is to use a timer. There are many other solutions, but try this:
PHP Code:
//global variable:
new TruckTimer[MAX_PLAYERS];
//when you enter the truck:
TruckTimer[playerid] = SetTimerEx("OnPlayerAttachTrailer",1000,1,"i",playerid);
//when you left the truck:
KillTimer(TruckTimer[playerid]);
TruckTimer[playerid] = 0;
forward OnPlayerAttachTrailer(playerid);
public 
OnPlayerAttachTrailer(playerid)
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(!
IsTrailerAttachedToVehicle(vehicleid))return 1;
    if(
pInfo[playerid][pLevel] > 2)
    {
        if(
GetPVarInt(playerid,"TRUCK_MERCH") == 1)
        {
            new 
Tipe[20],trailerid GetVehicleTrailer(vehicleid);
            switch(
GetVehicleModel(trailerid))
            {
                case 
435Tipe "Cereal";
            }
            
SetPlayerCheckpoint(playerid, -2457.8601,2291.7852,5.09907);
            
SetPVarInt(playerid"TRUCK_MERCH"2);
            
DeletePVar(playerid"TRUCK_GO");
               
c_clvl2_e1_b false;
            
SendClientMessage(playerid, -1"Go to the checkpoint");
            
RemovePlayerMapIcon(playeridCEREAL_DEPOSIT);
            
SetPVarInt(playerid"TRUCK_GOING"2);
            return 
1;
        }
    }
    return 
1;

Reply
#6

Quote:
Originally Posted by Mencent
View Post
I think an option is to use a timer. There are many other solutions, but try this:
PHP Code:
//global variable:
new TruckTimer[MAX_PLAYERS];
//when you enter the truck:
TruckTimer[playerid] = SetTimerEx("OnPlayerAttachTrailer",1000,1,"i",playerid);
//when you left the truck:
KillTimer(TruckTimer[playerid]);
TruckTimer[playerid] = 0;
forward OnPlayerAttachTrailer(playerid);
public 
OnPlayerAttachTrailer(playerid)
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(!
IsTrailerAttachedToVehicle(vehicleid))return 1;
    if(
pInfo[playerid][pLevel] > 2)
    {
        if(
GetPVarInt(playerid,"TRUCK_MERCH") == 1)
        {
            new 
Tipe[20],trailerid GetVehicleTrailer(vehicleid);
            switch(
GetVehicleModel(trailerid))
            {
                case 
435Tipe "Cereal";
            }
            
SetPlayerCheckpoint(playerid, -2457.8601,2291.7852,5.09907);
            
SetPVarInt(playerid"TRUCK_MERCH"2);
            
DeletePVar(playerid"TRUCK_GO");
               
c_clvl2_e1_b false;
            
SendClientMessage(playerid, -1"Go to the checkpoint");
            
RemovePlayerMapIcon(playeridCEREAL_DEPOSIT);
            
SetPVarInt(playerid"TRUCK_GOING"2);
            return 
1;
        }
    }
    return 
1;

Code:
warning 219: local variable "vehicleid" shadows a variable at a preceding level
warning 219: local variable "trailerid" shadows a variable at a preceding level
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)