2 registered members (AndrewAMD, Ayumi),
1,405
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How can I set the entity name in script?
#224447
08/30/08 07:26
08/30/08 07:26
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
Hi everybody,
when I set an entity in WED it gets a name by WED.
How can I set this entity name when I create the entity in script by ent_create ???
I tried it as follows:
player1 = ent_create (str_create("giana.mdl"), vector(489 , -71 , -150), NULL); wait(1); player1.link.name = "giana.mdl_02";
That causes no compiler problem at all, but doesn't set the name either :-(
Regards, Pegamode.
Last edited by pegamode; 08/30/08 07:48. Reason: additional info
|
|
|
Re: How can I set the entity name in script?
[Re: pegamode]
#224495
08/30/08 14:25
08/30/08 14:25
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Errr, whats wrong with calling it by the name you created it under, as in "player1" from your examples?
Where is there a diffeerence?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: How can I set the entity name in script?
[Re: pegamode]
#224507
08/30/08 15:43
08/30/08 15:43
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
Senior Member
|
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
It should have an entity number.
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: How can I set the entity name in script?
[Re: pegamode]
#224562
08/30/08 21:08
08/30/08 21:08
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
Senior Member
|
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
pegamode this may help you
handle (object); Returns a handle of an engine object. A handle is a unique object number that can be assigned to any variable, and identifies that object. Parameters: object - ENTITY*, STRING*, BMAP*, VIEW*, PANEL*, TEXT*, FONT*, SOUND*, or MATERIAL* pointer. Returns: Handle of object. Speed: Fast Remarks: A handle is similar to a pointer, but is just a number and therefore can be assigned to any variable or skill. For getting a handle to a lite-C struct that is not an engine object, use the pVars pointer. After saving and loading a game, a handle generated by this instruction is guaranteed to reference always the same object - this is not guaranteed for pointers that are just references to memory areas. On a single player system, the entity handle is valid immediately after entity creation ( (► ent_create). On multiplayer systems, it can take up to 0.5 seconds until the entity is created on all connected machines and the handle becomes valid. During that time the entity handle can not be used. For using a handle to get the referenced object, it can be converted to a pointer through the ptr_for_handle instruction. The handle is the first integer of an object. It consists of a unique index number plus an object type identifier taken from the following table, and left shifted by 24. The handle can be used to identify the type of the object. For converting the handle to a var that contains the index number, right shift it by 24, then left shift the resulting int by 10. INVALID -1 ENTITY 4 (global) ENTITY 5 (local) ENTITY 8 (layer) STRING 10 FONT 11 BMAP 12 MATERIAL 13 SOUND 14 STREAM 15 TEXT 20 PANEL 21 VIEW 22
Example: if(entity) { my.skill48 = handle(entity); // store entity pointer } you = ptr_for_handle(my.skill48); // restore YOU; See also: ptr_for_handle, pVars
► latest version online
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: How can I set the entity name in script?
[Re: pegamode]
#224575
08/30/08 22:35
08/30/08 22:35
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
If an entity is set in WED and you call (entity->link).name the name is returned. Correct. If an entity is created by ent_create and you call the same NULL is returned. Correct, but un-important. So an entity created by ent_create has no name ... Incorrect, true it has no name in link, but using link as a name is a BAAD habit. The link info really only tells you about how it was created in WED or 'originally' as a global object. The name you 'should' be using, youve already supplied in your examples. -> player1 Because you will use something like the following to create your entity, player1 = ent_create (str_create("giana.mdl"), vector(489 , -71 , -150), NULL);you can from here on refer to this entity as "player1", if you want to rename it on-the-fly then you can always do something like this...
ENTITY* player1; //outside all functions - global pointer is available to all
ENTITY* giana_mdl_02; //outside all functions - global pointer is available to all
...
...
// inside some function
//
if( player1 != NULL ) // make sure player has been created
{
giana_mdl_02 = player1; // 'aim' new name at our entity (this line perfectly fine)
player1 = NULL; // 'remove' old name from our entity (try to avoid this line, can get messy)
}
...
from now on you access the same entity, by the new name of "giana_mdl_02". Is this what you're after? So what do you need the link name for? How do you plan on using it? If we knew that we would be better able to suggest a better way of doing what you want, rather than messing around with un-trustworthy INTERNAL data structures.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|