Raised This Month: $ Target: $400
 0% 

Knife Reward


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Big Joe
Junior Member
Join Date: Sep 2009
Old 12-02-2010 , 13:44   Knife Reward
Reply With Quote #1

Hi there! I wanted to make a plugin, that will count 3 knife kills per round and give a player a reward.
PHP Code:
#include <amxmodx>
 
new knife[32] = {0,...}
public 
plugin_init() {
 
register_plugin("Knife Reward","1.0","Big Joe")
 
register_event("RoundTime""eventStartRound""bc")
}
public 
client_death(killerwpnindex)
{
 if (
wpnindex == CSW_KNIFE)
               {
         new 
killer_name[32]
 
  
get_user_name(killerkiller_name31)
                
knife[killer] ++
        }
 
 if (
knife[killer] == 3
        {
  
server_cmd("molotov_give %s"killer)
        }
}
public 
client_putinserver(id) {
 
knife[id] = 0;
 
 return 
PLUGIN_CONTINUE
}
public 
eventStartRound (id) {
 
knife[id] = 0;
 
 return 
PLUGIN_CONTINUE

The code compiles, but doesn't work, though the molotov plugin is ON. Help, plz!
Big Joe is offline
Racoon
Senior Member
Join Date: Mar 2008
Location: Ukraine
Old 12-03-2010 , 05:29   Re: Knife Reward
Reply With Quote #2

Why don't you hook Deathmsg?
Racoon is offline
Send a message via ICQ to Racoon
Vechta
Veteran Member
Join Date: Jun 2010
Old 12-03-2010 , 08:28   Re: Knife Reward
Reply With Quote #3

PHP Code:
#include <amxmodx>

new g_kills[33]

public 
plugin_init() 
    
register_event("DeathMsg""Event_Deathmsg""a")
    
public 
Event_DeathMsg()
{
    new 
attacker read_data(1)
    
    if (
get_user_weapon(attacker) == CSW_KNIFE)
    {
        
g_kills[attacker]++
        
        if (
g_kills[attacker] == 3)
        {
            
g_kills[attacker] -= 3
            server_cmd
("molotov_give %s"attacker)
        }
    }

Maybe this work?
Vechta is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-03-2010 , 08:58   Re: Knife Reward
Reply With Quote #4

Quote:
Originally Posted by Vechta View Post
PHP Code:
#include <amxmodx>

new g_kills[33]

public 
plugin_init() 
    
register_event("DeathMsg""Event_Deathmsg""a")
    
public 
Event_DeathMsg()
{
    new 
attacker read_data(1)
    
    if (
get_user_weapon(attacker) == CSW_KNIFE)
    {
        
g_kills[attacker]++
        
        if (
g_kills[attacker] == 3)
        {
            
g_kills[attacker] -= 3
            server_cmd
("molotov_give %s"attacker)
        }
    }

Maybe this work?
You need to reset g_kills counter on client disconnect
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Vechta
Veteran Member
Join Date: Jun 2010
Old 12-03-2010 , 09:04   Re: Knife Reward
Reply With Quote #5

I would add it, if it be requested xD
Vechta is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 12-03-2010 , 10:08   Re: Knife Reward
Reply With Quote #6

You also need to check if attacker is a player entity:
Code:
#include <amxmodx> #define is_user_valid_connected(%1) (1 <= %1 <= 32 && g_connected[ %1 ]) new g_kills[33], g_connected[33] public plugin_init() register_plugin( "how", "r", "u" )     register_event("DeathMsg", "Event_Deathmsg", "a")       public Event_DeathMsg() {     static attacker; attacker = read_data(1)         if (is_user_valid_connected(attacker) && get_user_weapon(attacker) == CSW_KNIFE)     {         g_kills[attacker]++                   if (g_kills[attacker] == 3)         {             g_kills[attacker] -= 3             server_cmd("molotov_give %s", attacker)         }     } } public client_disconnect( id ) g_connected[ id ] =false     g_kills[ id ] = 0 public client_connect( id ) g_connected[ id ] = true
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Big Joe
Junior Member
Join Date: Sep 2009
Old 12-03-2010 , 14:14   Re: Knife Reward
Reply With Quote #7

Thank you very much for the reply!
abdul-rehman, I've looked through your code, but couldn't find a place, where you reset knife kills at the begining of each round.
Big Joe is offline
Racoon
Senior Member
Join Date: Mar 2008
Location: Ukraine
Old 12-03-2010 , 18:21   Re: Knife Reward
Reply With Quote #8

You need to register hamsandwich, if you want to hook three knife kills only during the round.
PHP Code:
#include <amxmodx> 
#include <hamsandwich>

#define is_user_valid_connected(%1) (1 <= %1 <= 32 && g_connected[ %1 ])
new g_kills[33], g_connected[33]

public 
plugin_init() {
    
register_plugin"Bonus Molotov""version""author" )
    
register_event("DeathMsg""Event_Deathmsg""a"
           
RegisterHam(Ham_Spawn,"player","playerSpawn")
}
    
public 
Event_DeathMsg() {
    static 
attackerattacker read_data(1)
    
    if (
is_user_valid_connected(attacker) && get_user_weapon(attacker) == CSW_KNIFE)
    {
        
g_kills[attacker]++ 
        
        if (
g_kills[attacker] == 3
        {
            
g_kills[attacker] -= 
            server_cmd
("molotov_give %s"attacker)
        }
    }
}

public 
client_disconnectid ) { 
    
g_connectedid ] =false
    g_kills
id ] = 0
}

public 
client_connectid ) { 
    
g_connectedid ] = true
}

public 
playerSpawn(id) {
        
g_connectedid ] = true
    g_kills
id ] = 0

Racoon is offline
Send a message via ICQ to Racoon
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 11:23.


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