Disabling firing weapons from a vehicle if there is no driver (drive-by shooting).
#1

Hi,

I have been recently trying to figure out how to disable the drive-by shooting from a vehicle if there is no driver, I kinda made this code but it doesnt work lol. Can somebody help me? Would be appreciated(+rep)...

Код:
new allowed[MAX_PLAYERS]=0;
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
	if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
	{
	    PlayerLoop(i)
	    {
	        new numri=GetPlayerVehicleID(i);
	        if(numri == GetPlayerVehicleID(playerid))
	        {
	            if(GetPlayerVehicleSeat(i) == 0)
	            {
	                allowed[playerid]=1;
	            }
	            if(allowed[playerid]==0)
	            {
					return SendClientMessage(playerid, COLOR_LIGHTGREY, "You are not allowed to fire weapons in a vehicle without a driver."), SetPlayerArmedWeapon(playerid, 0);
				}
			}
		}
	}
        return 1;
}
Reply
#2

nvm misreaded
Reply
#3

Let me know how this works out:

Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{	
	new allowed;

	if (IsPlayerInAnyVehicle(playerid))
	{
		new vehicleid = GetPlayerVehicleID(playerid);

		for (new i = 0; i < MAX_PLAYERS; i++)
		{
			if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER)
			{
				allowed = 1;
				break;
			}
		}
		
		if (allowed == 0)
		{
			SendClientMessage (playerid, -1, "SERVER: You must have a driver to perform a drive-by!");
			SetPlayerArmedWeapon(playerid, 0);
		}
		
	}
	
	return 1;
}
Reply
#4

You sure this won't need a timer?
Reply
#5

Thanks it actually works.
Reply
#6

Quote:
Originally Posted by fatlirmorina
Посмотреть сообщение
You sure this won't need a timer?
Unless you want to check at intervals instead of shooting, no.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)