Jump to content
The Dark Mod Forums

How do I spawn an entity from script?


Fidcal

Recommended Posts

How do I spawn an entity from script? This is what I've got so far, triggered by a switch in-game. the test light toggles on and off OK but no hammer is spawned that I can see...

 

 

 

entity g_testPart; //define global entity

void spawnParts()
{
sys.trigger($light_371); //test light works OK
g_testPart = sys.spawn("atdm:moveable_weapon_hammer");
$g_testPart.setOrigin('-1973 -1336 79');
}

Link to comment
Share on other sites

why don't you use hide/unhide?

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Obsttorte: Hide is not a bad idea but I need to create a loop of entities. When a new one is created then the oldest in the queue needs to be deleted so that there are not too many. Maybe I can just teleport the oldest to the front of the queue. It's not obvious how to simulate a sequence without arrays. In script I might have a variable with the latest number and increment it. Then a series of conditional checks to see which entity corresponds to that value.

 

Sotha: I'm unsure myself about the dollar sign. I saw an example like mine in another script so hope it's OK. My tenuous belief is that the spawn line creates an entity and names it g_testPart. Until then, no entity exists for this so I don't think I can stick a $ at the front. After that it's a normal entity and is referenced with the dollar sign. That's the theory at any rate. But... since it doesn't work - who knows? In support of that, there is no error such as wrong variable type or whatever.

Link to comment
Share on other sites

If you are refering to entityname you need the dollar sign.

If you are refering to a variable you don't use the dollar sign.

 

You are creating a variable that holds in the entity data, you are not setting it's entityname.

 

That's my belief, you need to test to be sure.

 

EDIT:

here is one example I found with quick googling:

http://www.doom3world.org/phpbb2/viewtopic.php?f=4&t=4999

Clipper

-The mapper's best friend.

Link to comment
Share on other sites

When a new one is created then the oldest in the queue needs to be deleted so that there are not too many.

you could hide it then ;)

 

well, for the loop thing, I guess you could just use several variables according to the number of entities you want to have in-game at maximum and an iterating number, I'm not sure if there's a modulo operator in the d3 scripting language, that would make things easier for you

FM's: Builder Roads, Old Habits, Old Habits Rebuild

Mapping and Scripting: Apples and Peaches

Sculptris Models and Tutorials: Obsttortes Models

My wiki articles: Obstipedia

Texture Blending in DR: DR ASE Blend Exporter

Link to comment
Share on other sites

Yeah, the scripting language really badly needs array support. It unfortunately a bit out of my league, but I could have used it a lot already. Right now I am playing tricks with storing stuff on spawnargs on entities (or the player, since that entity is always available). Really nasty workaround to just doing "for (i = 0; i < array.length; i ++) { ..}" :(

"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." -- George Bernard Shaw (1856 - 1950)

 

"Remember: If the game lets you do it, it's not cheating." -- Xarax

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • nbohr1more

      The FAQ wiki is almost a proper FAQ now. Probably need to spin-off a bunch of the "remedies" for playing older TDM versions into their own article.
      · 1 reply
    • nbohr1more

      Was checking out old translation packs and decided to fire up TDM 1.07. Rightful Property with sub-20 FPS areas yay! ( same areas run at 180FPS with cranked eye candy on 2.12 )
      · 3 replies
    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 7 replies
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
×
×
  • Create New...