In-Car drive by weapons
#1

Ok guys well, I've already tried this and I really can't get it. All the weapons I want are the SMG, UZI, TEC 9, AK47 & M4. I've tried this last time but I couldn't get both with the class of "Driveby Weapons" and "Assault Rifles". How do I make it that when a player enters a car, no matter he has a "Driveby-able" gun or a "assault rifle" gun, he can use it in a driveby. The rest such as deagles and shotguns nah.... . Well I will provide the code below and hope someone could shed some light on this matter for me greatly.

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( newstate == PLAYER_STATE_DRIVER )
    {
        SetPlayerArmedWeapon( playerid, 0 );
	}
	if( newstate == PLAYER_STATE_PASSENGER )
	{
		SetPlayerArmedWeapon( playerid, 28 );
	}
	if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
	{
	    StopAudioStreamForPlayer(playerid); // Stop the audio stream
        }
         return 1;
}
Currently: The guns that I can use for driveby are the SMG, Tec9 and Uzi even when I just added one ID which was the: (2 UZI. Now how do I also make it assault rifle supported too?
Reply
#2

Are you asking for something like you need the passenger to use whatever weapon he/she got while entering the vehicle? And if it's in case a shotgun or any weapon that's not valid for driveby, he/she would get a weapon on hand which is currently there on the weapon slots of the player? If yes, this is it. I've created an array to store valid Drive by weapons and in case if player enters with any weapon ID which isn't mentioned on this array it will be scanning player's weapon slots and check in case if he/she got a valid weapon for driveby. If not, they'll be disarmed on the vehicle.

pawn Код:
new DriveBy_Weps[] =
{
31,
30,
22,
28,
29,
32}; //Add more ids if you want.

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
        SetPlayerArmedWeapon(playerid, 0);
    else if(newstate == PLAYER_STATE_PASSENGER)
    {
        new bool:DBWep = false, DBWep2 = false;
        for(new i; i< sizeof(DriveBy_Weps); i++)
        {
            if(GetPlayerWeapon(playerid) == DriveBy_Weps[i])
            {
                SetPlayerArmedWeapon(playerid, DriveBy_Weps[i]);
                DBWep = true;
                break;
            }
        }
        if(DBWep == false)
        {
            new p_WepData[13][2];
            for(new i; i< 13; i++)
            {
                GetPlayerWeaponData(playerid, i, p_WepData[i][0], p_WepData[i][1]);
                for(new a; a< sizeof(DriveBy_Weps); a++)
                {
                    if(p_WepData[i][0] == DriveBy_Weps[i] && p_WepData[i][1] >= 1)
                    {
                        SetPlayerArmedWeapon(playerid, DriveBy_Weps[i]);
                        DBWep2 = true;
                        break;
                    }
                }
                if(i >= 12 && !DBWep2)
                {
                    SetPlayerArmedWeapon(playerid, 0);
                    break;
                }
            }
        }
    }
    if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        StopAudioStreamForPlayer(playerid);
    return 1;
}
Reply
#3

Lordz, I tried out the code and it worked fine but then when I got in the car with a deagle, I could fire with it. I only want the drive by weapons and assault rifles. I removed ID 22 which was the 9mm but still I could fire with a deagle...
Reply
#4

Try this code:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
        SetPlayerArmedWeapon(playerid, 0);
    else if(newstate == PLAYER_STATE_PASSENGER) {
        new
            bool:DBWep = false;
        for(new i = 0; i< sizeof(DriveBy_Weps); i++) {
            if(GetPlayerWeapon(playerid) == DriveBy_Weps[i]) {
                SetPlayerArmedWeapon(playerid, DriveBy_Weps[i]);
                DBWep = true;
                break;
            }
        }
        if(DBWep) return 1;
        else if(!DBWep) {
            new
                bool:DBWep2 = false,
                p_WepData[13][2];
            for(new i = 0; i< 13; i++) {
                GetPlayerWeaponData(playerid, i, p_WepData[i][0], p_WepData[i][1]);
                for(new a; a< sizeof(DriveBy_Weps); a++) {
                    if(p_WepData[i][0] == DriveBy_Weps[a] && p_WepData[i][0] >= 1) {
                        SetPlayerArmedWeapon(playerid, DriveBy_Weps[a]);
                        DBWep2 = true;
                        break;
                    }
                }
                if(DBWep2) break;
            }
        }
        if(!DBWep2) return SetPlayerArmedWeapon(playerid, 0), 1;
    }
    return 1;
}
I think I made mistakes inside the looping part before, the array index given were incorrect.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)