new id = GetDriverID(vehicleid); //Anti Team-Jack
if(IsPlayerInAnyVehicle(id) && !ispassenger && GetPlayerTeam(playerid) == GetPlayerTeam(id))
{
GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
}
stock GetDriverID(vehicleid)
{
for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i))
{
if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
}
return 1;
}
if(IsPlayerInAnyVehicle(id) && GetPlayerTeam(playerid) == GetPlayerTeam(id))
{
if(!ispassenger)
{
GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
}
}
if(IsPlayerInAnyVehicle(id) && GetPlayerTeam(playerid) == GetPlayerTeam(id))
{
if(ispassenger)
{
return 1;
}
else
{
GameTextForPlayer(playerid, "~r~Team Jack is not allowed!", 2100, 3);
SetVehicleParamsForPlayer(vehicleid, playerid, false, true);
}
}
new bool:driver = false;
for(new i = 0; i < MAX_PLAYERS; i ++) // If you use foreach, use that instead of a for loop
{
if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
driver = true;
break;
}
if(!driver) // No driver found for that vehicle
{
// Do stuff to prevent vehicle entering
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_PASSENGER)
{
if(GetPlayerWeapon(playerid) == 24) //Deagle
{
SetPlayerArmedWeapon(playerid,0);
}
}
return 1;
}
|
@NaS, I tried your code, and I used ClearAnimations(playerid);, but I seem to have another problem, at first the passenger's could not enter without a driver. But they even can't enter as a driver. Its like I disable driving in this game. Hahaha. How do I fix it?
|
|
@NaS, I tried your code, and I used ClearAnimations(playerid);, but I seem to have another problem, at first the passenger's could not enter without a driver. But they even can't enter as a driver. Its like I disable driving in this game. Hahaha. How do I fix it?
|
|
Make sure the code I posted is only executed in OnPlayerEnterVehicle if the player tries to enter as passenger, if the player enters as driver you should unlock the vehicle using SetVehicleParamsForPlayer.
You could (for testing) leave away the params and only work with ClearAnimations to see if the code runs in the right situations, or if the vehicle was just locked. |
new bool:driver = false; //Anti 'G' Abuse
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
driver = true;
break;
}
if(!driver) // No driver found for that vehicle
{
ClearAnimations(playerid);
}
|
Yes, I entered it at OnPlayerEnterVehicle, exactly like how you put it,
Код:
new bool:driver = false; //Anti 'G' Abuse
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
driver = true;
break;
}
if(!driver) // No driver found for that vehicle
{
ClearAnimations(playerid);
}
|
new driver = -1; //Anti 'G' Abuse
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(GetPlayerVehicleID(i) != vehicleid || GetPlayerState(i) != PLAYER_STATE_DRIVER) continue;
driver = i;
break;
}
if(driver == -1 && ispassenger) // No driver found for that vehicle, player is trying to enter as passenger - prevent that
{
ClearAnimations(playerid);
}
else if(driver != -1 && !ispassenger && GetPlayerTeam(driver) == GetPlayerTeam(playerid)) // player tries to enter as driver but the vehicle already has a driver which is on the same team - don't allow it
{
ClearAnimations(playerid);
}
