1) Bugs:When user becomes zombie if he has weapon in hand it creates a giftbox on the zombie which makes the zombies stuck inside the giftbox.
2) Please add a chance to get empty box as well. the box is empty.
3) Please make it like we can get any extra item also randomly but increase the chance to get empty box.
Code:
#include < amxmodx >
#include < cstrike >
#include < hamsandwich >
#include < engine >
#include < fakemeta >
#include < fun >
#include < zombieplague >
#define VERSION "1.2"
new const BOX_CLASSNAME[ ] = "func_bonusbox" ;
new const BOX_MODEL[ ] = "models/bonusbox.mdl" ;
new const BOX_SPRITE[ ] = "sprites/bonusbox_sprite.spr" ;
new g_iSprite ;
new g_iCvars[ 6 ] ;
new const g_szRestrictedEntities[ ][ ] = {
"weapon_hegrenade",
"weapon_flashbang",
"weapon_smokegrenade"
}
public plugin_init( ) {
register_plugin( "[ZP] GiftBox", VERSION, "DoNii" ) ;
RegisterHam( Ham_Touch, "weaponbox", "fw_HamTouchPre", 0 ) ;
RegisterHam( Ham_Touch, "armoury_entity", "fw_HamTouchPre", 0 ) ;
RegisterHam( Ham_Touch, "info_target", "fw_HamTouchPreInfoTarget", 0 ) ;
g_iCvars[ 0 ] = register_cvar( "giftbox_winhp", "30" ) ;
g_iCvars[ 1 ] = register_cvar( "giftbox_winarmor", "30" ) ;
g_iCvars[ 2 ] = register_cvar( "giftbox_losehp", "15" ) ;
g_iCvars[ 3 ] = register_cvar( "giftbox_winhenades", "3" ) ;
g_iCvars[ 4 ] = register_cvar( "giftbox_winflashbangs", "2" ) ;
g_iCvars[ 5 ] = register_cvar( "giftbox_winsmokenades", "1" ) ;
register_cvar( "giftbox_version", VERSION, FCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED ) ;
}
public plugin_precache( ) {
precache_model( BOX_MODEL ) ;
g_iSprite = precache_model( BOX_SPRITE ) ;
}
public fw_HamTouchPre( iEnt, iToucher ) {
if( ! pev_valid( iEnt ) )
return HAM_IGNORED ;
new szToucherClass[ 32 ], szEntClass[ 32 ] ;
pev( iToucher, pev_classname, szToucherClass, charsmax( szToucherClass ) ) ;
pev( iEnt, pev_classname, szEntClass, charsmax( szEntClass ) ) ;
if( equal( szToucherClass, "weaponbox" ) ) {
for( new i ; i < sizeof g_szRestrictedEntities ; i++ ) {
if( equal( szToucherClass, g_szRestrictedEntities[ i ] ) || equal( szEntClass, g_szRestrictedEntities[ i ] ) )
return HAM_IGNORED ;
}
new iEntBox = create_entity( "info_target" ) ;
new Float:vEntOrigin[ 3 ] ;
entity_get_vector( iEnt, EV_VEC_origin, vEntOrigin ) ;
entity_set_vector( iEntBox, EV_VEC_origin, vEntOrigin ) ;
entity_set_string( iEntBox, EV_SZ_classname, BOX_CLASSNAME ) ;
entity_set_model( iEntBox, BOX_MODEL ) ;
entity_set_int( iEntBox, EV_INT_solid, SOLID_BBOX ) ;
entity_set_int( iEntBox, EV_INT_movetype, MOVETYPE_PUSHSTEP ) ;
entity_set_size( iEntBox, Float:{ -2.0,-2.0,-2.0 },Float:{ 5.0,5.0,5.0 } ) ;
engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, vEntOrigin, 0 )
write_byte( TE_BEAMCYLINDER ) // TE id
engfunc( EngFunc_WriteCoord, vEntOrigin[ 0 ] ) // x
engfunc( EngFunc_WriteCoord, vEntOrigin[ 1 ] ) // y
engfunc( EngFunc_WriteCoord, vEntOrigin[ 2 ] ) // z
engfunc( EngFunc_WriteCoord, vEntOrigin[ 0 ] ) // x axis
engfunc( EngFunc_WriteCoord, vEntOrigin[ 1 ] ) // y axis
engfunc( EngFunc_WriteCoord, vEntOrigin[ 2 ] + 385.0 ) // z axis
write_short( g_iSprite ) // sprite
write_byte( 0 ) // startframe
write_byte( 0 ) // framerate
write_byte( 4 ) // life
write_byte( 1 ) // width
write_byte( 0 ) // noise
write_byte( random_num( 128, 255 ) ) // red
write_byte( random_num( 128, 255 ) ) // green
write_byte( random_num( 128, 255 ) ) // blue
write_byte( 25 ) // brightness
write_byte( 0 ) // speed
message_end( )
engfunc( EngFunc_DropToFloor, iEntBox ) ;
engfunc( EngFunc_RemoveEntity, iEnt ) ;
set_rendering( iEntBox, kRenderFxGlowShell, random_num( 128, 255 ), random_num( 128, 255 ), random_num( 128, 255 ), kRenderFxNone, 255 ) ;
}
return HAM_IGNORED ;
}
public fw_HamTouchPreInfoTarget( iEnt, iToucher ) {
if( zp_get_user_zombie( iToucher ) || zp_get_user_nemesis( iToucher ) )
return HAM_IGNORED ;
new szClassNameEnt[ 32 ], szClassNamePlayer[ 32 ] ;
pev( iEnt, pev_classname, szClassNameEnt, charsmax( szClassNameEnt ) ) ;
pev( iToucher, pev_classname, szClassNamePlayer, charsmax( szClassNamePlayer ) ) ;
if( ! equal( szClassNameEnt, BOX_CLASSNAME ) || ! equal( szClassNamePlayer, "player" ) )
return HAM_IGNORED ;
entity_set_int( iEnt, EV_INT_solid, SOLID_NOT ) ;
entity_set_int( iEnt, EV_INT_effects, MOVETYPE_PUSHSTEP ) ;
engfunc( EngFunc_RemoveEntity, iEnt ) ;
new iRandomNum = random_num( 1, 6 ) ;
switch( iRandomNum ) {
case 1 : {
set_user_health( iToucher, get_user_health( iToucher ) + get_pcvar_num( g_iCvars[ 0 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Won %d HP", get_pcvar_num( g_iCvars[ 0 ] ) );
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Won %d HP", get_pcvar_num( g_iCvars[ 0 ] ) ) ;
}
case 2 : {
set_user_armor( iToucher, get_user_armor( iToucher ) + get_pcvar_num( g_iCvars[ 1 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Won %d ARMOR", get_pcvar_num( g_iCvars[ 1 ] ) ) ;
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Won %d ARMOR", get_pcvar_num( g_iCvars[ 1 ] ) ) ;
}
case 3 : {
set_user_health( iToucher, get_user_health( iToucher ) - get_pcvar_num( g_iCvars[ 2 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Lost %d HP", get_pcvar_num( g_iCvars[ 2 ] ) ) ;
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Lost %d HP", get_pcvar_num( g_iCvars[ 2 ] ) ) ;
}
case 4 : {
give_item( iToucher, "weapon_hegrenade" ) ;
cs_set_user_bpammo( iToucher, CSW_HEGRENADE, get_pcvar_num( g_iCvars[ 3 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Won %d HE Grenade%s", get_pcvar_num( g_iCvars[ 3 ] ), get_pcvar_num( g_iCvars[ 3 ] ) != 1 ? "s" : "" ) ;
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Won %d HE Grenade%s", get_pcvar_num( g_iCvars[ 3 ] ), get_pcvar_num( g_iCvars[ 3 ] ) != 1 ? "s" : "" ) ;
}
case 5 : {
give_item( iToucher, "weapon_flashbang" ) ;
cs_set_user_bpammo( iToucher, CSW_FLASHBANG, get_pcvar_num( g_iCvars[ 4 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Won %d Flashbang%s", get_pcvar_num( g_iCvars[ 4 ] ), get_pcvar_num( g_iCvars[ 4 ] ) != 1 ? "s" : "" ) ;
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Won %d Flashbang%s", get_pcvar_num( g_iCvars[ 4 ] ), get_pcvar_num( g_iCvars[ 4 ] ) != 1 ? "s" : "" ) ;
}
case 6 : {
give_item( iToucher, "weapon_smokegrenade" ) ;
cs_set_user_bpammo( iToucher, CSW_SMOKEGRENADE, get_pcvar_num( g_iCvars[ 5 ] ) ) ;
client_print( iToucher, print_chat, "[GiftBox] You Just Won %d Smoke Grenade%s", get_pcvar_num( g_iCvars[ 5 ] ), get_pcvar_num( g_iCvars[ 5 ] ) != 1 ? "s" : "" ) ;
set_hudmessage( 0, 255, 0, 0.40, 0.35, 0, 6.0, 3.0 ) ;
show_hudmessage( iToucher, "[GiftBox] You Just Won %d Smoke Grenade%s", get_pcvar_num( g_iCvars[ 5 ] ), get_pcvar_num( g_iCvars[ 5 ] ) != 1 ? "s" : "" ) ;
}
}
return HAM_IGNORED ;
}
public zp_round_ended( ) {
new iEnt = -1 ;
while( ( iEnt = find_ent_by_class( iEnt, BOX_CLASSNAME ) ) != 0 ) {
if( is_valid_ent( iEnt ) )
remove_entity( iEnt ) ;
}
}
public zp_round_has_started( ) {
new iEnt = -1 ;
while( ( iEnt = find_ent_by_class( iEnt, BOX_CLASSNAME ) ) != 0 ) {
if( is_valid_ent( iEnt ) )
remove_entity( iEnt ) ;
}
}