SA-MP Forums Archive
Faction/Job vehicles - 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: Faction/Job vehicles (/showthread.php?tid=547813)



Faction/Job vehicles - siemka321 - 25.11.2014

Can anyone give me an idea on how to make a pickup, that when picked up it spawns a vehicle that nobody but you can enter it. What I tried doing is creating a variable, let's just say pizzaboy[MAX_PLAYERS];

When you enter a pickup, it spawns the car and everything is ok, but there is one problem though. I've made more cars: sweeper[MAX_PLAYERS], tractor[MAX_PLAYERS]. And now when I enter one of them, sometimes they get the wrong callback (I enter the sweeper and it acts as if its the pizzaboy). Does anyone know what am I doing wrong? Maybe you have a better idea.

Here's some code:

Pizzaboy pickup code:
Код:
if(pickupid == ppizzaboy)
    {
    if(pInfo[playerid][Darbas] == DARBAS_PICININKAS || pInfo[playerid][Admin] >= 2)
    {
    if(IsValidVehicle(pizzaboy[playerid])){ DestroyVehicle(sweeper[playerid]); }
    pizzaboy[playerid] = CreateVehicle(448,218.9097,-180.5808,1.1772,85.6636,3,6,-1);
    PutPlayerInVehicle(playerid,pizzaboy[playerid],0);
    }
	else
	{
	//bla bla bla not a pizzaguy
	}
    }
now here's the OnPlayerStateChange callback

Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
	{
	
    if(GetPlayerVehicleID(playerid) == sweeper[playerid])
    {
    if(pInfo[playerid][Darbas] == DARBAS_SLAVEJAS || pInfo[playerid][Admin] >= 2)
    {
	//bla bla sweeper
    }
    else
    {
	KickPlayerOutOfVehicle(playerid); 
	//bla bla wrong job mate
 	}
    }

    else if(GetPlayerVehicleID(playerid) == pizzaboy[playerid]) //pizzaboy
	{
 	if(pInfo[playerid][Darbas] == DARBAS_PICININKAS || pInfo[playerid][Admin] >= 2)
 	{
 	//Bla bla pizzaguy stuff	
	}
	else
	{
	KickPlayerOutOfVehicle(playerid);
	//Bla bla not your car
	}
	}



Re: Faction/Job vehicles - dusk - 25.11.2014

Consider this: all Pawn variables start with the number 0. If the player is not in vehicle, GetPlayerVehicleID will return 0. In that case, they will match.

Try checking if a player is in vehicle first like so
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerVehicleID(playerid) == sweeper[playerid])
        {
            if(pInfo[playerid][Darbas] == DARBAS_SLAVEJAS || pInfo[playerid][Admin] >= 2)
            {
                //bla bla sweeper
            }
            else
            {
                KickPlayerOutOfVehicle(playerid);
                //bla bla wrong job mate
            }
        }

        else if(GetPlayerVehicleID(playerid) == pizzaboy[playerid]) //pizzaboy
        {
            if(pInfo[playerid][Darbas] == DARBAS_PICININKAS || pInfo[playerid][Admin] >= 2)
            {
                //Bla bla pizzaguy stuff   
            }
            else
            {
                KickPlayerOutOfVehicle(playerid);
                //Bla bla not your car
            }
        }
    }



Re: Faction/Job vehicles - siemka321 - 25.11.2014

Nope, still the same. Any other ideas?


Re: Faction/Job vehicles - siemka321 - 25.11.2014

Aw man guys, I've been messing around for hours. Anyone has an idea?


Re: Faction/Job vehicles - Steven82 - 25.11.2014

Quick question, why is this
pawn Код:
DestroyVehicle(sweeper[playerid]);
under the pizza boy code.


Re: Faction/Job vehicles - siemka321 - 25.11.2014

Yeah, I noticed it later after posting, it was supposed to be pizzaboy, but now it's different. But I still keep having the same problem.


Re: Faction/Job vehicles - siemka321 - 26.11.2014

YES, fixed it. Thanks to dusk over there, I noticed that vehicles are spawned with the same ID, meaning that pizzaboy AND sweeper = 0, so if you spawn a car and your other car is already present, it gets destroyed, and the car's variable is set to -1.