Game Development Community

Dynamic creation of Items in the World

by Kyle Hubert · in Technical Issues · 05/16/2005 (2:25 pm) · 3 replies

This really pertains to throwing Items, but in the future I want to dynamically create new Items.

My problem is that I started using the starter.fps and extended the HealthKit to use onThrow. At first I did not think I succeeded since I didn't see anything on the screen after hitting the throw key. However, hitting F11 exposed my problem. The Items placeholder was there in the World Editor, when I clicked the Item the engine suddenly filled it in with the right Object for rendering (dts and such).

I believe what is happening is the Client side's Scene isn't recognizing an addition to the MissionGroup that would result in reloading or rendering or whatever. Something about clicking the item in the World Editor correctly forces the client to start rendering the Item.

If I understand it, this code for onThrow should be correct:

HealthKit::onThrow(%this,%user,%amount) {
%user.decInventory(%this,%amount)
%obj = new Item() {
datablock = %this;
}
MissionGroup.add(%obj);
return %obj;
}

Other than checking for amounts and all that jazz, shouldn't this cause the Client to render the new Object as soon as the setTransform is called from the ShapeBase::throwObject function?

Thanks for your help.

-Kyle

PS: I might remember some of the details of the function names incorrectly, I'm at work and not in front of the code.

About the author

Recent Threads


#1
05/16/2005 (5:51 pm)
It's a bit hard to tell since you didn't tell us where you placed your script, but some of the common issues regarding creating new items:

1) If you want an object to be net propagated (even in a single player game), it should be created in the server scripts.
2) The item needs to have networking enabled: i.e., it needs to be created as the proper type of object, have a scoping type set, etc.
3) The object needs to have appropriate network code (pack/unpack, etc.) written to handle the network propagation.
4) Any client side manipulation of the object needs to be handled properly: normally through RPC calls (commandToServer).

It's hard to tell from your small code snippet, but you probably aren't passing the right datablock value through your execution chain. you may want to put echos in the code from the initial "throw" command all the way down to this function and see if each are being called as expected.
#2
05/17/2005 (4:07 pm)
Uh, I left out the details due to the fact it was based on starter.fps. I forgot not everyone is probably familiar with that one.

The actual answer, for any future people looking, is here:

http://www.garagegames.com/mg/forums/result.thread.php?qt=22253

-Kyle
#3
05/18/2005 (8:31 am)
Hehe..it's not that we're not familiar with starter.fps, it's that we aren't sure that you were using it!

Thanks for posting the fix!