AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Grenade Bonus (https://forums.alliedmods.net/showthread.php?t=126288)

DjOptimuS 05-07-2010 23:50

Grenade Bonus
 
I tried to write a plugin, that gives 1 grenade to a player that makes a frag with a grenade.

Here is the code

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "Grenade Bonus"
#define VERSION "1.0"
#define AUTHOR "OptimuS"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("DeathMsg""playerDeath""a""1>0")
}

public 
playerDeath()
{
    new 
killer read_data(1)
    new 
victim read_data(2)
    new 
weapon[8]
    
read_data(4weapon7)
 
    if (
killer != victim && equal(weapon"grenade"))
    {
        new 
clipammo
        
new const uid get_user_index(killer)
        
get_user_ammo(uidCSW_HEGRENADEclipammo)
        if(
ammo == 0)
        {
            
give_item(uid"weapon_hegrenade")
        }
    }

        


And this is the error log from the compiler

Code:

//// groptimus.sma
// D:\groptimus.sma(26) : error 035: argument type mismatch (argume
nt 1)

Line 26 is

new const uid = get_user_index(killer);

Any help would be appreciated, thank you.

HLM 05-08-2010 00:27

Re: Grenade Bonus
 
untested, but this should explain it a bit more..

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "Grenade Bonus"
#define VERSION "1.0"
#define AUTHOR "OptimuS"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("DeathMsg""playerDeath""a""1>0")
}

public 
playerDeath()
{
    new 
killer read_data(1//get the fragger's _index_
    
new victim read_data(2//get the dead persons index
    
new weapon[8]
    
read_data(4weapon7)
 
    if (
killer != victim && equal(weapon"grenade"))
    {
        new 
clipammo
        
//new const uid = get_user_index(killer) //not needed since killer = uid
        
get_user_ammo(killerCSW_HEGRENADEclipammo)
        if(
ammo == 0)
        {
            
give_item(killer"weapon_hegrenade")
        }
    }

        



Bugsy 05-08-2010 00:37

Re: Grenade Bonus
 
I added an is_user_connected() check to prevent an error if a player tosses a killing nade and he disconnects before the kill occurs. You will need to include cstrike module.
PHP Code:

#include <amxmodx>
#include <fun>
#include <cstrike>

register_event"DeathMsg" "playerDeath" "a" "1>0" )

public 
playerDeath()
{
    new 
iKiller read_data);
    new 
iVictim read_data);
    new 
szWeapon]; read_dataszWeapon charsmaxszWeapon ) );
 
    if ( ( 
iKiller != iVictim ) && equalszWeapon "grenade" ) && is_user_connectediKiller ) && !cs_get_user_bpammoiKiller CSW_HEGRENADE ) )
    {
        
give_itemiKiller "weapon_hegrenade" );
    }



Leon M. 05-08-2010 02:00

Re: Grenade Bonus
 
Why you didn't use the original natives? If you use give_item then you must not check the backpack ammo.

PHP Code:

#define PLUGIN     "Nade Giver or something else"
#define AUTHOR     "me"
#define VERSION     "0.1"

#include <amxmodx>
#include <fun>

public plugin_init(){
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
client_death(iKilleriVictimiWeaponiHitplaceTK){
    if (!
TK && is_user_alive(iKiller)){
        if (
iWeapon == CSW_HEGRENADE){
            
give_item(iKiller"weapon_hegrenade")
        }
    }



DjOptimuS 05-08-2010 06:41

Re: Grenade Bonus
 
"killer" is not the userid, killer is the killer's name, read through event.

Thank you Leon.

Bugsy 05-08-2010 07:41

Re: Grenade Bonus
 
Quote:

Originally Posted by DjOptimuS (Post 1174259)
"killer" is not the userid, killer is the killer's name, read through event.

Killer is the players id (not userid). To obtain the players name in DeathMsg you must use get_user_name( killer , [...] ).
  • DeathMsg
    • byte KillerID
    • byte VictimID
    • byte IsHeadshot
    • string TruncatedWeaponName

Why not check all conditions with a single if()?
PHP Code:

public client_deathiKiller iVictim iWeapon iHitplace TK )
{
    if ( ( 
iWeapon == CSW_HEGRENADE ) && !TK && is_user_aliveiKiller ) )
    {
        
give_item(iKiller"weapon_hegrenade")
    }



DjOptimuS 05-08-2010 08:34

Re: Grenade Bonus
 
Thank you all, but what about the killer, hit's 2 targets, he will get 2 grenades ? Or HLDS limit's by default hegrenade to only 1 unit ?

DarkGod 05-08-2010 08:43

Re: Grenade Bonus
 
Quote:

Originally Posted by DjOptimuS (Post 1174322)
Thank you all, but what about the killer, hit's 2 targets, he will get 2 grenades ? Or HLDS limit's by default hegrenade to only 1 unit ?

Using give_item() you can only get one HE. You can use cs_set_user_bpammo() to give them extra if they kill more.

DjOptimuS 05-08-2010 08:50

Re: Grenade Bonus
 
No, i just want to give them only 1 HE, no matter the number of kills. Thank you.


All times are GMT -4. The time now is 03:45.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.