Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
Darrin

Registered:
Posts: 35
Reply with quote  #1 
So, let's say you want to set a named object's x-position and z-position to variables. I was told this wasn't possible. So I went and did it anyway. 

For the more exalted programmers out there, please forgive me if you've already found a better/faster way to do this. (Ah, the ravages of a Liberal Arts degree...)

And yes, I am aware that it's fewer events if you iterate through the main script loop but I was worried that the object's position might change too much between loops. 


<event name="xzpos0" id_arme="856fba42-d19e-49ca-b922-f95b80d46196">
<if_variable name="FindObject" comparator="EQUALS" value="1.0" />
<set_variable name="xpos" value="0.0" />
<set_variable name="zpos" value="0.0" />
<set_variable name="FindObject" value="2.0" integer="yes" />
</event>
<event name="xpos1" id_arme="c9411e10-ed9b-49be-bbf3-a00cfe160b26">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="0.0" mostX="65536.0" mostZ="100000.0" />
<set_variable name="xpos" value="65536 + xpos" />
</event>
<event name="xpos2" id_arme="9f64b346-5b60-48fa-93f6-59f7be9b2181">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="32768.0 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="32768 + xpos" />
</event>
<event name="xpos3" id_arme="54290197-fa87-4098-8eaf-f547e9ffd438">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="16384.0 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="16384 + xpos" />
</event>
<event name="xpos4" id_arme="e11123ff-6676-4f41-a12f-8acc1e56f31d">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="8192 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="8192 + xpos" />
</event>
<event name="xpos5" id_arme="54e372c7-f6c8-4e47-a748-9d3cb96aa762">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="4096 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="4096 + xpos" />
</event>
<event name="xpos6" id_arme="ea837546-e219-48e2-a888-5481cc9e2828">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="2048 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="2048 + xpos" />
</event>
<event name="xpos7" id_arme="5e649d63-a223-4523-a185-c502003a8b89">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="1024 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="1024 + xpos" />
</event>
<event name="xpos8" id_arme="a59524ed-a058-4217-a956-ac2fa480b3c2">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="512 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="512 + xpos" />
</event>
<event name="xpos9" id_arme="d6435591-bc9b-4125-b1dc-9c590528f241">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="256 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="256 + xpos" />
</event>
<event name="xpos10" id_arme="25b3219c-9570-47b3-a164-7cfed47e005e">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="128 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="128 + xpos" />
</event>
<event name="xpos11" id_arme="dc15e930-a4ef-4e84-add6-a93d47683819">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="64 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="64 + xpos" />
</event>
<event name="xpos12" id_arme="21ee4c7d-a44f-4969-8323-fe2eb1a888bc">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="32 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="32 + xpos" />
</event>
<event name="xpos13" id_arme="f3a96268-fb8e-4854-9443-8fe36b581594">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="16 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="16 + xpos" />
</event>
<event name="xpos14" id_arme="1659b2a6-bebc-4c59-ad98-49d094fe0991">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="8 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="8 + xpos" />
</event>
<event name="xpos15" id_arme="b3273b6c-f226-46d5-9bcc-f3b9537ea68d">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="4 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="4 + xpos" />
</event>
<event name="xpos16" id_arme="169c67d0-b245-428e-92c5-a6f1283c5e36">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="2 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="2 + xpos" />
</event>
<event name="xpos17" id_arme="dde37f0a-27ce-4579-8edf-20b7ab343718">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="1 + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="1 + xpos" />
</event>
<event name="zpos1" id_arme="13b93f2e-4592-465d-a108-40aa08b0c36b">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="0.0" mostX="100000.0" mostZ="65536.0" />
<set_variable name="zpos" value="65536 + zpos" />
</event>
<event name="zpos2" id_arme="94987061-f6c3-4ddc-924e-0b848cd8ba00">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="32768 + zpos" />
<set_variable name="zpos" value="32768 + zpos" />
</event>
<event name="zpos3" id_arme="8036b4c6-8398-4f23-8eef-a39e3c72dd9e">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="16384 + zpos" />
<set_variable name="zpos" value="16384 + zpos" />
</event>
<event name="zpos4" id_arme="5fbb82e0-b3f8-4061-a324-7b9d2742e581">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="8192 + zpos" />
<set_variable name="zpos" value="8192 + zpos" />
</event>
<event name="zpos5" id_arme="06f0b545-fa10-464e-801a-2d1660c550e1">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="4096 + zpos" />
<set_variable name="zpos" value="4096 + zpos" />
</event>
<event name="zpos6" id_arme="91790ce6-0e86-4d89-8e56-726a1239099a">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="2048 + zpos" />
<set_variable name="zpos" value="2048 + zpos" />
</event>
<event name="zpos7" id_arme="b6513858-bd07-4839-bf65-7174b153a0e9">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="1024 + zpos" />
<set_variable name="zpos" value="1024 + zpos" />
</event>
<event name="zpos8" id_arme="500de33d-03d3-4ae9-bdd3-b8e90c2d6813">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="512 + zpos" />
<set_variable name="zpos" value="512 + zpos" />
</event>
<event name="zpos9" id_arme="2b800071-6792-4245-a9d2-d9adb13d792d">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="256 + zpos" />
<set_variable name="zpos" value="256 + zpos" />
</event>
<event name="zpos10" id_arme="10cd9590-921f-4112-a82e-b5a76bd90cb2">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="128 + zpos" />
<set_variable name="zpos" value="128 + zpos" />
</event>
<event name="zpos11" id_arme="dad0b166-8f85-4c44-9b37-d2193efd3b07">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="64 + zpos" />
<set_variable name="zpos" value="64 + zpos" />
</event>
<event name="zpos12" id_arme="116cbffa-088f-4570-b5c3-d23ed3434777">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="32 + zpos" />
<set_variable name="zpos" value="32 + zpos" />
</event>
<event name="zpos13" id_arme="ecebb035-0d8a-410f-9f5a-acecb76eb2ea">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="16 + zpos" />
<set_variable name="zpos" value="16 + zpos" />
</event>
<event name="zpos14" id_arme="7adfbb5c-1906-45bc-84e0-d9dd7cdddef3">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="8 + zpos" />
<set_variable name="zpos" value="8 + zpos" />
</event>
<event name="zpos15" id_arme="a64d08f5-ab5b-40c2-8b5d-75787432d107">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="4 + zpos" />
<set_variable name="zpos" value="4 + zpos" />
</event>
<event name="zpos16" id_arme="043c7694-9a26-4ed0-b410-6775f1140d24">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="2 + zpos" />
<set_variable name="zpos" value="2 + zpos" />
</event>
<event name="zpos17" id_arme="a7bc3749-f40c-4672-9625-1af3ab868a06">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="1 + zpos" />
<set_variable name="zpos" value="1 + zpos" />
</event>
<event name="xzpos_Done" id_arme="e3fb9f94-b0c7-4bb1-a346-f42426918160">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<big_message title="Artemis is at |xpos|, |zpos|." />
<set_variable name="FindObject" value="3.0" integer="yes" />
</event>



Mike Substelny

Avatar / Picture

Administrator
Registered:
Posts: 2,115
Reply with quote  #2 
Great work, Darrin!

There should be no problem with using this. While the Artemis software bogs down when you place a large number of objects on the map, the actual file size of a mission script doesn't seem to matter.

This code should make it possible to place a mine relative to an object such as an AI ship.

__________________
"The Admiralty had demanded six ships; the economists offered four; and we finally compromised on eight."
- Winston Churchill
ryleyra

Registered:
Posts: 2,872
Reply with quote  #3 
That is a quite efficient bit of code. Based on a binary search, I think? Also, you're doing both a greater than and less than test at once with if_outside_box.

Personally, I tend to track objects by copying the x and z coordinates into a variable as the object is created, and then using a greater than/less than test to monitor when the object moves to a new location. If I'm just tracking, adding or subtracting 4 seems to keep pace as long as I do one test per cycle. If I'm searching for the object, I have to use a larger number, like 100, and the search can take several seconds. Once it's found the object, though, it keeps up as it moves.

Fortunately, the players really can't tell if you place an object 4 or even 100 units off of the original object. That's less than the size of most ships. (Which tend to be around 100x150 units)

Darrin

Registered:
Posts: 35
Reply with quote  #4 
If you want to iterate the search through the main script loop:


<event name="xzfind" id_arme="e373ca40-dd7a-4014-818a-3166fda8fbf1">
<if_variable name="FindObject" comparator="EQUALS" value="1.0" />
<set_variable name="toplim" value="131072.0" />
<set_variable name="xpos" value="0.0" />
<set_variable name="zpos" value="0.0" />
<set_variable name="FindObject" value="2.0" integer="yes" />
</event>
<event name="xztop" id_arme="afca86a6-7ef4-4a3e-ae51-001e417a4301">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<set_variable name="toplim" value="toplim / 2" />
</event>
<event name="xpos" id_arme="64149200-f597-4ba1-8ccd-2eb0b1ce624b">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="xpos" leastZ="0.0" mostX="toplim + xpos" mostZ="100000.0" />
<set_variable name="xpos" value="toplim + xpos" />
</event>
<event name="zpos" id_arme="56604bfc-da45-4449-a95b-b991666ee0fb">
<if_variable name="FindObject" comparator="EQUALS" value="2.0" />
<if_outside_box name="Artemis" leastX="0.0" leastZ="zpos" mostX="100000.0" mostZ="toplim + zpos" />
<set_variable name="zpos" value="toplim + zpos" />
</event>
<event name="xzfound" id_arme="ab0bf346-3f1f-4c11-ba6f-a1aa3f4c7449">
<if_variable name="toplim" comparator="EQUALS" value="1.0" />
<set_variable name="xpos1" value="xpos1 + 1" />
<set_variable name="zpos1" value="zpos1 + 1" />
<big_message title="Artemis is at |xpos1|, |zpos1|." />
<set_variable name="toplim" value="131072.0" />
<set_variable name="FindObject" value="3.0" integer="yes" />
</event>



If you want to make it faster, change the xzfound conditional to toplim = 128 or 64 or whatever gets you close enough to work.

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.