[Tutorial] Stop player shooting on vehicles [First tutorial]
#1

Hello this first tutorial

What is can do?:

This can stop player shooting on vehicles.

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
   	if(GetPlayerWeapon(playerid) != 29) // MP5
           {
      		SetPlayerArmedWeapon(playerid, 0);
           }
     }
     return 1;
}
or

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
      if(newkeys & KEY_FIRE)
     {
             if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    	     {
   	             if(GetPlayerWeapon(playerid) == 29 )
        	     {
      			     SetPlayerArmedWeapon(playerid, 0);
		     }
	     }
      }
      return 1;
}
You can use this to stop player shooting on vehicle in your gamemode!
Reply
#2

It's a tutorial board and you've to EXPLAIN the snippet you posted! And your first code won't avoid driveby as you're checking if it's not MP5. Also, MP5 isn't the only weapon which allows driveby.
Reply
#3

I will suggest read this document: https://sampforum.blast.hk/showthread.php?tid=65567 on "How to Write a Tutorial" by ******.
Reply
#4

I would suggest removing the weapon check if(GetPlayerWeapon(playerid) != 29) and just set the players armed weapon to 0 when they enter a car at all.

Like this
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
   		SetPlayerArmedWeapon(playerid, 0);
    }
    return 1;
}
This code works, so whenever someone gets inside any seat of a car their weapons are set to fists.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)