Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
Xavier Wise

Registered:
Posts: 981
Reply with quote  #1 

In another post, I added code that allowed destruction of all randomly named ships. I used this code to also create how to create random names for a ship. In the TSN Sandbox, I use this code to spawn a fleet of ships all with the name --, assign specific AI to that group of ships and then rename to a random name. 

Code:
<event name="Check for -- names" id_arme="1941463d-5354-4003-b1bc-12f68d2174fd" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="RandomName" comparator="EQUALS" value="1.0" />
<if_not_exists name="--" />
<set_variable name="RandomName" value="0.0" integer="yes" />
</event>

<event name="Randomise Digits" id_arme="5c0a7923-b28e-401e-8932-46115fe6bb31" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="RandomName" comparator="EQUALS" value="1.0" />
<if_exists name="--" />
<set_variable name="firstnumber" randomIntLow="0" randomIntHigh="9" integer="yes" />
<set_variable name="secondnumber" randomIntLow="0" randomIntHigh="9" integer="yes" />
<set_variable name="random letter" randomIntLow="1" randomIntHigh="26" integer="yes" /></event>

<event name="A" id_arme="8da645ee-5a55-4259-b55c-8e236a19b7be" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="1.0" />
<set_ship_text name="--" newname="A|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="B" id_arme="df47cd14-4047-424a-9cb6-1b9af479e1f1" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="2.0" />
<set_ship_text name="--" newname="B|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="C" id_arme="ccc1a5e2-b843-4e60-8b29-75e9614f3c07" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="3.0" />
<set_ship_text name="--" newname="C|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="D" id_arme="7b6b0cb0-e4f3-43c6-ac9c-22285716f933" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="4.0" />
<set_ship_text name="--" newname="D|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="E" id_arme="fae62c6e-0414-436f-a902-c275c1f10893" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="5.0" />
<set_ship_text name="--" newname="E|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="F" id_arme="ee327d69-af86-4b58-8e2d-d882060cbf03" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="6.0" />
<set_ship_text name="--" newname="F|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="G" id_arme="6fad4455-c434-4d85-84bd-e6f95e33c3fa" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="7.0" />
<set_ship_text name="--" newname="G|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="H" id_arme="e66981a5-60e7-45af-968a-b336211201f1" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="8.0" />
<set_ship_text name="--" newname="H|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="I" id_arme="5ec09bbf-7a2e-4ee0-8d71-979672acbba5" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="9.0" />
<set_ship_text name="--" newname="I|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="J" id_arme="0ff9a1b7-7e9e-49c6-8c79-8051c67236ed" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="10.0" />
<set_ship_text name="--" newname="J|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="K" id_arme="9223ea33-28d6-4d74-b573-073f3c367fd3" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="11.0" />
<set_ship_text name="--" newname="K|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="L" id_arme="2bbf7973-51af-40e0-a38e-63b9d1c64065" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="12.0" />
<set_ship_text name="--" newname="L|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="M" id_arme="a8d9b38a-1a0f-4828-a9f9-91143d836a67" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="13.0" />
<set_ship_text name="--" newname="M|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="N" id_arme="b168883e-0fde-4fe6-b361-01cc6dcc16b9" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="14.0" />
<set_ship_text name="--" newname="N|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="O" id_arme="b21d4319-88ce-46cd-aedb-b8c336f065d9" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="15.0" />
<set_ship_text name="--" newname="O|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="P" id_arme="592d4bc5-d372-4688-b6b5-f74dda37c5ba" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="16.0" />
<set_ship_text name="--" newname="P|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="Q" id_arme="e6b1d442-cb69-4073-8e2c-d6f276448026" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="17.0" />
<set_ship_text name="--" newname="Q|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="R" id_arme="eda91eb0-0684-4b0f-ba43-f4f7dcad6811" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="18.0" />
<set_ship_text name="--" newname="R|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="S" id_arme="f48e1017-5383-4ee9-bfb5-dc54111b5894" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="19.0" />
<set_ship_text name="--" newname="S|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="T" id_arme="d7ff7a7b-eea7-4fa4-a569-95055b55a178" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="20.0" />
<set_ship_text name="--" newname="T|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="U" id_arme="7b6e7ff1-9539-4cbf-84c3-59cb96baa9e9" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="21.0" />
<set_ship_text name="--" newname="U|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="V" id_arme="88a4ab28-1d16-4473-8990-51dffe93da9f" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="22.0" />
<set_ship_text name="--" newname="V|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="W" id_arme="d2868148-7a35-4ebe-bcfa-d57391f78855" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="23.0" />
<set_ship_text name="--" newname="W|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="X" id_arme="32449c38-c4b9-4ab7-94b7-5d43c1f7ca70" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="24.0" />
<set_ship_text name="--" newname="X|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="Y" id_arme="bf75887b-269c-4585-9151-c980f6c5a2e8" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="25.0" />
<set_ship_text name="--" newname="Y|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>

<event name="Z" id_arme="0ed204db-d53d-4720-bd40-6280a2a555b7" parent_id_arme="eb987843-ce4d-47f0-9a89-a9295442455f">
<if_variable name="random letter" comparator="EQUALS" value="26.0" />
<set_ship_text name="--" newname="Z|firstnumber||secondnumber|" />
<set_variable name="random letter" value="0.0" integer="yes" /></event>




Below are the snippets of code from the TSN Sandbox which spawned an enemy fleet, chose a particular set of AI instructions, and then renamed the ships randomly.

Code:
<event name="Custom 1A" id_arme="7cbbe37d-6ec1-46fe-808c-f304306ad0a4" parent_id_arme="0fc9dd71-2783-4713-a773-bca1116e079d">
<if_gm_button text="Menu 1\Custom 1A" />
<create type="enemy" use_gm_position="" name="--" raceKeys="Kralien enemy" hullKeys="medium" fleetnumber="Fleetnumber" />
<create type="enemy" use_gm_position="" name="--" raceKeys="Kralien enemy" hullKeys="small" fleetnumber="Fleetnumber" />
<create type="enemy" use_gm_position="" name="--" raceKeys="Kralien enemy" hullKeys="small" fleetnumber="Fleetnumber" />
<create type="enemy" use_gm_position="" name="--" raceKeys="Kralien enemy" hullKeys="small" fleetnumber="Fleetnumber" />
<set_variable name="RandomName" value="1.0" integer="yes" />
<set_variable name="Auto AI Type" value="5.0" />
</event>

*Note, Fleetnumber drawn from a variable that is assigned and then incremented by +1 so that a second fleet created using the same button press has a different fleet number than the first.

Code:
<event name="Hunt Base" id_arme="54b51b38-18cc-40ec-b94b-87601daa45ca" parent_id_arme="94f2a431-32fc-497a-8028-05ffdb8f16b3">

<if_variable name="Auto AI Type" comparator="EQUALS" value="5.0" />
<clear_ai name="--" />
<add_ai type="TRY_TO_BECOME_LEADER" name="--" />
<add_ai type="CHASE_STATION" value1="100000" name="--" />
<add_ai type="CHASE_AI_SHIP" value1="3000" value2="500" name="--" />
<add_ai type="CHASE_PLAYER" value1="3000" value2="500" name="--" />
<add_ai type="CHASE_ANGER" name="--" />
<add_ai type="LEADER_LEADS" name="--" />
<add_ai type="FOLLOW_LEADER" name="--" />
</event>


__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
Xavier Wise

Registered:
Posts: 981
Reply with quote  #2 
Below is the link to the post in which you can find the code to destroy all ships with random names.

Post - Destroy all randomly named ships - Problem Solved

__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
Mike Substelny

Avatar / Picture

Administrator
Registered:
Posts: 1,692
Reply with quote  #3 
That's very clever, Xavier. I love it!

Thank you very much for sharing.

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

Registered:
Posts: 2,439
Reply with quote  #4 
Seriously? All 26 letters? [biggrin] I don't think I'll go that far.

It's a great example, though.
Xavier Wise

Registered:
Posts: 981
Reply with quote  #5 
Yes... all 26 letters. I wanted it to come up with every possible combination that the normal coop or single player modes come up with it. Really though, it was quick just to edit one letter and one variable, so didn't take much time at all. Infact, I had it written and tested in about 10 minutes. It took me longer to figure out HOW to put it all together than actually write it.

Feel free just to copy the code to save time!

__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
Richard

Registered:
Posts: 104
Reply with quote  #6 
Xavier, great code this one of yours!

I tryed to do something similar, but I faced a problem: my random numbers had always a decimal even with the variables set to integer (ie: C2.04.0 when it should be just C24).

Do you know what may be the cause?

Thanks
Fish Evans

Registered:
Posts: 350
Reply with quote  #7 
Try setting it to a value or 0 in the start block with the is interger set. - its posible that its beeing called else where as a float first which would set it up as such.
ryleyra

Registered:
Posts: 2,439
Reply with quote  #8 
Exactly. Integer variables should always be declared in the start block.

Technically you could create them in any event as long as you make sure it is declared before it is used. Since the majority of variables are tested for in the conditional part of an event before executing the declarative part, however, it is more robust to simply put them in the start block, which you know will be called first.
Richard

Registered:
Posts: 104
Reply with quote  #9 
Quote:
Originally Posted by Fish Evans
Try setting it to a value or 0 in the start block with the is interger set.


It works!
And if I had studied a little bit more before asked I would have got to this answer... Sometimes I'm a lazy guy.

Thanks!
Richard

Registered:
Posts: 104
Reply with quote  #10 
Quote:
Originally Posted by ryleyra
it is more robust to simply put them in the start block, which you know will be called first.


Great little piece of advice.

Thanks.
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.