PDA

View Full Version : how to add drive by , help me?


linhpro200294
13/07/2018, 07:54 AM
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?


// 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, 28);
}
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);
}

linhpro200294
13/07/2018, 08:18 AM
Help me please?

linhpro200294
13/07/2018, 10:56 AM
So how can I make DB guns?
Do I need to adjust my code?

linhpro200294
13/07/2018, 11:03 AM
This is a normal line of code in the model I have available now that can make other guns DB help you please?


// 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);
}

ItsRobinson
13/07/2018, 07:31 PM
Under OnPlayerKeyStateChange (http://wiki.sa-mp.com/wiki/OnPlayerKeyStateChange)


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.1, 0, 0, 0, 0, 0, 0); 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.1, 0, 0, 0, 0, 0, 0); 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)