/*
#include <a_samp> // In case you already haven't included it.
*/
new
allowPlayerToUseKickGun[MAX_PLAYERS]
// Defining a (global) variable. We use a global variable since we will be using this variable in a non-limited scope.
;
#define WEAPON_ID_USED_FOR_KICKING 24
// Defining a certain weapon for the "kick gun". You don't want every weapon to be able to kick. Incase you do, it is also included in this tutorial.
CMD:onduty(playerid, params[]) // Assuming you are using ZCMD or YCMD. We want it to only kick players Admins are on duty.
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Access denied."); // Check if a player is logged in as an RCON administrator and if
// not logged in, disallow him to use the command and only send his client a message saying "Access denied".
// You can replace IsPlayerAdmin with your variable containing the player's admin level and restrict it to certain admin levels only. For example:
/*
if(adminLevel[playerid] < 3) // Assuming your variable containing the admin levels is "adminLevel", you check for the player's level
return SendClientMessage(playerid, -1, "Access denied); // If the above condition is met, the player is a lower level admin,
// he'll recieve a message saying "Access denied.".
// You can edit the message to tell him what level is required for the command either. I'll assume you know that, at least.
*/
// Check the rest of the things you want to here
/* Incase you don't know how to check
Let's suppose you want to check if the player is spawned or not:
if(GetPlayerState(playerid) != PLAYER_STATE_SPAWNED) // Check if the player is spawned using his current state.
// You can also check if he is spawned with a simple variable that you trigger OnPlayerSpawn and OnPlayerDeath.
return SendClientMessage(playerid, -1, "You aren't spawned."); // If the above condition is met i.e. the player isn't spawned,
// a message "You aren't spawned." will be sent to his client.
You can also check if the player is already on duty or not.
Likewise, you can check for other things here as well.
*/
allowPlayerToUseKickGun[playerid] = 1; // Set the variable to allow the script, later, know that the player can use the kick gun.
// If you don't set this, the kick gun won't work. We will check for this later under OnPlayerGiveDamage or OnPlayerTakeDamage.
GivePlayerWeapon(playerid, WEAPON_ID_USED_FOR_KICKING, 999); // Give the player, executing the command,
// the weapon you want the player to use to kick players, in case he doesn't have it.
SendClientMessage(playerid, -1, "You can now use the kick gun."); // Sending the player using the command a confirmation message.
return 1; // This is to tell the script that the command was successfully executed.
// If returned 0 (return 0;) the player will see a message saying Unknown command, though, the command will work.
}
CMD:offduty(playerid, params[])
{
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "Access denied."); // Check if a player is logged in as an RCON administrator and
// if not logged in, disallow him to use the command and only send his client a message saying "Access denied". Copy/Paste :)
// As stated above, you can check for other things here as well. I won't go deep into this since it's already explained in the above command.
// You can also check if the player is already on duty or not or if he can use the kick gun already or not.
allowPlayerToUseKickGun[playerid] = 0; // Set the variable to allow the script to differentiate between players who can use the kick gun.
// If this isn't toggled back to 0, the player would still be able to kick players.
SendClientMessage(playerid, -1, "You can't use the kick gun anymore."); // Sending the player a confirmation message.
return 1; // Letting the script know the command executed successfully.
}
/* This is the main part. This is the part where we check for damage on a player and then check if the player is
using the kick gun and incase he is, kick the player.
We can use OnPlayerTakeDamage or OnPlayerGiveDamage. Let's see how to use them. */
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) /* OnPlayerTakeDamage is called when a player takes damage (you don't say!).
The 'playerid' parameter shows the player who took damage, 'issureid' shows the player who gave damage to the player (can be invalid as well),
'amount' shows the amount of damage sustained by 'playerid' and 'weaponid' represents the weapon by 'issuerid' to give 'amount' damage to 'playerid'. */
{
if(issuerid == INVALID_PLAYER_ID) // Check if the 'issureid' isn't an invalid player.
return 1; // Letting the script return back and not execute the upcoming code.
if(allowPlayerToUseKickGun[issuerid] != 1) // Checking if the player can use the kick gun or not. In this case, we check if the player can't use the kick gun.
return 1; // Letting the script return back and not execute the upcoming code.
/*
Checking if the player is admin. It isn't necessary, though, since the allowPlayerToUseKickGun is only triggered for RCON administrators.
if(!IsPlayerAdmin(issuerid)) // Checking if the player is logged in RCON.
return 1; // Letting the script return back and not execute the upcoming code.
*/
// Incase you want to check if the player is using the kick gun
if(weaponid != WEAPON_ID_USED_FOR_KICKING) // If the player isn't using the kick gun.
// If you don't want the kick gun to be a single weapon or in other words, you want to use all weapons as a kick gun, don't check this.
return 1; // Letting the script return back and not execute the upcoming code.
// You can send a message to the player here as well but since 0.3x, it won't work unless you time it or use an alternate function. Won't go deep into this.
Kick(playerid); // Kick the player who was shot at.
return 1; // Letting the script know the OnPlayerTakeDamage was successful.
}
// You can use OnPlayerGiveDamage as well. Let's see how to do that:
// NOTICE: Don't use both at once.
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid) // OnPlayerGiveDamage is called when a player gives damage to another player.
/* The difference between OnPlayerGiveDamage and OnPlayerTakeDamage is not much except that the player who gave damage in OnPlayerGiveDamage cannot be invalid
while in OnPlayerTakeDamage can be. 'playerid' denotes the player who is shooting, 'damagedid' denotes the player who is taking the shots (ouch!), 'amount'
denotes the amount of damage while 'weaponind' denotes the weapon used by 'playerid' to inflict 'amount' damage on 'damagedid'. */
{
if(allowPlayerToUseKickGun[playerid] != 1) // Checking if the player can use the kick gun or not. In this case, we check if the player can't use the kick gun.
return 1; // Letting the script return back and not execute the upcoming code.
/*
Checking if the player is admin. It isn't necessary, though, since the allowPlayerToUseKickGun is only triggered for RCON administrators.
if(!IsPlayerAdmin(playerid)) // Checking if the player is logged in RCON.
return 1; // Letting the script return back and not execute the upcoming code.
*/
if(weaponid != WEAPON_ID_USED_FOR_KICKING) // If the player isn't using the kick gun.
// If you don't want the kick gun to be a single weapon or in other words, you want to use all weapons as a kick gun, don't check this.
return 1; // Letting the script return back and not execute the upcoming code.
// You can send a message to the player here as well but since 0.3x, it won't work unless you time it or use an alternate function. Won't go deep into this.
Kick(damagedid); // Kick the player who was shot at.
return 1; // Letting the script know the OnPlayerGiveDamage was successful.
}
The previous tutorial was "https://sampforum.blast.hk/showthread.php?tid=435626"
Same topic But this seems better ![]() |
Please use set line lengths on your comments - having to scroll both horizontally and vertically to read what you are saying is very tricky! You missed one VERY important piece of information - what is a kick gun?
|
I did this a while ago except we had a kick bat and ban hammer.
|