| MiniBrackeur |
06-09-2012 07:03 |
Re: how to shorten and debug this code?
I opened this topic because I changed the code, I want that the player can't pick up the weapon if he is limited, but I can't do it :/
Somebody can help me again? x)
PHP Code:
#include <amxmodx> #include <cstrike> #include <fun> #include <hamsandwich> #include <fakemeta>
new disable_plugin new disable_help
new pl_limitation[33]
new const gWeaponLimits[] = { 0, 0, (1<<CSW_M249), (1<<CSW_SCOUT)|(1<<CSW_AWP)|(1<<CSW_SG550)|(1<<CSW_G3SG1), (1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_M4A1)|(1<<CSW_AK47)|(1<<CSW_AUG)|(1<<CSW_SG552), (1<<CSW_MAC10)|(1<<CSW_TMP)|(1<<CSW_MP5NAVY)|(1<<CSW_UMP45)|(1<<CSW_P90), (1<<CSW_M3)|(1<<CSW_XM1014), (1<<CSW_P228)|(1<<CSW_DEAGLE)|(1<<CSW_FIVESEVEN)|(1<<CSW_ELITE), (1<<CSW_USP)|(1<<CSW_GLOCK18) }
public plugin_init() { register_plugin("[CSD] Limitation","1.0","Daminou") RegisterHam(Ham_Spawn, "player", "client_spawn", 1) RegisterHam(Ham_Touch, "armoury_entity", "anti_weapon_pickup1", 0) RegisterHam(Ham_Touch, "weaponbox", "anti_weapon_pickup2", 0) disable_plugin = register_cvar("csd_lim_p_disable", "0") disable_help = register_cvar("csd_lim_h_disable", "0") register_dictionary("csd_plugins.txt") }
public check_ratio(id) { new frags = get_user_frags(id) new deaths = get_user_deaths(id) new ratio = (frags - deaths) if(ratio > 14) { pl_limitation[id] = 8 } else if(ratio > 12) { pl_limitation[id] = 7 } else if(ratio > 10) { pl_limitation[id] = 6 } else if(ratio > 8) { pl_limitation[id] = 5 } else if(ratio > 6) { pl_limitation[id] = 4 } else if(ratio > 4) { pl_limitation[id] = 3 } else if(ratio > 3) { pl_limitation[id] = 2 } else if(ratio > -3) { pl_limitation[id] = 1 } else if(ratio < -4) { pl_limitation[id] = 0 } new niveau_limitation = pl_limitation[id] client_print(id, print_chat, "test 0: %s", niveau_limitation) if(2 <= niveau_limitation <= 8) { check_armes(id) } else if(niveau_limitation == 0) { if(!get_pcvar_num(disable_help)) { give_stuff(id) client_print(id, print_chat, "test 1") } } }
public client_spawn(id) { if(!get_pcvar_num(disable_plugin)) { set_task(0.5, "check_ratio", id) } else { pl_limitation[id] = 1 } }
public check_armes(id) { if(is_user_alive(id)) { new niveau_limitation = pl_limitation[id] new Weapon = get_user_weapon(id) for (new i = 1; i <= niveau_limitation && i < sizeof(gWeaponLimits); i++) { if(gWeaponLimits[i] & (1 << Weapon)) { new WeaponName[32] get_weaponname(Weapon, WeaponName, charsmax(WeaponName)) engclient_cmd(id, "drop", WeaponName) client_print(id, print_chat, "test 2") } } } }
public anti_weapon_pickup1(ent, id) { if(is_user_alive(id)) { new niveau_limitation = pl_limitation[id] new Weapon = cs_get_armoury_type(ent) for (new i = 1; i <= niveau_limitation && i < sizeof(gWeaponLimits); i++) { if(gWeaponLimits[i] & (1 << Weapon)) { client_print(id, print_chat, "test 3") return HAM_SUPERCEDE } } } return HAM_IGNORED }
public anti_weapon_pickup2(id, ent) { if(is_user_alive(id)) { new niveau_limitation = pl_limitation[id] new Weapon = cs_get_weapon_id(ent) for (new i = 1; i <= niveau_limitation && i < sizeof(gWeaponLimits); i++) { if(Weapon & gWeaponLimits[i]) { client_print(id, print_chat, "test 4") return HAM_SUPERCEDE } } } return HAM_IGNORED }
public give_stuff(id) { switch(cs_get_user_team(id)) { case CS_TEAM_CT: { if(!cs_get_user_defuse(id)) { cs_set_user_defuse(id, 1) } if(!user_has_weapon(id, CSW_M4A1)) { give_item(id, "weapon_m4a1") cs_set_user_bpammo(id, CSW_M4A1, 90) } } case CS_TEAM_T: { if(!user_has_weapon(id, CSW_AK47)) { give_item(id, "weapon_ak47") cs_set_user_bpammo(id, CSW_AK47, 90) } } } if(!user_has_weapon(id, CSW_HEGRENADE)) { give_item(id, "weapon_hegrenade") } if(!user_has_weapon(id, CSW_FLASHBANG)) { give_item(id, "weapon_flashbang") give_item(id, "weapon_flashbang") } if(!user_has_weapon(id, CSW_SMOKEGRENADE)) { give_item(id, "weapon_smokegrenade") } if(!user_has_weapon(id, CSW_DEAGLE)) { give_item(id, "weapon_deagle") cs_set_user_bpammo(id, CSW_DEAGLE, 35) } cs_set_user_armor(id, 100, CS_ARMOR_VESTHELM) }
PS: I changed the title of the topic.
|