PDA

View Full Version : OnPlayerEnterVehicle Help needed


Avi57
12/06/2013, 06:24 PM
Hello,

I have this script :-

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel(vehicleid) == 432)
{
if(class[playerid][Mechanic] < 1) return RemovePlayerFromVehicle(playerid);
}
if(GetVehicleModel(vehicleid) == 520 && GetVehicleModel(vehicleid) == 425)
{
if(class[playerid][Pilot] < 1) return RemovePlayerFromVehicle(playerid);
}
}
return 1;
}

Errors :-

E:\Scripter\filterscripts\tdm.pwn(289) : warning 219: local variable "vehicleid" shadows a variable at a preceding level
E:\Scripter\filterscripts\tdm.pwn(290) : error 017: undefined symbol "newstate"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.


I Want that if Pilot and Mechanic < 1 then player cant enter.

feartonyb
12/06/2013, 06:31 PM
Replace the code with this:


public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new playercar = GetPlayerVehicleID(playerid);
new newstate = GetPlayerState(playerid);
if(newstate == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel(playercar) == 432)
{
if(class[playerid][Mechanic] < 1) return RemovePlayerFromVehicle(playerid);
}
if(GetVehicleModel(playercar) == 520 && GetVehicleModel(playercar) == 425)
{
if(class[playerid][Pilot] < 1) return RemovePlayerFromVehicle(playerid);
}
}
return 1;
}

Avi57
13/06/2013, 04:33 AM
There is No error But it dont remove Player From Vehicle.
Please Any Solution?

dubyabeast
13/06/2013, 05:11 AM
OnPlayerEnterVehicle calls whenever the person hits the button to enter the vehicle, and is close enough to the vehicle. Try setting the players pos. e.g:

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
new playercar = GetPlayerVehicleID(playerid);
new newstate = GetPlayerState(playerid);
new Float:pos[3];
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
if(newstate == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel(playercar) == 432)
{
if(class[playerid][Mechanic] < 1) return SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
}
if(GetVehicleModel(playercar) == 520 && GetVehicleModel(playercar) == 425)
{
if(class[playerid][Pilot] < 1) return SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
}
}
return 1;
}

Avi57
13/06/2013, 05:15 AM
Didn't Worked.
Player can still enter.

yaron0600
13/06/2013, 05:27 AM
Did you define the vehicles cant enter ? I mean did you create them on the script ? re-create and did you do new MechanicVehicles[YourNumberHere];?

Pottus
13/06/2013, 05:53 AM
Did no one see this ?

if(GetVehicleModel(vehicleid) == 520 && GetVehicleModel(vehicleid) == 425)

CJay9209
13/06/2013, 06:42 AM
U should NOT be using onplayerentervehicle for this. Use onplayerstatechange instead and save yourself the headache...

Ballu Miaa
13/06/2013, 07:01 AM
But doing it under OnPlayerEnterVehicle is not a good idea. Using it under OnPlayerStateChange is better and effective. It will only be called when a player successfully enter's the car. OnPlayerEnterVehicle is called everytime a player attempt's to enter a vehicle.


public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel(vehicleid) == 432)
{
if(class[playerid][Mechanic] < 1) return RemovePlayerFromVehicle(playerid);
}
if(GetVehicleModel(vehicleid) == 520 || GetVehicleModel(vehicleid) == 425)
{
if(class[playerid][Pilot] < 1) return RemovePlayerFromVehicle(playerid);
}
}
return 1;
}

Avi57
13/06/2013, 08:59 AM
Thanks Ballu :)