Re: Return csw_ weapon
Oh shit, when I was posting that my internet crashed and how did it post? Sorry guys. I fixed it using cs_get_weapon_id().
To be more specific, I was trying to check if I have a primary/secondary weapon depending of which weapon I'm trying to pickup from the ground and drop it for pickup the dropped weapon.
I mean:
Prostotem@'s code:
PHP Code:
#include <amxmodx> #include <cstrike> #include <engine> #include <fakemeta> #include <hamsandwich>
const XO_CWEAPONBOX = 4 new const m_rgpPlayerItems_CWeaponBox[6] = {34,35,...}
const PRIMARY_WEAPONS = (1 << CSW_AK47)|(1 << CSW_AUG)|(1 << CSW_GALIL)|(1 << CSW_SCOUT) |(1 << CSW_SG550)|(1 << CSW_SG552)|(1 << CSW_FAMAS)|(1 << CSW_AWP)|(1 << CSW_M4A1)|(1 << CSW_G3SG1)|(1 << CSW_M249)|(1 << CSW_MP5NAVY)|(1 << CSW_MAC10)|(1 << CSW_P90)|(1 << CSW_M3)|(1 << CSW_XM1014)|(1 << CSW_UMP45)|(1 << CSW_TMP) const SECONDARY_WEAPONS = (1 << CSW_DEAGLE)|(1 << CSW_USP)|(1 << CSW_GLOCK18)|(1 << CSW_ELITE)|(1 << CSW_FIVESEVEN)|(1 << CSW_P228)
new g_hSync
public plugin_init() { register_plugin("Thor Weapon Pickup", "1.0", "EFFx/ProSToTeM@") register_forward(FM_CmdStart, "CmdStart", ._post=true) g_hSync = CreateHudSyncObj() }
public CmdStart(player, userCmdHandle, randomSeed) { if(!is_user_alive(player)) return
if(get_uc(userCmdHandle, UC_Buttons) & IN_USE && !(entity_get_int(player, EV_INT_oldbuttons) & IN_USE)) { OnUsePress(player) } }
OnUsePress(player) { enum _:WboxInfo { WboxInfo_Ent, WboxInfo_Owner } new Array:wboxInfos = ArrayCreate(WboxInfo) static wboxInfo[WboxInfo] for(new iWbox = 0; (iWbox = find_ent_by_class(iWbox, "weaponbox")) != 0;) { wboxInfo[WboxInfo_Ent] = iWbox wboxInfo[WboxInfo_Owner] = entity_get_edict(iWbox, EV_ENT_owner) ArrayPushArray(wboxInfos, wboxInfo) entity_set_int(iWbox, EV_INT_solid, SOLID_BBOX) entity_set_edict(iWbox, EV_ENT_owner, 0) RelinkEntity(iWbox) entity_set_vector(iWbox, EV_VEC_size, Float:{1.0, 0.0, 0.0}) } const iMaxDistance = 76 static iHitEnt, iHitGroup get_user_aiming(player, iHitEnt, iHitGroup, iMaxDistance) new iHitWbox = 0, iWeaponID = 0 if(iHitEnt != 0) { iWeaponID = GetWeaponBoxWeaponType(iHitEnt) static szClassName[MAX_PLAYERS] entity_get_string(iHitEnt, EV_SZ_classname, szClassName, charsmax(szClassName)) if(equal(szClassName, "weaponbox")) { iHitWbox = iHitEnt static szWeapon[MAX_PLAYERS], szOwnerName[MAX_PLAYERS], iRGB[3], szHudFormat[50] get_weaponname(iWeaponID, szWeapon, charsmax(szWeapon)) get_user_name(wboxInfo[WboxInfo_Owner], szOwnerName, charsmax(szOwnerName)) replace(szWeapon, charsmax(szWeapon), "weapon_", "") strtoupper(szWeapon) if(is_user_connected(wboxInfo[WboxInfo_Owner])) { switch(get_user_team(wboxInfo[WboxInfo_Owner])) { case 1: { iRGB = {220, 30, 0} } case 2: { iRGB = {0, 100, 200} } default: { iRGB = {255, 255, 255} } } } else { iRGB = {255, 255, 255} } if(player == wboxInfo[WboxInfo_Owner]) { formatex(szHudFormat, charsmax(szHudFormat), "%s", szWeapon) } else { formatex(szHudFormat, charsmax(szHudFormat), "%s's %s", szOwnerName, szWeapon) } set_hudmessage(iRGB[0], iRGB[1], iRGB[2], 0.70, 0.80, 0, 1.0, 4.0) ShowSyncHudMsg(player, g_hSync, "You got %s", szHudFormat) } } new wboxCount = ArraySize(wboxInfos) for(new i = 0; i < wboxCount; i++) { static wboxInfo[WboxInfo] ArrayGetArray(wboxInfos, i, wboxInfo) new iWbox = wboxInfo[WboxInfo_Ent] entity_set_edict(iWbox, EV_ENT_owner, wboxInfo[WboxInfo_Owner]) entity_set_int(iWbox, EV_INT_solid, SOLID_TRIGGER) RelinkEntity(iWbox) } ArrayDestroy(wboxInfos) if(iHitWbox != 0) { new iWeaponByte = (1 << iWeaponID) if(iWeaponByte & (PRIMARY_WEAPONS | SECONDARY_WEAPONS)) { new bool:bIsPrimary = bool:(iWeaponByte & PRIMARY_WEAPONS) if(pev(player, pev_weapons) & (_:bIsPrimary) ? PRIMARY_WEAPONS : SECONDARY_WEAPONS) { dropWeapons(player, (bIsPrimary) ? 1 : 2) } } ExecuteHamB(Ham_Touch, iHitWbox, player) } }
RelinkEntity(ent) { static Float:origin[3] entity_get_vector(ent, EV_VEC_origin, origin) entity_set_origin(ent, origin) }
GetWeaponBoxWeaponType(ent) { new weapon for(new i = 1; i <= 5; i++) { weapon = get_pdata_cbase(ent, m_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX) if(weapon > 0) { return cs_get_weapon_id(weapon) } } return 0 }
dropWeapons(id, iType) { new iWeapons[MAX_PLAYERS], szWeaponName[MAX_PLAYERS], iWeapon, iWeaponsCount, iWeaponByte get_user_weapons(id, iWeapons, iWeaponsCount)
for(new i; i < iWeaponsCount; i++) { if(!iWeaponsCount) continue iWeapon = iWeapons[i] iWeaponByte = (1 << iWeapon) get_weaponname(iWeapon, szWeaponName, charsmax(szWeaponName)) switch(iType) { case 1: { if(iWeaponByte & PRIMARY_WEAPONS) { client_cmd(id, "drop ^"%s^"", szWeaponName) } } case 2: { if(iWeaponByte & SECONDARY_WEAPONS) { client_cmd(id, "drop ^"%s^"", szWeaponName) } } } } }
Here:
PHP Code:
if(iHitWbox != 0) { new iWeaponByte = (1 << iWeaponID) if(iWeaponByte & (PRIMARY_WEAPONS | SECONDARY_WEAPONS)) { new bool:bIsPrimary = bool:(iWeaponByte & PRIMARY_WEAPONS) if(pev(player, pev_weapons) & (_:bIsPrimary) ? PRIMARY_WEAPONS : SECONDARY_WEAPONS) { dropWeapons(player, (bIsPrimary) ? 1 : 2) } } ExecuteHamB(Ham_Touch, iHitWbox, player) }
The problem was here
PHP Code:
new iWeaponByte = (1 << iWeaponID)
I was trying to use CSW_ here but I didn't knew how. I readed cstrike.inc and found out how. But I got another problem. When I'm too close to the dropped weapon and press E, I'd drop my weapon and pick it up normally. But If i'm a little bit far away, I only drop my weapon and don't pick the dropped the weapon up. Why?
|