Raised This Month: $ Target: $400
 0% 

Randomly spawn entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 05-22-2012 , 02:49   Randomly spawn entity
Reply With Quote #1

I have been trying to randomly spawn entities on maps without making the spawn points myself, but it seems that the entities are going behind maps and out of bounds as well.

Can someone help with some better working methods or ways of doing this? Thanks!

PHP Code:
public MakeZmGift()
{
    new 
iEnt
    
new Float:spawnAngle[3
    
    
iEnt fm_create_entity("info_target")
    
    if(!
pev_valid(iEnt))
        return
    
    
set_pev(iEntpev_classname"eqgift")
    
    
engfunc(EngFunc_SetModeliEntg_models[random_num(0sizeof g_models 1)])
    
set_pev(iEnt,pev_solidSOLID_BBOX)
    
set_pev(iEntpev_movetypeMOVETYPE_FLY)
    
    
set_pev(iEntpev_minsFloat:{-10.0,-10.0,0.0})
    
set_pev(iEntpev_maxsFloat:{10.0,10.0,25.0})
    
set_pev(iEntpev_sizeFloat:{-10.0,-10.0,0.0,10.0,10.0,25.0})
    
engfunc(EngFunc_SetSizeiEntFloat:{-10.0,-10.0,0.0}, Float:{10.0,10.0,25.0})
    
    new 
Float:vMinOrigin[3], Float:vMaxOrigin[3];
    new 
Float:vOrigin[3], iMaxEnts global_getglb_maxEntities );
    
    new 
ij;
    for( 
0iMaxEntsi++ )
    {
        if( 
pev_valid) )
        {
            
pevipev_originvOrigin );                
            if ( 
vOrigin[0] == 0.0 && vOrigin[1] == 0.0 && vOrigin[1] == 0.0 )
                
fm_get_brush_entity_originivOrigin );
            
            for( 
03j++ )
            {
                if( 
vOrigin] > vMaxOrigin] )
                    
vMaxOrigin] = vOrigin];
                if( 
vOrigin] < vMinOrigin] )
                    
vMinOrigin] = vOrigin];
            }
        }
    }
    
    if ( 
get_distance_fvMinOriginvMaxOrigin ) <= 500.0 )
    {
        for ( 
03i++ )
        {
            
vMinOrigin] -= -360.0;
            
vMaxOrigin] += 360.0;
        }
    }
    
    for ( 
03i++ )
        {
        
vOrigin] = random_floatvMinOrigin], vMaxOrigin] );        
    }
    
    
fm_entity_set_originiEntvOrigin );
    
    if ( !
UnStuck(iEnt, .iHullsize HULL_HEAD, .iAttempts 128 ) )
    {
        
fm_remove_entity(iEnt)
        return
    }
    
    
set_pev(iEntpev_anglesspawnAngle)
}

stock UnStuckidiHullsize = -1iStartDist 32iAddDist 32iMaxDist 1000iAttempts 128 )
{
    if ( 
iHullsize == -)
        
iHullsize zm_getHullSizeid );

    if( 
iHullsize == -|| !is_user_stuckidiHullsize ) ) 
    {
        return 
true;
    }

    new 
Float:vOrigin[3], Float:vNewOrigin[3], i;
    
pevidpev_originvOrigin );

    for ( new 
iDistance iStartDistiDistance iMaxDistiDistance += iAddDist )
    {
        for( 
0iAttemptsi++ )
        {
            
vNewOrigin[0] = random_floatvOrigin[0] - iDistancevOrigin[0] + iDistance );
            
vNewOrigin[1] = random_floatvOrigin[1] - iDistancevOrigin[1] + iDistance );
            
vNewOrigin[2] = random_floatvOrigin[2] - iDistancevOrigin[2] + iDistance );

            if ( 
fm_trace_hullvNewOriginiHullsizeid ) == )
            {
                
fm_entity_set_originidvNewOrigin );
                return 
true;
            }
        }
    }

    return 
false;
}

stock zm_getHullSize(id)
 {
    return (
pev(idpev_flags) & FL_DUCKING) ? HULL_HEAD HULL_HUMAN;
 }
 
 
stock bool:is_user_stuckidiHullsize = -)
{
    if ( 
iHullsize == -)
        
iHullsize zm_getHullSizeid );
    
    new 
Float:vOrigin[3], iTrace 0
    
pevidpev_originvOrigin );
    
engfuncEngFunc_TraceHullvOriginvOriginDONT_IGNORE_MONSTERSiHullsizeidiTrace );
    
    if( 
get_tr2iTraceTR_StartSolid ) || get_tr2iTraceTR_AllSolid ) || !get_tr2iTraceTR_InOpen ) )
        return 
true;
    
    return 
false;


Last edited by Y060N; 05-22-2012 at 15:07.
Y060N is offline
byetovice
Senior Member
Join Date: Nov 2009
Location: Turkey
Old 05-22-2012 , 03:21   Re: Randomly spawn entity
Reply With Quote #2

Get a random origin, and get another origin just under the skybox adding height to the first origin you find.
So place your entity there and let it fall on the ground.
__________________
Working on mods..
byetovice is offline
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 05-22-2012 , 03:28   Re: Randomly spawn entity
Reply With Quote #3

Can you give me an example of this? I'm not sure how to find the skybox beginning. Thanks, I'd appreciate it
Y060N is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-22-2012 , 07:47   Re: Randomly spawn entity
Reply With Quote #4

If you want to spawn them during the game, you can store random player origins on every X seconds and then spawn the entities on these origins.
__________________
<VeCo> is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 05-22-2012 , 13:13   Re: Randomly spawn entity
Reply With Quote #5

This will help you with origins: https://forums.alliedmods.net/showthread.php?t=132500
t3hNox is offline
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 05-22-2012 , 15:08   Re: Randomly spawn entity
Reply With Quote #6

I've posted the code I am trying to get to work. Can anyone help me out?

The superspawns did not work correctly for me, it only spawned a few out of ~60 (so I am guessing they were outside the map)

Last edited by Y060N; 05-22-2012 at 15:22.
Y060N is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 05-22-2012 , 18:01   Re: Randomly spawn entity
Reply With Quote #7

Check this out:
http://forums.alliedmods.net/showthread.php?t=49829
__________________
Quote:
#define true ((rand() % 2)? true: false) //Happy debugging suckers
mottzi is offline
Send a message via MSN to mottzi
Reply



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 06:09.


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