how to add drive by , help me?
#1

This is code I wrote in my gamemode to use the DB on the Horn press, I have F5 back it. It is not completely fault but in the game get guns, for example M4 on the car press Horn can not DB if anyone know fix help me with please?


Quote:

// Timer Name: ServerHeartbeatTwo()
// TickRate: 1 secs.
task ServerHeartbeatTwo[9000]() {

foreach(new i: Player)
{
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][3] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 25);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][2] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 24);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][5] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 30);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][5] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 31);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][6] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 33);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][4] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 32);
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][4] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 2;
}
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][2] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 22);
}

Reply
#2

Help me please?
Reply
#3

So how can I make DB guns?
Do I need to adjust my code?
Reply
#4

This is a normal line of code in the model I have available now that can make other guns DB help you please?


Quote:

// Timer Name: ServerHeartbeatTwo()
// TickRate: 1 secs.
task ServerHeartbeatTwo[1000]() {

foreach(new i: Player)
{
if(IsPlayerInAnyVehicle(i)) {
if(GetPlayerState(i) == PLAYER_STATE_DRIVER) SetPlayerArmedWeapon(i, 0);
else if(PlayerInfo[i][pGuns][3] == 0) SetPlayerArmedWeapon(i, 0);
else SetPlayerArmedWeapon(i, 25);
}

Reply
#5

Under OnPlayerKeyStateChange

PHP код:
if ((newkeys 2) && !(oldkeys 2)) //key 2 is what we have to use to check if the key pressed was H.
{
    if(
IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) != 0)
    {
        switch(
GetPlayerWeapon(playerid))
        {
            case 
31: {SendClientMessage(playerid, -1"You can't drive-by with this weapon."); ApplyAnimation(playerid"PED""CAR_sitp"4.1000000); return 1;}
            case 
/*weapon id you don't want to be able to driveby with, i.e. m4*/: {SendClientMessage(playerid, -1"You can't drive-by with this weapon."); ApplyAnimation(playerid"PED""CAR_sitp"4.1000000); return 1;}
        }
    }

Code above will check to see the player press the H key, then check to see if they're in a vehicle and not in the drivers seat.

It will then check the weapon the player has (in-hand) and if it comes up with any ID's you check for, it'll respond with the code you entered.

In my code, if the weapon they're using isn't allowed, it sends them a message and places them back in the passenger seat (if I didn't put them back in the passenger seat, it would still allow them to drive-by, so I'd recommended also using ApplyAnimation to put them back in the passenger seat)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)