Raised This Month: $ Target: $400
 0% 

give items to killer for kill


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-02-2012 , 09:42   give items to killer for kill
Reply With Quote #1

Hi! I'm noob in scripting, and this one, I think, is easy for you - smart guys. Basically I want to add a function to this super player code. I want to give bonus grenades for killer, if one kills the super player.


Code:
public super_kill()
{    

    new victim = read_data(2)
    
    if ( victim != gSuperPlayerCT || victim != gSuperPlayerT  ) return

    {
        
    new killer = read_data(1)
    give_item(killer,"weapon_hegrenade")
    cs_set_user_bpammo(killer,CSW_HEGRENADE,2)
    
    give_item(killer,"weapon_flashbang")
    cs_set_user_bpammo(killer,CSW_FLASHBANG,1)
    client_print(killer, print_center, "You've got a grenade bonus for killing superplayer!")
    
    }
}
So:

if ( victim != gSuperPlayerCT || victim != gSuperPlayerT ) return // this has no effect at all

And if I change it to:

if ( victim == gSuperPlayerCT || victim == gSuperPlayerT ) // after I kill the special player, game kicks me out and I get text in console:

Code:
SZ_GetSpace: overflow on netchan->message
WARNING: reliable overflow for me.
me. overflowed
Reliable channel over
Or:

// Maybe I'm registering event incorrectly:

register_event("DeathMsg", "super_kill", "a", "1>0")

Last edited by simple_user; 05-07-2012 at 23:14.
simple_user is offline
Send a message via Skype™ to simple_user
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 05-02-2012 , 09:56   Re: give items to killer if victim == special player
Reply With Quote #2

This is how i would do it

PHP Code:
register_event("DeathMsg""eDeath""a"
PHP Code:
public eDeath(id)
{
new 
ikiller read_data (1)
new 
ivictim read_data (2)

if (
ivictim == gSuperPlayerCT)
{
    
give_item(ikiller"weapon_hegrenade")
    
cs_set_user_bpammo(ikiller,CSW_HEGRENADE,2)

__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.
Bilal Pro is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-02-2012 , 10:57   Re: give items to killer if victim == special player
Reply With Quote #3

Quote:
Originally Posted by simple_user View Post
Hi! I'm noob in scripting, and this one, I think, is easy for you - smart guys. Basically I want to add a function to this super player code. I want to give bonus grenades for killer, if one kills the super player.


Code:
public super_kill()
{    

    new victim = read_data(2)
    
    if ( victim != gSuperPlayerCT || victim != gSuperPlayerT  ) return

    {
        
    new killer = read_data(1)
    give_item(killer,"weapon_hegrenade")
    cs_set_user_bpammo(killer,CSW_HEGRENADE,2)
    
    give_item(killer,"weapon_flashbang")
    cs_set_user_bpammo(killer,CSW_FLASHBANG,1)
    client_print(killer, print_center, "You've got a grenade bonus for killing superplayer!")
    
    }
}

So:

if ( victim != gSuperPlayerCT || victim != gSuperPlayerT ) return // this has no effect at all

And if I change it to:

if ( victim == gSuperPlayerCT || victim == gSuperPlayerT ) // after I kill the special player, game kicks me out and I get text in console:

Code:
SZ_GetSpace: overflow on netchan->message
WARNING: reliable overflow for me.
me. overflowed
Reliable channel over
Or:

// Maybe I'm registering event incorrectly:

register_event("DeathMsg", "super_kill", "a", "1>0")
Use hamsandwich. Its a little easier.
Code:
register_event("DeathMsg", "super_kill", "a", "1>0")

PHP Code:
RegisterHam("Ham_Killed""player""super_kill"1
This will directly give you the person who died, and the attacker

Code:
public super_kill()

PHP Code:
public super_kill(victimIDkillerIDshouldgib
Then inside we're gonna switch it up a bit....

PHP Code:
if(victimID != gSuperPlayerCT || victimID != gSuperPlayerT || !is_user_alive(killerID))
    return 
HAM_HANDLED

give_item
(killerID,"weapon_hegrenade")
cs_set_user_bpammo(killerID,CSW_HEGRENADE,2)
    
give_item(killerID,"weapon_flashbang")
cs_set_user_bpammo(killerID,CSW_FLASHBANG,1)
client_print(killerIDprint_center"You've got a grenade bonus for killing superplayer!")

return 
HAM_HANDLED 
I changed the if statement to check to see if the victim is NOT a super_player, as well as if the killer is dead. This way it returns out of the function quicker, less hopping around code, and i feel it looks cleaner. I added !is_user_alive because there's no sense giving grenades to a dead client, is there?

The variables were changed to reflect the new header

shouldgib isn't used. Ignore that variable.
Liverwiz is offline
Old 05-02-2012, 11:11
simple_user
This message has been deleted by simple_user. Reason: ,
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-02-2012 , 11:43   Re: give items to killer if victim == special player
Reply With Quote #4

Looks fine to me, but now it doesn't compile.

HTML Code:
error 035: argument type mismatch <argument 1>
1 error

in line 79:
HTML Code:
RegisterHam("Ham_Killed", "player", "super_kill", 1)
simple_user is offline
Send a message via Skype™ to simple_user
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 05-02-2012 , 11:59   Re: give items to killer if victim == special player
Reply With Quote #5

RegisterHam("Ham_Killed", "player", "super_kill", 1)
->
RegisterHam(Ham_Killed, "player", "super_kill", 1)
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-02-2012 , 12:44   Re: give items to killer if victim == special player
Reply With Quote #6

no errors in compiling. no grenades if super player killed, either.

ok. I made a conditional statement:

Code:
if(victimID == gSuperPlayerCT || victimID == gSuperPlayerT )
still no results

Last edited by simple_user; 05-02-2012 at 12:50.
simple_user is offline
Send a message via Skype™ to simple_user
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-02-2012 , 13:08   Re: give items to killer if victim == special player
Reply With Quote #7

what data type is gSuperPlayerCT/T? Make sure they are, in fact, IDs for the player you wish them to be. Try this as a means of debug....it'll print the name of the player that killed you, if that method is even called.

PHP Code:
//function header of super_kill
new sz_attacker[32], sz_victim[32]
get_user_name(attackerIDsz_attacker31)
get_user_name(victimIDsz_victim31)
        
// say if the function was even called
client_print(0print_chat"[Debug] %s killed %s"sz_attackersz_victim)    
if(
victimID != gSuperPlayerCT || victimID != gSuperPlayerT || !is_user_alive(killerID)) 
{
        
// confirm gSuperPlayer is improperly used
    
client_print(attackerIDprint_chat"[Debug] %s was not a SuperPlayer"sz_victim)    
    return 
HAM_HANDLED 
}
        
// giving the grenades isn't done right
client_print(attackerIDprint_chat"[Debug] %s was, in fact, a SuperPlayer"sz_victim)    

give_item(killerID,"weapon_hegrenade"
cs_set_user_bpammo(killerID,CSW_HEGRENADE,2
     
give_item(killerID,"weapon_flashbang"
cs_set_user_bpammo(killerID,CSW_FLASHBANG,1
client_print(killerIDprint_center"You've got a grenade bonus for killing superplayer!"

return 
HAM_HANDLED 
Liverwiz is offline
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-02-2012 , 13:21   Re: give items to killer if victim == special player
Reply With Quote #8

new gSuperPlayerT
new gSuperPlayerCT

these are variables.

do I need to make id equal to gSuperPlayer, like in this code? :

Code:
    if ( id )
    {
        if ( get_user_team(id) == 1 )
        {
            if ( gSuperPlayerT == id ) return
            
            SetAbilities(id)
            gSuperPlayerT = id
        }
        
        else
        {
            event_choose_terrorist()
simple_user is offline
Send a message via Skype™ to simple_user
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-02-2012 , 13:29   Re: give items to killer if victim == special player
Reply With Quote #9

if(id) {
will NEVER proceed. There is no condition in that statement.

but, yes, that's what you have to do to set that, assuming the context is right.
Liverwiz is offline
simple_user
Member
Join Date: Apr 2012
Location: Latvia, the cube
Old 05-02-2012 , 13:32   Re: give items to killer if victim == special player
Reply With Quote #10

function is called.

Last edited by simple_user; 05-06-2012 at 02:35.
simple_user is offline
Send a message via Skype™ to simple_user
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 07:45.


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