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

spawn objects/entities [Help]


Post New Thread Reply   
 
Thread Tools Display Modes
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-13-2013 , 20:28   Re: spawn objects
Reply With Quote #11

OK lets say there can be more then one entity of the same class in the game, when one of these entities is touched and I remove that entity in the ontouch function, will the hook still be availlable for other entities of the same class but with a diffrent index? Will it only remove its own hook when ALL entities of the same class are destroyed ?

- Not removing a parameter, but only the "const", "String" and Float tags. Optional or not allowed?

Thanks for all youre help so far ajr1234 && others, I'm gonna finish the code soon and post it here for revision, maybe this thread could be used for a small tutorial on how to code entities for source.
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 02-13-2013 , 20:47   Re: spawn objects
Reply With Quote #12

The hook only affects the entity-- not all entities of the classname. You can still hook other entities of the same class. Also, you can hook more than one entity, i.e.:

PHP Code:
// hook entities to a particular callback
HookSingleEntityOutput(entity1"OnStartTouch"ontouch);
HookSingleEntityOutput(entity2"OnStartTouch"ontouch);
HookSingleEntityOutput(entity3"OnStartTouch"ontouch);
HookSingleEntityOutput(entity4"OnStartTouch"someothercallback);


// let's say some player touches entity1. The following callback is fired
public ontouch(const String:output[], calleractivatorFloat:delay)
{
     if (
IsValidEdict(caller)) RemoveEdict(caller);

     
// hook is removed for the destroyed caller (entity1), but remain for other hooked
     // entities (i.e. entity2 and entity3) that are not destroyed yet.

     // if the player then touches entity2, then entity2 is removed but entity3 is still hooked.
}

// fired for entity4
public someothercallback(const String:output[], calleractivatorFloat:delay)
{
     
// do something

As for your second question, no, you cannot remove the the declarations and data types; otherwise, the data being passed will be assumed to be integers, and that is not the case here.
ajr1234 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-15-2013 , 07:45   Re: spawn objects
Reply With Quote #13

Ok thanks, i think im starting to get it,
now i have a question about timers:
is there a way to group a bunch of active timers so that when you have multiple timers running and you wanna use KillTimer on only specifik timers, not all.
how or what would be the best way to do this?
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 02-15-2013 at 07:46.
striker07 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-15-2013 , 09:56   Re: spawn objects
Reply With Quote #14

Ok so this is what i have so far, could anyone revise this code?
I can compile it without warnings but i would like to know if its coded correctly and efficient.

All i need now is a way to assign each created entity timers and be able to remove them separatly while multiple timers are running. and offcourse a model for the entity, working on my own model but its going slow.

plugin
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
happs
Junior Member
Join Date: Aug 2012
Old 02-15-2013 , 14:40   Re: spawn objects/entities [Code Revise REQ]
Reply With Quote #15

I'm a little confused about what you are trying to do.

PHP Code:
stock CreateSomeEntity(clientFloat:Origin[3]) 
You pass the client index from the death callback, but then you don't use it.

PHP Code:
   new entity CreateEntityByName("my_entity"); 
What entity type are you trying to create?


PHP Code:
HookEvent("player_spawn"Event_PlayerSpawn);

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
  
g_bTouchedIt[activator] = false;

You should initialize your global variable. I'm guessing you want to only track who has touched these entities between lives.

As far as multiple-timers, I'm guessing you want these entities to disappear after a certain time if they were not triggered?
Spoiler


CreateTimer(...) returns a handle. You have to store this handle someplace along with the corresponding specific information you will use to identify it. Handles become invalidated when the timer fires its callback, or when repeating timers return Plugin_Stop. Accessing any stored handles after this event will cause problems. So be sure to clear any stored handles in your callback.

As a generic case, you can use an array to store the handles.
Spoiler

Last edited by happs; 02-15-2013 at 15:13.
happs is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 02-15-2013 , 22:24   Re: spawn objects
Reply With Quote #16

CreateTimer returns a handle to the timer object. You can use this to store the timer. Just create another global variable. As for setting a model, use SetEntityModel.
ajr1234 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-16-2013 , 07:35   Re: spawn objects/entities [Code Revise REQ]
Reply With Quote #17

First of all, thanks happs for revising my code.
Quote:
Originally Posted by happs View Post
I'm a little confused about what you are trying to do.
PHP Code:
stock CreateSomeEntity(clientFloat:Origin[3]) 
You pass the client index from the death callback, but then you don't use it.
woops, forgot to take that part out.
Quote:
Originally Posted by happs View Post
PHP Code:
new entity CreateEntityByName("my_entity"); 
What entity type are you trying to create?
I'm trying to make a very basic NPC entity that does not move, only rotate (not sure how to do this just yet but my model isnt finished yet and neighter is the anim).
 
Quote:
Originally Posted by happs View Post
PHP Code:
HookEvent("player_spawn"Event_PlayerSpawn);

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
g_bTouchedIt[activator] = false;

You should initialize your global variable. I'm guessing you want to only track who has touched these entities between lives.
yeah I know its just the entity coding that needs revising, the rest of the plguin isnt written yet, I first need my model finished.
Spoiler

Spot on! and also a timer to change the renderingmode en fix to visually show to ppl its gonna go away (so 2 timers per entitiy).
But since a whole series of entities can spawn, alot of timers will start.
So i want to find the corresponding timer linked to a entities index.
The problem with that is that my array for the timer handle would be waay to big since entities can have indexes of high numers right(100K+)?
its not that i can do like MAXPLAYERS or for Assign it an insanely high number to it? that would be way to intensive for the plugin
Spoiler

 
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-16-2013 , 07:38   Re: spawn objects/entities [Code Revise REQ]
Reply With Quote #18

My first solution was to just let the timer run out and detect if the entity is still alive at the beginning:
PHP Code:
CreateTimer(Float:20.0Timer:ChangeEntRenderany:entity);
CreateTimer(Float:30.0Timer:RemoveEntany:entity);
 
public 
ChangeEntRender(entity)
{
 if( 
IsValidEntity(entity) ) 
 {
  
SetEntityRenderMode(entityRENDER_GLOW); 
  
SetEntityRenderFx(entityRENDERFX_PULSE_FAST_WIDER);
 }  
}
public 
RemoveEnt(entity)
{
 if( 
IsValidEntity(entity) ) 
 {
  if( !
AcceptEntityInput(entity"kill") )
   
RemoveEdict(entity);
 }  

What would be the most efficient way? removing the timers or just letting them run out
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]

Last edited by striker07; 02-16-2013 at 07:44.
striker07 is offline
ajr1234
Senior Member
Join Date: Mar 2011
Location: Chicago, IL, U.S.A.
Old 02-16-2013 , 10:17   Re: spawn objects/entities [Code Revise REQ]
Reply With Quote #19

Quote:
Originally Posted by striker07 View Post
its not that i can do like MAXPLAYERS or for Assign it an insanely high number to it? that would be way to intensive for the plugin
Actually, you can. The engine has a limit to the number of edicts that it can create. You can essentially use a static array and get rid of the overhead of using a dynamically allocated container. Moreover, since you are looking to create some sort of NPC plugin, I bet you will need a method to store data. Unfortunately, SourcePawn is not object oriented. The closest you can do is use an array with enumerators, as I show below. The nice thing about this is that you can easily expand the enumerator with more properties (e.g. destruction time, NPC status, health, mission, etc.) using getters and setters. Plus, it is more efficient than using a dynamic array and constantly pushing/popping elements. Using a larger array just allocates more bytes during load, and a few thousand more bytes in memory is absolutely no problem at all.

Spoiler
ajr1234 is offline
striker07
Veteran Member
Join Date: Mar 2012
Location: Solar System/Earth/Belgi
Old 02-16-2013 , 13:20   Re: spawn objects/entities [Code Revise REQ]
Reply With Quote #20

Nice ajr, thanks.

Both methods for arrays are very usefull, i prefer yours though becous its logic is not specifically sourcemod related and it could benefit me more in the future for other projects idk .

got a few questions tough:

an invalid edict id would not be a problem in all these stocks becous all possible entities are cached into the array? it would only retrieve a false result?
__________________

Working on:
[CSGO/CSS] Mmorpg - an extensive XP/level modulair platform
Progress: [♣♣♣♣♣♣♣|♣♣♣]
striker07 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 12:30.


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