Raised This Month: $ Target: $400
 0% 

[SNIPPET][ANY-GAME] Remove Weapons on event death


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 06-07-2009 , 08:47   [SNIPPET][ANY-GAME] Remove Weapons on event death
Reply With Quote #1

Hi there this snippet removes all player weapons right before the player dies.

Code:
public OnPluginStart() {
    HookEvent("player_death", Event_Death_Pre, EventHookMode_Pre);
}

public Event_Death_Pre(Handle:event, const String:name[], bool:broadcast) {
    
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    RemoveAllWeapons(client);
}

stock RemoveAllWeapons(client) {
    
    if(!IsClientInGame(client) || !IsPlayerAlive(client) || !Client_IsPlayer(client) || !IsValidEdict(client)){
        return -1;
    }
    
    new String:clientNetClass[64];
    
    if(!GetEntityNetClass(client,clientNetClass,sizeof(clientNetClass))){
        return -1;
    }
    
    new offset_PlayerWeapons = FindSendPropOffs(clientNetClass, "m_hMyWeapons");
    
    if(offset_PlayerWeapons == -1){
        LogError("[SMLIB] Error: Can't get m_hMyWeapons from client '%N' clientindex: %d offset: %d. Wrong playernetclass? PlayerNetClass is: %s",client,offset_PlayerWeapons,clientNetClass);
        return -1;
    }
    
    new entity;
    new removedweapons = 0;
    new bool:success;
    
    for (new offset=0;offset<128;offset+=4){
        
        entity = GetEntDataEnt2(client, offset_PlayerWeapons+offset);
        
        if (IsValidEdict(entity) && IsValidEntity(entity)){
            
            success = RemovePlayerItem(client,entity);
            if(!success){continue;}
            RemoveEdict(entity);
            removedweapons++;
        }
    }
    
    return removedweapons;
}

/**
 * Checks if an entity index is a player and ingame
 *
 * @param entity        An entity index
 * @return                true if the specified entity index is a player ingame, false otherwise
 */
stock bool:Client_IsPlayer(entity) {
    
    if (entity > GetMaxEntities()) {
        entity = EntRefToEntIndex(entity);
    }

    if (entity >= 1 && entity <= MaxClients) {
        if (IsValidEntity(entity) && IsClientInGame(entity)) {
            return true;
        }
    }
    
    return false;
}
if you want to use it in another mod, then search for something similar to CHL2MP_Player...

cya chanz

Last edited by Chanz; 04-15-2010 at 09:07. Reason: update
Chanz is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:42.


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