Members | Sign In
All Forums > Mission Scripting
avatar

[Code Snippet] This is how you set an object's location to variables.

posted Jun 06, 2013 20:05:20 by badgeguy
For those of you looking for a way to set the X and Z (and sometimes Y) of an object to variables, please check out the attached code snippet "Peek A Boo". This script will place a craft 500 meters "North" of your current position 10 seconds after launch, and every 20 second there after, using variables set from Artemis' determined location and not by a "create relative to" or "copy properties from" action. It is not a tiny routine nor is it, in the grand scheme of things, gigantic.

I would love to hear your thoughts.

Rusty

Attachment: MISS_PeekABoo.zip
page   1
8 replies
avatar
matt.schillinger said Jun 06, 2013 21:02:21
Wow! That is some insightful scripting, and totally what I was looking for. I would have never thought of that.

Now I can place my mines exactly where I want to.

PERFECT!

Thanks!
avatar
JSpaced said Jun 07, 2013 08:56:56
Yep, I think PERFECT sums it up brilliantly.
Pure mathematical genius! Well done Rusty!
So anything we want to track the position of we just keep adding these chunks of code and changing the names of the ship. Amazing.

Now we can REALLY blow stuff up!

J
"We should give him the send-off he deserves. He died saving us all. Prepare a Rocket-Shed for immediate launch."
avatar
badgeguy said Jun 07, 2013 15:26:47
Instead of adding the code over and over again, could you not create an object with a specific name, copy the properties of the location of the ship you wish to "find", use the code on the specifically named temporary object then remove the temporary object. You now have the intended target's location without having to have the 84 lines or so of logic over and over again. This would mean only one bank of location code and a few lines of temporary object code for each one you want to find.
avatar
matt.schillinger said Jun 07, 2013 16:13:26
Hmm. I have some questions about this model.

In this case, all of the location code would need to have a condition of 'If_exists' for the temporary object. Is that right?

then the code only runs when you create the temp object.

So we have the code for the X and Z coordinates, using something like postTempX and posTempZ variables. Each of those events have a condition of 'if Temp exists'.

So to actually use it, we do the following.

create Temp object.
Copy postitionX and positionZ from the object we want to track/place near to Temp
use the posTempX and posTempZ values to place an object (mine in my case).
destroy Temp Object.

Does that look like the right logic?

One concern if that is correct: It would probably be pretty rare, but technically, if 2 objects were wanting to track simultaneously, the code would break, right? Can't have 2 temp objects simultaneously.. so one of the trackers would get the wrong coordinates.

With that said, I think that is probably rare enough that it's still worth it to use this model.
avatar
badgeguy said Jun 07, 2013 16:39:51
The if exist logic is what I was thinking as well, but I am not sure that the if exist logic is needed for each event within the location code as it would just return 0 anyway rather than cause an exception, but don't quote me on that. I am thinking that the if exist logic is only for the placement of the mine routine to verify that the location is valid upon trigger.

If you are sure you are going to track 2 objects at once, you could create a second bank of location (peek a boo) code with a different name. My idea was to keep the code from having to be placed for every single ship you were wishing to track (say it were 10 or 12). If it is only going to be for 2 ships, I see no reason not to have 2 sets of location code and leave it at that.
avatar
matt.schillinger said Jun 07, 2013 20:56:32
Tested it and it works with using a temp object. I didn't add a condition of temp object existing to the coordinate code. I just added check that temp and the object that will inevitably be blown up exist. The mine does some nice damage.

Thanks again!
avatar
JSpaced said Jun 16, 2013 16:43:40
Hi guys, I've tried your method of creating a temp object like this:
In the Start Block I've put:

<create type="genericMesh" x="1.0" y="0.0" z="1.0" angle="0.0" name="T1" meshFileName="dat\R_Post.dxs" textureFileName="dat\Hull_Roms.png" colorRed="0.0" colorGreen="0.0" colorBlue="0.0" />
<set_object_property property="pushRadius" value="0.0" name="T1" />

<event name_arme="Track Excalibur" id_arme="3cca342f-47ea-41cb-8c6b-ac45c7fbd9bc">
<if_variable name="chapter" comparator="EQUALS" value="1.0" />
<if_exists name="USS Excalibur" />
<copy_object_property property="positionZ" name1="USS Excalibur" name2="T1" />
<copy_object_property property="positionX" name1="USS Excalibur" name2="T1" />
</event>

Then I get:

Error:
Assertion failed!
Program: D:\Artemis\Artemis.exe
Line:162

Expression: pos.x > -SPACE_SIZE_W

How do you create an object that will follow you around, matching X and Z position and how do you HIDE it from Science and visual?

J

"We should give him the send-off he deserves. He died saving us all. Prepare a Rocket-Shed for immediate launch."
avatar
Mike_Substelny said Jun 19, 2013 16:36:31
When you create the object T1 you have already set its RGB color to black, I think that's 0, 0, 0. That will make its position symbol nearly invisible to Science and Long Range Scan. Isn't that what you want?

Try this:

Don't assign the generic object a dxs or png file. That should make it invisible to the view screen.

Instead of two copy_object_property blocks use one set_relative_position block and put T1 inside the stern section of the player ship (perhaps range 10 meters). Use a copy_object_property to copy the direction if you need it.
"Damn the torpedoes! Four bells, Captain Drayton!"

(Likely actual words of Admiral David Farragut, USN, at the battle of Mobile Bay. Four bells was the signal for the engine room to make full steam ahead).
Login below to reply: