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

Need help setting the position & removing an entity!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ethorbit
Member
Join Date: Sep 2016
Location: Oregon
Old 12-22-2017 , 17:46   Need help setting the position & removing an entity!
Reply With Quote #1

Hello. I'm trying to replace all npcs that are/get created with an npc_zombie. So far, it will create an npc if an entity classname includes npc_ in it, but the npc it creates isn't at the position I told it to go to, I also tried TeleportEntity, which didn't do anything. On top of that, I need a way to remove the original npc.

PHP Code:
new Handle:z_timer INVALID_HANDLE

public 
OnEntityCreated(entity, const String:classname[]){
    new 
ent = -1
    
while (ent FindEntityByClassname(ent,"classname")){
        if(
StrContains(classname"npc_") != -1){
            
decl String:targetname[128];
            
GetEntPropString(entityProp_Data"m_iName"targetnamesizeof(targetname));
            if(
StrEqual(targetname,"ThisIsNew") != 1){
                if(
IsValidEntity(entity)){
                    
z_timer CreateTimer(1.0SpawnDesiredNPC);
                }
            }
            return 
Plugin_Handled;
        } 
        else {
            return 
Plugin_Handled;
        }
    }
}

public 
Action SpawnDesiredNPC(Handle timerentity)
{
new 
ent = -1
decl String
:targetname[128];
if(
StrEqual(targetname,"ThisIsNew") != 1){
    if(
IsValidEntity(entity)){
        new 
Float:npcposition[3];
            new 
Float:npcangle[3];
            
GetEntPropVector(entityProp_Send"m_vecOrigin"npcposition);
            
GetEntPropVector(entityProp_Send"m_angRotation"npcangle);
            new 
EntIndex CreateEntityByName("npc_zombie");    
            
DispatchKeyValueVector(EntIndex"m_vecOrigin"npcposition);
            
DispatchKeyValueVector(EntIndex"m_angRotation"npcangle);
            
DispatchKeyValue(EntIndex"m_iName""ThisIsNew")
            
DispatchSpawn(EntIndex);
            
TeleportEntity(EntIndexnpcpositionnpcangleNULL_VECTOR); // Just testing. Doesn't work.
            
}
            
CloseHandle(z_timer);
        return 
Plugin_Handled;
        }
    else
    {
    
CloseHandle(z_timer);
    return 
Plugin_Handled;
    }


Last edited by Ethorbit; 12-22-2017 at 21:06.
Ethorbit is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-22-2017 , 20:00   Re: Need help setting the position & removing an entity!
Reply With Quote #2

I'd start by fixing your indentation.
Mitchell is offline
Ethorbit
Member
Join Date: Sep 2016
Location: Oregon
Old 12-22-2017 , 20:50   Re: Need help setting the position & removing an entity!
Reply With Quote #3

Still need help. Particularly here:
PHP Code:
GetEntPropVector(entityProp_Send"m_vecOrigin"npcposition); 
        
GetEntPropVector(entityProp_Send"m_angRotation"npcangle);   
        new 
EntIndex CreateEntityByName("npc_zombie");     
        
DispatchKeyValueVector(EntIndex"m_vecOrigin"npcposition); 
        
DispatchKeyValueVector(EntIndex"m_angRotation"npcangle); 
        
DispatchKeyValue(EntIndex"m_iName""ThisIsNew"
        
DispatchSpawn(EntIndex); 
        
TeleportEntity(EntIndexnpcpositionnpcangleNULL_VECTOR); // Just testing. Doesn't work. 
I do not see why this isn't working. When I spawn an npc using npc_create <name> it doesn't place a npc_zombie there, it places the zombie inside the ground probably at 0,0,0, no matter what. It doesn't teleport it either.

Last edited by Ethorbit; 12-23-2017 at 03:14.
Ethorbit is offline
Ethorbit
Member
Join Date: Sep 2016
Location: Oregon
Old 12-22-2017 , 21:07   Re: Need help setting the position & removing an entity!
Reply With Quote #4

Quote:
Originally Posted by Mitchell View Post
I'd start by fixing your indentation.
Done.
Ethorbit 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 00:46.


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