Faction Vehicles[Problem solved] -
antonio112 - 12.03.2011
Heya ! I`m having some problems with faction vehicles. So, the script is like this:
First, global array for LSPD vehicles
Then, created the vehicles:
pawn Код:
public OnGameModeInit()
{
LSPDCar[ 0 ] = AddStaticVehicle( 596, 1570.4307, -1710.5015, 5.6118, 359.0704, 0, 1 ); // LSPDCruiser1
LSPDCar[ 1 ] = AddStaticVehicle( 596, 1574.4824, -1710.7050, 5.6126, 359.5297, 0, 1 ); // LSPDCruiser2
LSPDCar[ 2 ] = AddStaticVehicle( 596, 1578.6796, -1710.6199, 5.6113, 358.9721, 0, 1 ); // LSPDCruiser3
LSPDCar[ 3 ] = AddStaticVehicle( 596, 1583.5558, -1710.6246, 5.6117, 358.6743, 0, 1 ); // LSPDCruiser4
LSPDCar[ 4 ] = AddStaticVehicle( 596, 1587.4552, -1710.6227, 5.6123, 359.9478, 0, 1 ); // LSPDCruiser5
LSPDCar[ 5 ] = AddStaticVehicle( 596, 1591.5229, -1710.7249, 5.6120, 0.7387, 0, 1 ); // LSPDCruiser6
LSPDCar[ 6 ] = AddStaticVehicle( 596, 1602.0529, -1683.9634, 5.6110, 90.7847, 0, 1 ); // PDCruiser7
LSPDCar[ 7 ] = AddStaticVehicle( 596, 1601.9954, -1688.0194, 5.6131, 89.2227, 0, 1 ); // PDCruiser8
LSPDCar[ 8 ] = AddStaticVehicle( 596, 1601.7228, -1692.0026, 5.6109, 88.5967, 0, 1 ); // PDCruiser9
LSPDCar[ 9 ] = AddStaticVehicle( 596, 1601.3859, -1696.0682, 5.6096, 90.4116, 0, 1 ); // PDCruiser10
LSPDCar[ 10 ] = AddStaticVehicle( 596, 1600.9125, -1700.1434, 5.6098, 89.4584, 0, 1 ); // PDCruiser11
LSPDCar[ 11 ] = AddStaticVehicle( 596, 1601.4318, -1704.2673, 5.6122, 90.6356, 0, 1 ); // PDCruiser12
return 1;
}
Everything fine till now. Now here comes the problem, when someone gets in a LSPDCar and his GetPVarInt( playerid, "Faction" ) isn`t 1 it should remove the player from the vehicle but it`s not working.
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vid = GetPlayerVehicleID( playerid );
if( vid == LSPDCar[ 11 ] )
{
if( newstate == 2 && GetPVarInt( playerid, "Faction" ) != 1 )
{
RemovePlayerFromVehicle( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
}
return 1;
}
Anyone has any idea why it`s not working?
Re: Faction Vehicles -
iMonk3y - 12.03.2011
Replace RemovePlayerFromVehicle( playerid ); with ClearAnimations( playerid );
RemovePlayerFromVehicle function removes player from vehicle. In your code, player isn't in vehicle.
Re: Faction Vehicles -
antonio112 - 12.03.2011
It`s not working.
Well, if it`s
OnPlayerStateChange, if I`m not wrong, the player is already in the vehicle when he 'changes' his state ...
Grrr... But thanks anyway for trying :P
Re: Faction Vehicles -
iMonk3y - 12.03.2011
Then place your code under OnPlayerEnterVehicle callback :P
Re: Faction Vehicles -
antonio112 - 12.03.2011
Tried it like:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if( vehicleid == LSPDCar[ 11 ] )
{
if( GetPVarInt( playerid, "Faction" ) != 1 )
{
ClearAnimations( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
}
return 1;
}
Not working ... but still, I would like if I could make it work
OnPlayerStateChange
Still, not working.
Later edit:
Tried debugging it like:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vid = GetPlayerVehicleID( playerid );
if( vid == LSPDCar[ 11 ] )
{
print( "Debug" );
if( newstate == 2 && GetPVarInt( playerid, "Faction" ) != 1 )
{
RemovePlayerFromVehicle( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
}
return 1;
}
And it didn`t print anything ... so I guess the problem is somewhere at the vehicle id?
Re: Faction Vehicles -
iMonk3y - 12.03.2011
In your case, it will only work if you enter 1 vehicle
(LSPDCar[ 11 ]).
Re: Faction Vehicles -
antonio112 - 12.03.2011
Yes ! That was the problem. Partially fixed it ... but you know how can I make it a bit smaller? Since I have 11 cars for the moment and I have like:
pawn Код:
if( vid == LSPDCar[ 0 ] || LSPDCar[ 1 ] || LSPDCar[ 2 ] || LSPDCar[ 3 ] || LSPDCar[ 4 ] || LSPDCar[ 5 ] || LSPDCar[ 6 ] || LSPDCar[ 7 ] || LSPDCar[ 8 ] || LSPDCar[ 9 ] || LSPDCar[ 10 ] || LSPDCar[ 11 ] )
I want it a bit shorter
ps: Thanks for your help by the way !
Later Edit: Nevermind, done it myself using a stock.
Re: Faction Vehicles -
iMonk3y - 12.03.2011
Make a loop
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
for( new i; i < 12; i++ )
{
if( vehicleid == LSPDCar[ i ] )
{
if( GetPVarInt( playerid, "Faction" ) != 1 )
{
ClearAnimations( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
break;
}
}
return 1;
}
Re: Faction Vehicles -
antonio112 - 12.03.2011
Works like a charm! Thanks again for the help.
If anyone can think at a solution with
I would appreciate it.
Till now, I have:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if( newstate == 2 )
{
new VehicleID = GetPlayerVehicleID ( playerid );
if( IsLSPDVeh( VehicleID ) )
{
if( GetPVarInt( playerid, "Faction" ) == 1 ) { }// LSPD Faction
else
{
RemovePlayerFromVehicle( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
return 1;
}
if( IsFBIVeh( VehicleID ) )
{
if( GetPVarInt( playerid, "Faction" ) == 2 ) { } // FBI Faction
else
{
RemovePlayerFromVehicle( playerid );
SendClientMessage( playerid, -1, "You don`t have the keys for this car." );
}
return 1;
}
}
return 1;
}
And the IsLSPDVeh and ISFBIVeh:
pawn Код:
stock IsLSPDVeh( VehicleID )
{
if ( ( VehicleID == LSPDCar[ 0 ] || LSPDCar[ 1 ] || LSPDCar[ 2 ] || LSPDCar[ 3 ] || LSPDCar[ 4 ] || LSPDCar[ 5 ] || LSPDCar[ 6 ] || LSPDCar[ 7 ] || LSPDCar[ 8 ] || LSPDCar[ 9 ] || LSPDCar[ 10 ] || LSPDCar[ 11 ] ) )
return true;
else return false;
}
stock IsFBIVeh( VehicleID )
{
if ( ( VehicleID == FBICar[ 0 ] || FBICar[ 1 ] || FBICar[ 2 ] || FBICar[ 3 ] || FBICar[ 4 ] || FBICar[ 5 ] || FBICar[ 6 ] ) )
return true;
else return false;
}