Raised This Month: $ Target: $400
 0% 

Optimizing - Remove dropped weapons


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
atomen
Veteran Member
Join Date: Oct 2006
Location: Stockholm, Sweden
Old 06-26-2009 , 21:41   Optimizing - Remove dropped weapons
Reply With Quote #1

Hello!

Well it's pretty simple, the code I've made for deleting dropped weapons
after a certain period works somewhat good but not enough. If you take
a look at the the script you quickly notice how inefficient it is. Therefore
I'm asking you for help!
PHP Code:
#include <amxmodx>
#include <fakemeta>

#define gPLUGIN        "Weapon Controller"
#define gVERSION    "X"
#define gAUTHOR        "."

new const g_weapon_contain[] = "models/w_";

new 
g_pcvar_remove;
new 
g_drop_id;

public 
plugin_init()
{
    
register_plugin(gPLUGINgVERSIONgAUTHOR);
    
register_clcmd("drop""dropped_weapon");

    
register_forward(FM_SetModel"forward_set_model");

    
g_pcvar_remove register_cvar("amx_weapon_removetime""10");
}

public 
forward_set_model(entmodel[])
{
    if (!
pev_valid(ent) || containi(modelg_weapon_contain) == -|| equali(model"models/w_weaponbox.mdl"))
    {
        return 
FMRES_IGNORED;
    }

    static 
Float:info[4], Float:origin[3];

    if(
is_user_connected(g_drop_id))
    {
        
info[3] = ent;
        
g_drop_id 0;
    }

    else
    {
        return 
FMRES_IGNORED;
    }

    if(
engfunc(EngFunc_EntIsOnFloorent))
    {
        
pev(entpev_originorigin);

        for(new 
03i++)
        {
            
info[i] = origin[i];
        }

        
set_task(get_pcvar_float(g_pcvar_remove), "check_weapon"__:info4);
    }

    else
    {
        
set_task(0.1"check_weapon_floor"__:info4);
    }

    return 
FMRES_IGNORED;
}

public 
check_weapon_floor(info[])
{
    static 
origin[3], model[sizeof(g_weapon_contain) + 1];
    new 
ent info[3];

    
pev(entpev_modelmodelsizeof(g_weapon_contain));

    if(!
pev_valid(ent) || containi(modelg_weapon_contain) == -1)
        return;

    if(
engfunc(EngFunc_EntIsOnFloorent))
    {
        
pev(entpev_originorigin);

        for(new 
03i++)
        {
            
info[i] = origin[i];
        }

        
set_task(get_pcvar_float(g_pcvar_remove) - info[4], "check_weapon"__:info4);
    }

    else
    {
        
set_task(0.1"check_weapon_floor"__:info4);
    }
}

public 
check_weapon(info[])
{
    new 
ent info[3];

    if(!
pev_valid(ent))
        return;

    new 
Float:_origin[3];
    
pev(entpev_origin_origin);

    for(new 
03i++)
    {
        new 
origin    _:_origin[i];
        new 
_info    _:info[i];

        
log_amx("%d"1);

        if(
origin != _info)
        {
            return;
        }
    }

    
set_pev(entpev_effectspev(entpev_effects) & EF_NODRAW);
    
engfunc(EngFunc_RemoveEntityent);
}

public 
dropped_weapon(id)
{
    if(
is_user_connected(id) & is_user_alive(id))
    {
        
g_drop_id id;
    }

Some description: The plugin is supposed to delete a dropped weapon after
a certain time has passed (defined by cvar). To check that the weapon hasn't
been picked up under the time passed (time defined by cvar) the code checks
if the origin of the entity has changed. For some reason the origin is only correct
50% of the times...
__________________
atomen is offline
Send a message via MSN to atomen
 



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 15:27.


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