Raised This Month: $ Target: $400
 0% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
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
Tuna_Can
Junior Member
Join Date: Apr 2010
Old 04-13-2010 , 22:16   Re: [SNIPPET][HL2MP] Remove Weapons on event death
Reply With Quote #2

I get these errors when I try to compile.
(2) error 010: invalid function or declaration
(6) error 017: undefined symbol "off_PlayerWeapons"
(15) error 017: undefined symbol "off_PlayerWeapons"
__________________
Noob learning SourcePawn.
Thanks for the help!!
Tuna_Can is offline
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 04-14-2010 , 12:23   Re: [SNIPPET][ANY-GAME] Remove Weapons on event death
Reply With Quote #3

Hm dunno, but I updated the snipped. Now it should work, please test it.
__________________
[ SourceModPlugins.org ][ My Plugins ]

Thank you for donations: [ Paypal ]

Video Tutorial (German): [ Gameserver & SourceMod Plugins mit HLSW verwalten ]
Chanz is offline
Tuna_Can
Junior Member
Join Date: Apr 2010
Old 04-14-2010 , 19:51   Re: [SNIPPET][ANY-GAME] Remove Weapons on event death
Reply With Quote #4

(13) error 017: undefined symbol "Client_IsPlayer"
(40) error 017: undefined symbol "RemovePlayerItem"
(40) warning 213: tag mismatch

Edit: Oh, I forgot to add includes. I just copy pasted it. I added #include <sourcemod> and #include <sdktools> but now I get this error.
(16) error 017: undefined symbol "Client_IsPlayer"
__________________
Noob learning SourcePawn.
Thanks for the help!!

Last edited by Tuna_Can; 04-14-2010 at 19:55.
Tuna_Can is offline
Chanz
Veteran Member
Join Date: Aug 2008
Location: Germany - Stuttgart
Old 04-15-2010 , 09:08   Re: [SNIPPET][ANY-GAME] Remove Weapons on event death
Reply With Quote #5

here it is:
Code:
/**
 * 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;
}
__________________
[ SourceModPlugins.org ][ My Plugins ]

Thank you for donations: [ Paypal ]

Video Tutorial (German): [ Gameserver & SourceMod Plugins mit HLSW verwalten ]
Chanz is offline
Reply


Thread Tools
Display Modes

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