#include #include #include #include #define PLUGIN_NAME "Real Weapon Drop" #define PLUGIN_VERSION "1.2" #define PLUGIN_AUTHOR "Numb" new weaponbox_encoded; new get_user_msgid_AmmoPickup; new Array:ammo_entery_datas; new ammo_entery_num; new bool:alive[33]; new cs_ammo_weapons[10] = { CSW_AWP, CSW_SCOUT, CSW_M249, CSW_M4A1, CSW_M3, CSW_USP, CSW_FIVESEVEN, CSW_DEAGLE, CSW_P228, CSW_GLOCK18 }; new cs_ammo_max[10] = { 30, 90, 200, 90, 32, 100, 100, 35, 52, 120 }; new cs_ammo_id[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; new const ammo_model[] = "models/w_357ammobox.mdl"; new const ammo_sound[] = "items/9mmclip2.wav"; // cs standart - "items/9mmclip1.wav" public plugin_init() { register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR); RegisterHam(Ham_Spawn, "weaponbox", "Ham_FOSpawn_weaponbox", 1); RegisterHam(Ham_Killed, "weaponbox", "Ham_FEKilled_weaponbox", 0); RegisterHam(Ham_Think, "weaponbox", "Ham_FEThink_weaponbox", 0); RegisterHam(Ham_Touch, "weaponbox", "Ham_FETouch_weaponbox", 0); RegisterHam(Ham_Spawn, "player", "Ham_FOSpawn_player", 1); RegisterHam(Ham_Killed, "player", "Ham_FEKilled_player", 0); register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0"); weaponbox_encoded = engfunc(EngFunc_AllocString, "weaponbox"); get_user_msgid_AmmoPickup = get_user_msgid("AmmoPickup"); ammo_entery_datas = ArrayCreate(64); } public Event_NewRound() { new view[32]; if( ammo_entery_num ) { new buffer[64], s_ent[5], ent; for( new item; item < ammo_entery_num; item++ ) { ArrayGetString(ammo_entery_datas, item, buffer, 63); replace_all(buffer, 63, "_", " "); parse(buffer, s_ent, 4); ent = str_to_num(s_ent); if( pev_valid(ent) ) { pev(ent, pev_classname, view, 31); if( equal(view, "weaponbox") ) { pev(ent, pev_model, view, 31); if( equal(view, ammo_model) ) { set_pev(ent, pev_solid, SOLID_NOT); dllfunc(DLLFunc_Think, ent); engfunc(EngFunc_RemoveEntity, ent); } } } } ArrayClear(ammo_entery_datas); ammo_entery_num = 0; } new ent = -1; while( (ent=engfunc(EngFunc_FindEntityByString, ent, "classname", "weaponbox"))>0 ) { pev(ent, pev_model, view, 31); if( equal(view, ammo_model) ) { set_pev(ent, pev_solid, SOLID_NOT); dllfunc(DLLFunc_Think, ent); engfunc(EngFunc_RemoveEntity, ent); } } } public plugin_precache() { precache_model(ammo_model); precache_sound(ammo_sound); } public Ham_FEThink_weaponbox(weaponbox_ent) { if( !ammo_entery_num ) return HAM_IGNORED; new buffer[64]; pev(weaponbox_ent, pev_model, buffer, 31); if( !equal(buffer, ammo_model) ) return HAM_IGNORED; new s_ent[5]; for( new item; item < ammo_entery_num; item++ ) { ArrayGetString(ammo_entery_datas, item, buffer, 63); replace_all(buffer, 63, "_", " "); parse(buffer, s_ent, 4); if( str_to_num(s_ent)==weaponbox_ent ) { ArrayDeleteItem2(ammo_entery_datas, item); ammo_entery_num--; return HAM_IGNORED; } } return HAM_IGNORED; } public Ham_FEKilled_weaponbox(weaponbox_ent, idattacker, shouldgib) { if( !ammo_entery_num ) return HAM_IGNORED; new buffer[64]; pev(weaponbox_ent, pev_model, buffer, 31); if( !equal(buffer, ammo_model) ) return HAM_IGNORED; new s_ent[5]; for( new item; item < ammo_entery_num; item++ ) { ArrayGetString(ammo_entery_datas, item, buffer, 63); replace_all(buffer, 63, "_", " "); parse(buffer, s_ent, 4); if( str_to_num(s_ent)==weaponbox_ent ) { ArrayDeleteItem2(ammo_entery_datas, item); ammo_entery_num--; return HAM_IGNORED; } } return HAM_IGNORED; } public Ham_FOSpawn_weaponbox(weaponbox_ent) weaponbox_spawned(weaponbox_ent, pev(weaponbox_ent, pev_owner)); public weaponbox_spawned(weaponbox_ent, owner) { static classname[32]; if( owner ) pev(owner, pev_classname, classname, 31); else copy(classname, 31, ""); if( equal(classname, "player") ) { static Float:velocity[3]; pev(owner, pev_velocity, velocity); if( alive[owner] ) { static Float:aim_speed[3]; velocity_by_aim(owner, 200, aim_speed); velocity[0] += aim_speed[0]; velocity[1] += aim_speed[1]; velocity[2] += aim_speed[2]; } else set_task(0.01, "modify_death_speed", weaponbox_ent); // it makes a delay, althow realy fast one, but dose. set_pev(weaponbox_ent, pev_velocity, velocity); } } public modify_death_speed(weaponbox_ent) { if( pev_valid(weaponbox_ent) ) { static classname[32]; pev(weaponbox_ent, pev_classname, classname, 31); if( equal(classname, "weaponbox") ) { pev(weaponbox_ent, pev_model, classname, 31); if( equal(classname, ammo_model) ) set_pev(weaponbox_ent, pev_nextthink, 0.0); static owner; owner = pev(weaponbox_ent, pev_owner); if( pev_valid(owner) ) { pev(owner, pev_classname, classname, 31); if( equal(classname, "player") ) { if( !alive[owner] ) { static Float:velocity[3]; pev(owner, pev_velocity, velocity); set_pev(weaponbox_ent, pev_velocity, velocity); } } } } } } public Ham_FOSpawn_player(id) alive[id] = true; public Ham_FEKilled_player(victim, idattacker, shouldgib) { client_dies(victim); return HAM_IGNORED; } public client_disconnect(id) client_dies(id); public client_dies(id) { if( !alive[id] ) return; alive[id] = false; new weapons[32], num; get_user_weapons(id, weapons, num); if( !num ) return; new weapon_name[32]; for( new i; i < num; i++ ) { switch( weapons[i] ) { case CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_KNIFE: continue; default: { get_weaponname(weapons[i], weapon_name, 31); engclient_cmd(id, "drop", weapon_name); } } } new buffer[64], len, pbammo, total_ammo; for( new i; i < 10; i++ ) { pbammo = clamp(cs_get_user_bpammo(id, cs_ammo_weapons[i]), 0, 254); len += format(buffer[len], 63-len, "%s%d", (i==0)?"":"_", pbammo); total_ammo += pbammo; } if( total_ammo>0 ) { new weaponbox_ent = engfunc(EngFunc_CreateNamedEntity, weaponbox_encoded); if( weaponbox_ent ) { new Float:origin[3]; pev(id, pev_origin, origin); set_pev(weaponbox_ent, pev_owner, id); dllfunc(DLLFunc_Spawn, weaponbox_ent); engfunc(EngFunc_SetModel, weaponbox_ent, ammo_model); engfunc(EngFunc_SetOrigin, weaponbox_ent, origin); weaponbox_spawned(weaponbox_ent, id) format(buffer, 63, "%d_%s", weaponbox_ent, buffer); ArrayPushString(ammo_entery_datas, buffer); ammo_entery_num++; } } } public Ham_FETouch_weaponbox(weaponbox_ent, id) { if( !ammo_entery_num ) return HAM_IGNORED; static classname[32]; pev(weaponbox_ent, pev_model, classname, 31); if( !equal(classname, ammo_model) ) return HAM_IGNORED; pev(id, pev_classname, classname, 31); if( equal(classname, "player") ) { static i, buffer[64], ent_id[5], s_ammo_values[10][4], ammo_values[10], item; for( item=0; item < ammo_entery_num; item++ ) { ArrayGetString(ammo_entery_datas, item, buffer, 63); replace_all(buffer, 63, "_", " "); parse(buffer, ent_id, 4, s_ammo_values[0], 3, s_ammo_values[1], 3, s_ammo_values[2], 3, s_ammo_values[3], 3, s_ammo_values[4], 3, s_ammo_values[5], 3, s_ammo_values[6], 3, s_ammo_values[7], 3, s_ammo_values[8], 3, s_ammo_values[9], 3); if( weaponbox_ent==str_to_num(ent_id) ) break; else copy(buffer, 63, ""); } if( !buffer[0] ) return HAM_IGNORED; for( i=0; i < 10; i++ ) ammo_values[i] = str_to_num(s_ammo_values[i]); if( !(pev(weaponbox_ent, pev_flags)&FL_ONGROUND) ) return HAM_SUPERCEDE; static user_ammo, total_new_user_ammo, new_user_ammo, total_ammo, ammo_values_changed; total_ammo = 0; ammo_values_changed = false; for( i=0; i < 10; i++ ) { if( ammo_values[i] ) { user_ammo = clamp(cs_get_user_bpammo(id, cs_ammo_weapons[i]), 0, 254); if( user_ammocs_ammo_max[i] ) ammo_values[i] = total_new_user_ammo-cs_ammo_max[i]; else ammo_values[i] = 0; message_begin(MSG_ONE_UNRELIABLE, get_user_msgid_AmmoPickup, {0, 0, 0}, id); write_byte(cs_ammo_id[i]); write_byte((new_user_ammo-user_ammo)); message_end(); cs_set_user_bpammo(id, cs_ammo_weapons[i], new_user_ammo); emit_sound(id, CHAN_ITEM, ammo_sound, 1.0, ATTN_NORM, 0, PITCH_NORM); if( !ammo_values_changed ) ammo_values_changed = true; } total_ammo += ammo_values[i]; } } if( !ammo_values_changed ) return HAM_SUPERCEDE; if( total_ammo ) { static len; len = format(buffer, 63, "%d", weaponbox_ent); for( i=0; i < 10; i++ ) len += format(buffer[len], 63-len, "_%d", ammo_values[i]); ArrayDeleteItem2(ammo_entery_datas, item); ArrayPushString(ammo_entery_datas, buffer); } else { set_pev(weaponbox_ent, pev_solid, SOLID_NOT); dllfunc(DLLFunc_Think, weaponbox_ent); engfunc(EngFunc_RemoveEntity, weaponbox_ent); ArrayDeleteItem2(ammo_entery_datas, item); ammo_entery_num--; } return HAM_SUPERCEDE; } return HAM_IGNORED; } ArrayDeleteItem2(Array:arrayid, itemid) // Fix standart native and I will use it. Untill then - I'll use my way... { if( ammo_entery_num==1 ) ArrayClear(arrayid); else { static bool:temp_exists, Array:temp_array; if( !temp_exists ) { temp_array = ArrayCreate(64); temp_exists = true; } else ArrayClear(temp_array); new data[64], item; for( item = 0; item < ammo_entery_num; item++ ) { if( item!=itemid ) { ArrayGetString(arrayid, item, data, 63); ArrayPushString(temp_array, data); } } ArrayClear(arrayid); for( item = 0; item < (ammo_entery_num-1); item++ ) { ArrayGetString(temp_array, item, data, 63); ArrayPushString(arrayid, data); } } return 1; }