AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check if entity exist on coordinates (https://forums.alliedmods.net/showthread.php?t=222178)

avril-lavigne 07-30-2013 18:27

check if entity exist on coordinates
 
Lets say I have coordinates written to the file 123.cfg like this

Code:

-118 -1624 -475
-157 -1624 -475
-192 -1623 -475
-235 -1622 -475
-278 -1621 -475
-324 -1620 -475
-379 -1619 -475

I can use find entity by class, but I dont know how to check it on each coords

(cheap suits code)
PHP Code:

Load_Origins(CurMap[])
{
    new 
MapFile[64]
    
format(MapFile63"%s/%s.cfg"g_ItemOriginDirCurMap)
    if(!
file_exists(MapFile)) {
        return 
PLUGIN_CONTINUE
    
}

    
g_MapItemNum 0
    
for(new 1<= MAX_MAPITEMS; ++i
    {
        
g_MapItemOrgins[i][0] = 0
        g_MapItemOrgins
[i][1] = 0
        g_MapItemOrgins
[i][2] = 0
    
}
    
    new 
Text[64], Line 0Len 0
    
while(read_file(MapFileLine++, Text63Len))
    {
        if((
Text[0]==';') || !Len) {
             continue
        }
        
        if(
g_MapItemNum >= MAX_MAPITEMS
        {
            
log_amx("Max map items reached, please increase MAX_MAPITEMS")
            break
        }
        
        new 
iOrigin[3][16]
        
parse(TextiOrigin[0], 15iOrigin[1], 15iOrigin[2], 15)
        
        
g_MapItemNum++
        
g_MapItemOrgins[g_MapItemNum][0] = str_to_num(iOrigin[0])
        
g_MapItemOrgins[g_MapItemNum][1] = str_to_num(iOrigin[1])
        
g_MapItemOrgins[g_MapItemNum][2] = str_to_num(iOrigin[2])
    }
    return 
PLUGIN_CONTINUE
}

public 
Spawn_Items()
{
    for(new 
1<= MAX_MAPITEMS; ++i)
    {
        if((
g_MapItemOrgins[i][0] == 0) && (g_MapItemOrgins[i][1] == 0) && g_MapItemOrgins[i][2] == 0) { 
                continue
        }    
                 
// here we must check if entity is already there and dont let it spawn twice           
        
Create_Items(g_MapItemOrgins[i])[/B]
    }


Your suggestion, how to block it from spawning twice at the same place? but spawn in others if not exist

Shooting King 07-31-2013 02:07

Re: check if entity exist on coordinates
 
Create g_MapItemOrgins[X][3].

In
g_MapItemOrgins[X][3] keep 1 if spawned else 0.
While spawning Items check if
g_MapItemOrgins[X][3] is 0/1.
If 0 spawn.
ELSE

find entity by class()
and

Quote:

Originally Posted by engine_stocks.inc
/* Get origin of a brush entity */
stock get_brush_entity_origin(ent, Float:orig[3])
{
new Float:Min[3], Float:Max[3];

entity_get_vector(ent, EV_VEC_origin, orig);
entity_get_vector(ent, EV_VEC_mins, Min);
entity_get_vector(ent, EV_VEC_maxs, Max);

orig[0] += (Min[0] + Max[0]) * 0.5;
orig[1] += (Min[1] + Max[1]) * 0.5;
orig[2] += (Min[2] + Max[2]) * 0.5;

return 1;
}


avril-lavigne 07-31-2013 15:57

Re: check if entity exist on coordinates
 
I did debug when it creates entity like so , not sure if its correct code

PHP Code:

Create_Items(Origin[3])
{
    new 
Float:flOrigin[3]
    
IVecFVec(OriginflOrigin)
    new 
ent find_ent_by_class(-1,"dm_ammo_grenade");
        if(
get_brush_entity_origin(ent,flOrigin) == 0) {
        
client_print(0,3,"entity not found")
        
        }
        if(
get_brush_entity_origin(ent,flOrigin) == 1) {
        
client_print(0,3,"entity found")
        
        }



So I need to check if any entity exist on these Origin[3] before create it here

this code catch spawn of other entities too.... so I see "entity found" even this one is not spawned yet.

Shooting King 08-02-2013 09:55

Re: check if entity exist on coordinates
 
You are checking if entity exists in world or not. You have to check if the both origins, Origin and flOrigin are equal or not. Call this function before Create_Items().
PHP Code:

CheckEntities()
{
    new 
temp_ent engfunc(EngFunc_FindEntityByString0"classname""dm_ammo_grenade");

    while( 
temp_ent 0
    {
        
get_brush_entity_origin(temp_ent,flOrigin);
        for( 
0sizeof(g_MapItemOrgins); i++ )
        {
            if( (
g_MapItemOrgins[i][0] == flOrigin[0]) && (g_MapItemOrgins[i][1] == flOrigin[1]) && (g_MapItemOrgins[i][2] == flOrigin[2])) 
            {
                
g_MapItemOrgins[i][3] = 1;
            }
        }
        
temp_ent engfunc(EngFunc_FindEntityByStringtemp_ent"classname""dm_ammo_grenade");
    }


Quote:

Originally Posted by Shooting King (Post 2002605)
While spawning Items check if g_MapItemOrgins[X][3] is 0/1.
If 0 spawn.


ConnorMcLeod 08-03-2013 12:15

Re: check if entity exist on coordinates
 
Why would items be spawned twice if you spawn them only once at map start ?

Also, use str_to_float instead of str_to_num


All times are GMT -4. The time now is 15:58.

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