Raised This Month: $ Target: $400
 0% 

check if entity exist on coordinates


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
avril-lavigne
Banned
Join Date: Apr 2009
Old 07-30-2013 , 18:27   check if entity exist on coordinates
Reply With Quote #1

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
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc

Last edited by avril-lavigne; 07-30-2013 at 18:30.
avril-lavigne is offline
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 07-31-2013 , 02:07   Re: check if entity exist on coordinates
Reply With Quote #2

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;
}
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 07-31-2013 at 02:17.
Shooting King is offline
avril-lavigne
Banned
Join Date: Apr 2009
Old 07-31-2013 , 15:57   Re: check if entity exist on coordinates
Reply With Quote #3

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.
__________________
VDS in Europe 1 gb/s unmetered.Any configurations.
I accept Paypal, Moneybookers,etc
avril-lavigne is offline
Old 08-01-2013, 07:44
Shooting King
This message has been deleted by Shooting King.
Shooting King
RAAASENGAN
Join Date: Mar 2012
Location: India
Old 08-02-2013 , 09:55   Re: check if entity exist on coordinates
Reply With Quote #5

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 View Post
While spawning Items check if g_MapItemOrgins[X][3] is 0/1.
If 0 spawn.
__________________
As every time said, don't ever UNDERESTIMATE me.

Donate - Here

Last edited by Shooting King; 08-02-2013 at 09:57.
Shooting King is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-03-2013 , 12:15   Re: check if entity exist on coordinates
Reply With Quote #6

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
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 15:58.


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