AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   recreating an entity? (https://forums.alliedmods.net/showthread.php?t=131867)

HLM 07-09-2010 19:22

recreating an entity?
 
I need an easy way to 1) get the 'origin', 'team_no' and 'angles' keys from an entity, save them temporarily, delete the entity, then rebuild it with specific keys?

I have made an attempt of just editing the entity as-is but all of the keys are not applied, so it wont always work as intended :(

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>

#define PLUGIN "Spam Packs"
#define VERSION "1.0"
#define AUTHOR "Master"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)    
    
// Add your code here...
}

public 
plugin_precache()
{
    
register_forward(FM_KeyValue"hook_KeyValue"1)
}

public 
hook_KeyValue(entIdkvdid)
{
    if(!
pev_valid(entId))
        return 
FMRES_HANDLED;
    
    new 
classname[64];
    
get_kvd(kvdidKV_ClassNameclassname63)    
    if(
equali(classname"info_tfgoal"))
    {
        new 
keyname[128]   
        new 
keydata[128]
        
get_kvd(kvdidKV_KeyNamekeyname127)
        
get_kvd(kvdidKV_Valuekeydata127)
        if(
containi(keyname"no_grenades") != -1)
        {
            
set_keyvalue(entId"no_grenades_1""4")
            
set_keyvalue(entId"no_grenades_2""4")
            
set_keyvalue(entId"health""100")
            
set_keyvalue(entId"armorvalue""300")
            
set_keyvalue(entId"message""Restocking Explosives.")
            
set_keyvalue(entId"noise""items/r_item1.wav")
            
set_keyvalue(entId"ammo_nails""200")
            
set_keyvalue(entId"ammo_rockets""100")
            
set_keyvalue(entId"ammo_cells""200")
            
set_keyvalue(entId"ammo_shells""200")
            
set_keyvalue(entId"wait""1")
            
set_keyvalue(entId"g_e""1")
            
set_keyvalue(entId"g_a""1")
        }
    }
    return 
FMRES_OVERRIDE;
}

stock set_keyvalue(entkey[], value[])
{
    new 
classname[32];
    
    
pev(entpev_classnameclassname31);
    
set_kvd(0KV_ClassNameclassname);
    
set_kvd(0KV_KeyNamekey);
    
set_kvd(0KV_Valuevalue);
    
set_kvd(0KV_fHandled0);
    
    
dllfunc(DLLFunc_KeyValueent0);


this is the code it used, some maps all the keys are set, other times, only the top X are set, can someone tell me how id store those keys and "recreate" the entity?

heres an example of one of the entities im working with:
Code:

{
"origin" "-1960 -2864 72"
"armorvalue" "300"
"health" "100"
"message" "Restocking Explosives."
"no_grenades_2" "4"
"ammo_medikit" "20"
"noise" "items/r_item1.wav"
"team_no" "2"
"no_grenades_1" "4"
"ammo_nails" "200"
"ammo_rockets" "100"
"ammo_cells" "200"
"ammo_shells" "200"
"wait" "1"
"mdl" "models/en/grenpack.mdl"
"g_e" "1"
"g_a" "1"
"classname" "info_tfgoal"
}


Backstabnoob 07-10-2010 03:32

Re: recreating an entity?
 
You should think about which module you'd use. Using both fakemeta and engine is bad.

like this:

PHP Code:



#include <engine>

new g_angles[3]
new 
g_origin[3]
new 
g_team_no

public when_to_delete_the_entity(entid)
{
    
entity_get_vector(entidEV_VEC_anglesg_angles)
    
entity_get_vector(entidEV_VEC_origing_origin)
    
g_team_no entity_get_int(entidEV_INT_team)
    
    
remove_entity(entid)
}


public 
sometime_spawn_entity()
{
    new 
ent create_entity("info_tfgoal")
    
    
// set the keys with entity_set_x



Hunter-Digital 07-10-2010 07:21

Re: recreating an entity?
 
No, it's not BAD to use both modules if you use the most efficient stuff from them.

And "entity_set_*" sets predefined internal values for entities, he wants to use keyvalues of the entities wich can have any key and any value.

To set entity keyvalues with engine you can use:
DispatchKeyValue(ent, "key", "value")
You also should call DispatchSpawn(ent) after all keys are set.

And I think you should use it in plugin_precache() to create an fake "already in map" entity... I used that for info_map_parameters.

You could hook entity spawn in precache and alter it's keyvalues... or remove it and remember that then, afterwards create the desired entity... you should use server_print messages to debug your actions.

Backstabnoob 07-10-2010 07:38

Re: recreating an entity?
 
Quote:

No, it's not BAD to use both modules if you use the most efficient stuff from them.
In his example it is.


All times are GMT -4. The time now is 07:11.

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