Raised This Month: $ Target: $400
 0% 

Grenade Bonus


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 05-07-2010 , 23:50   Grenade Bonus
Reply With Quote #1

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.
DjOptimuS is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 05-08-2010 , 00:27   Re: Grenade Bonus
Reply With Quote #2

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")
        }
    }

        

__________________
+|- KARMA Respectively

HLM is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-08-2010 , 00:37   Re: Grenade Bonus
Reply With Quote #3

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

__________________

Last edited by Bugsy; 05-08-2010 at 00:45.
Bugsy is offline
Leon M.
Senior Member
Join Date: Apr 2009
Location: Germany
Old 05-08-2010 , 02:00   Re: Grenade Bonus
Reply With Quote #4

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")
        }
    }


Last edited by Leon M.; 05-08-2010 at 02:05.
Leon M. is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 05-08-2010 , 06:41   Re: Grenade Bonus
Reply With Quote #5

"killer" is not the userid, killer is the killer's name, read through event.

Thank you Leon.

Last edited by DjOptimuS; 05-08-2010 at 07:11.
DjOptimuS is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-08-2010 , 07:41   Re: Grenade Bonus
Reply With Quote #6

Quote:
Originally Posted by DjOptimuS View Post
"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")
    }

__________________

Last edited by Bugsy; 05-08-2010 at 07:49.
Bugsy is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 05-08-2010 , 08:34   Re: Grenade Bonus
Reply With Quote #7

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 ?
DjOptimuS is offline
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 05-08-2010 , 08:43   Re: Grenade Bonus
Reply With Quote #8

Quote:
Originally Posted by DjOptimuS View Post
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.
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 05-08-2010 , 08:50   Re: Grenade Bonus
Reply With Quote #9

No, i just want to give them only 1 HE, no matter the number of kills. Thank you.
DjOptimuS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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