AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Spawn an Entity at an Origin (Float) via Fakemeta? (https://forums.alliedmods.net/showthread.php?t=46008)

Silencer123 10-16-2006 14:35

Spawn an Entity at an Origin (Float) via Fakemeta?
 
How to:


1. Spawn an Entity at an Origin (Float) via Fakemeta?

2. Remove an Entity via Fakemeta?

commonbullet 10-16-2006 16:12

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
Code:
// 1: create_entity(const classname[], Float:origin[3] = {0.0, 0.0, 0.0}) {     new ent     ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, classname))     if(ent) {         set_pev(ent, pev_origin, origin)            dllfunc(DLLFunc_Spawn, ent)     }     return ent } // 2: remove_entity(ent) {     if(pev_valid(ent))         engfunc(EngFunc_RemoveEntity, ent) }

XxAvalanchexX 10-16-2006 16:58

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
Use EngFunc_SetOrigin, not pev_origin.

commonbullet 10-16-2006 20:06

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
Quote:

Originally Posted by XxAvalanchexX (Post 391860)
Use EngFunc_SetOrigin, not pev_origin.

what's the difference? :stupid:

XxAvalanchexX 10-16-2006 21:18

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
Quote:

Originally Posted by commonbullet (Post 391928)
what's the difference? :stupid:

The comment for entity_set_origin (engine module's equivalent to EngFunc_SetOrigin) is:
Code:
/* Proper origin setting, keeps updated with Half-Life engine. */
One is proper, one is not. That's the difference. ;)

commonbullet 10-16-2006 21:51

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
I only asked because I've been using pev_origin to change an entity origin and I've never faced a bug; but I'm sure that this function must be safer (and proper).
Thanks.

P34nut 10-17-2006 03:39

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
if you use set_pev to set an origin of a player your server will crash...

Silencer123 10-17-2006 05:56

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
@ commonbullet: I was going to use fakemeta only
= Unknown symbol "remove_entity"
&= Unknown symbol "create_entity"
...

commonbullet 10-17-2006 10:30

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
I've been very stupid to use the same names as engine functions; but they’re 100% fakemeta and they don’t work exactly like the engine functions (i.e. create_entity in engine doesn’t 'spawn' the entity, you would have DispatchSpawn after creating; I was trying to give you examples.)

And that’s the proper way to set origin.
Code:
create_entity_at(const classname[], Float:origin[3] = {0.0, 0.0, 0.0}) {     new ent     ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, classname))     if(ent) {         engfunc(EngFunc_SetOrigin, ent, origin)         dllfunc(DLLFunc_Spawn, ent)     }     return ent }

Silencer123 10-17-2006 14:36

Re: Spawn an Entity at an Origin (Float) via Fakemeta?
 
Ok, I have made this Plugin to replace an Entity with another, but actually nothing happens:
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #define VERSION "1.0" new content_what[64][100] new content_with[64][100] public plugin_init() {     register_plugin("Entity Replacer",VERSION,"Silencer")     {         new path[128]         get_configsdir(path,127)         add(path,127,"/ent_replace.txt")         switch(file_exists(path))         {             case 1:             {                 new howlong                 new result[128]                 for(new i=0;i<100;i++)                 {                     read_file(path,i,result,127,howlong)                     parse(result,content_what,63,content_with,63)                 }             }             case 0:             {                 set_fail_state("NO FILE")             }         }     }     register_forward(FM_Spawn,"ER_Spawn") } public ER_Spawn(entid) {     new classname[64]     pev(entid,pev_classname,classname,63)     new curpos     while(curpos<100&&!equali(content_what[curpos],classname))     {         curpos++     }     if(curpos<100)     {         engfunc(EngFunc_RemoveEntity,entid)         if(!equali(content_with[curpos],"NOTHING"))         {             new Float:origin[3]             pev(entid,pev_origin,origin)             new alt_ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,content_with[curpos]))             engfunc(EngFunc_SetOrigin,alt_ent,origin)             dllfunc(DLLFunc_Spawn,alt_ent)             return alt_ent         }     }     return PLUGIN_HANDLED }
"addons\amxmodx\configs\ent_replace.txt":
Code:

weapon_shotgun nothing
ammo_buckshot nothing
weapon_357 weapon_gauss
ammo_357 ammo_gaussclip

What's wrong?


All times are GMT -4. The time now is 04:53.

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