Quote:
Originally Posted by simple_user
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(victimID, killerID, shouldgib)
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(killerID, print_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.