AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weapon Index from EntID? (https://forums.alliedmods.net/showthread.php?t=164603)

Backstabnoob 08-13-2011 12:34

Weapon Index from EntID?
 
Hello, is there any way around to detect weapon index from the world entity id?

Owyn 08-13-2011 12:54

Re: Weapon Index from EntID?
 
PHP Code:

#define offset_cs_get_weapon_id(%1)            get_pdata_int(%1, m_iId, 4) 


Backstabnoob 08-13-2011 13:01

Re: Weapon Index from EntID?
 
Okay, and any way how to use it in FM_SetModel? It looks like I won't be able to destroy only deagle whenever dropped, because when I compared the model it was w_weaponbox.mdl instead of w_deagle.

Hunter-Digital 08-13-2011 14:15

Re: Weapon Index from EntID?
 
FM_SetModel gets you a entity id, so you can use that define function on it.

And no, it can't have w_weaponbox.mdl model because then it would look like a big green can (drops from HLDM on death), it's got "weaponbox" classname but the model is models/w_<weapon_name>.mdl, so revise your code :P

Backstabnoob 08-13-2011 16:09

Re: Weapon Index from EntID?
 
PHP Code:

public forward_set_model(entidmodel[]) 
{
    
    
    if (!
is_valid_ent(entid))
        return 
FMRES_IGNORED

    
new id entity_get_edict(entidEV_ENT_owner)
    if (!
id || !is_user_connected(id) || is_user_alive(id))
        return 
FMRES_IGNORED

    client_print
(idprint_chat"weapon model: %s"model)
        
    new 
weaponid cs_get_weapon_id(entid)
    
    
client_print(idprint_chat"%d"weaponid)
        
    if (
weaponid == CSW_DEAGLE
    {
        
kill_entity(entid)
        return 
FMRES_IGNORED
    
}

    return 
FMRES_IGNORED


weaponid = 0, weaponmodel w_weaponbox.mdl

try it yourself

Exolent[jNr] 08-13-2011 17:01

Re: Weapon Index from EntID?
 
Because you are hooking the weapon box.
Try finding it's containing weapons.

Code:
stock getWeaponBoxEnts(weaponBox, ents[], entSize) {     if(entSize < 1 || !pev_valid(weaponBox)) {         return 0;     }         new maxEnts = global_get(glb_maxEntities);     new numEnts = 0;         for(new ent = get_maxplayers() + 1; ent <= maxEnts && numEnts < entSize; ent++) {         if(pev_valid(ent) && pev(ent, pev_owner) == weaponBox) {             ents[numEnts++] = ent;         }     }         return numEnts; }

Code:
// dropped weapon forward new weapons[32]; new numWeapons = getWeaponBoxEnts(entid, weapons, sizeof(weapons)); new class[32]; for(new i = 0; i < numWeapons; i++) {     pev(weapons[i], pev_classname, class, charsmax(class));     client_print(id, print_chat, "Dropped %s", class); }


All times are GMT -4. The time now is 03:21.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.