[Tutorial] "Kick gun"
#1

Introduction:
There suddenly has been a craze for the "Kick gun" on the forum, lately. There are tutorials on this already but I thought they were not either explained enough or weren't explained properly. I didn't really care about correcting them or making a tutorial about "Kick guns", neither do I like the idea of a kick gun but most of the communities based on SA-MP are not very serious about their servers or either like "fun", they think they must have things like these to make it look more immature, more fun. I am not criticizing anything or anyone, perhaps they have a better use to it that I can't think of. This is my first tutorial, and my first tutorial based on boredom. I was bored and didn't have anything to do and thought why not make a tutorial. Since this was the latest "craze" around the forum, I thought I'd make a tutorial regarding this. The tutorial isn't intended to be copy/pasted but to be understood and learned (who am I saying this to). The same steps provided in this tutorial, a bit tweaked perhaps, can be used to make a ban gun, a one hit kill gun, a jail gun....... endless possibilities.

A "kick gun":
A kick gun (as far as I understand) is defined as a gun that is used to kick players. In simpler words, you can use a weapon, any weapon, to shoot at a player and kick them. The kick would be a result of the shot made from that weapon. The weapon can be specified or your can use it with all weapons.

Making a "kick gun":
I have explained each and everything using comments. I don't like the idea of using the forum to break the code and explain the parts individually, that is my thought, though. The idea behind the kick gun is tracking a player giving/taking damage to/from another player and then checking if it was the specified kick weapon or the shooter having the kick gun, and kicking the player taking the damage.

pawn Code:
/*
#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.

}
Last words:
I might have made some mistakes in the explanation, code above and won't mind criticisms, suggestions and feedbacks.
Reply
#2

The previous tutorial was "https://sampforum.blast.hk/showthread.php?tid=435626"
Same topic

But this seems better
Reply
#3

Y_Less, I guess it's about a weapon that can be used to kick players by shooting them or something.
Reply
#4

I did this a while ago except we had a kick bat and ban hammer.
Reply
#5

Quote:
Originally Posted by Yashas
View Post
The previous tutorial was "https://sampforum.blast.hk/showthread.php?tid=435626"
Same topic

But this seems better
Well, basically, that's the point.

Quote:
Originally Posted by Y_Less
View Post
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've done line lengths, you still have to scroll around a bit though. I had also defined a "kick gun" in the introduction but I guess it was incomplete.

Quote:
Originally Posted by [uL]Pottus
View Post
I did this a while ago except we had a kick bat and ban hammer.
A ban hammer sounds quite interesting but I don't like the idea of it. I'd rather click ban or command ban someone but again, that's personal preference. It can be coded using the same tutorial but a bit "tweaked", I guess.
Reply
#6

I found a little typo in the code:

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.

This means, that if the player took damage from a player, the following code will not be executed, wich is the exact opposite of what you want, because "issuerid" will be INVALID_PLAYER_ID if the damage was self-inflicted (falling, explosives, etc.). Change it to ==.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)