Raised This Month: $51 Target: $400
 12% 

Getting entity position


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LucasFromDK
Member
Join Date: Sep 2016
Old 10-26-2016 , 19:36   Getting entity position
Reply With Quote #1

PHP Code:
#include <sourcemod>
#include <sdktools>

public Plugin:myinfo 
{
    
name "New Plugin",
    
author "Unknown",
    
description "<- Description ->",
    
version "1.0",
    
url "<- URL ->"
}

public 
OnPluginStart( ) {
    
HookEvent"round_start"OnRoundStartEventHookMode_PostNoCopy )
}

public 
OnMapStart( ) {
    
PrecacheModel"models/custom.mdl"true )
}


public 
OnRoundStartHandle:event, const String:name[ ], bool:dontBroadcast ) { 
    for( new 
1<= GetMaxEntities( ); i++ ) { 
        if( !
IsValidEntity) ) { 
            return 
Plugin_Handled
        
}
        
        new 
String:classname128 ]         
        
GetEntityClassnameiclassnamesizeofclassname ) )
        
        if( 
StrEqualclassname"info_deathmatch_spawn" ) ) { 
            switch( 
GetRandomInt1) ) {
                case 
: {
                    new 
entity CreateEntityByName"CustomEnt" 
                    
                    if( ( 
entity != -) && DispatchSpawnentity ) ) { 
                        
SetEntityModelentity"models/custom.mdl" )  
                        
SetEntPropentityProp_Send"m_CollisionGroup")
                        
                        new 
Float:position]
                        
GetEntPropVectorclassnameProp_Send"m_vecOrigin"position )
                        
                        
position] += 10
                        
                        TeleportEntity
entitypositionNULL_VECTORNULL_VECTOR )
                    } 
                }
                
                case 
: {
                    
// case 2 code, etc
                
}
            }
        }
    }
    
    return 
Plugin_Continue

So... this is my code. I knew from the begining that GetEntPropVector( classname, can't work, but i don't know any other way that may retrieve info_deathmatch_spawn location.

I want to retrieve all deathmatch spawn locations and spawn my own entity in that spot. Can you help me please ?
LucasFromDK is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-26-2016 , 19:49   Re: Getting entity position
Reply With Quote #2

Instead of using a for loop to loop through all entities, use FindEntityByClassname:

PHP Code:
// spawn is going to be the entity index of the info_deathmatch_spawn
new spawn = -1;
while ((
FindEntityByClassname(spawn"info_deathmatch_spawn")) != -1)
{
    switch( 
GetRandomInt1) ) { 
        case 
: { 
            new 
entity CreateEntityByName"CustomEnt" )  
                     
            if( ( 
entity != -) && DispatchSpawnentity ) ) {  
                
SetEntityModelentity"models/custom.mdl" )   
                
SetEntPropentityProp_Send"m_CollisionGroup"
                         
                new 
Float:position]
                
// note the change to spawn here instead of classname
                
GetEntPropVectorspawnProp_Send"m_vecOrigin"position 
                         
                
position] += 10 
                         
                TeleportEntity
entitypositionNULL_VECTORNULL_VECTOR 
            }  
        } 
                 
        case 
: { 
            
// case 2 code, etc 
        

    } 

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
LucasFromDK
Member
Join Date: Sep 2016
Old 10-26-2016 , 20:00   Re: Getting entity position
Reply With Quote #3

There is another way to find out if a map have info_deathmatch_spawn without de-compile the map ?
LucasFromDK is offline
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 03:16.


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