Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
Xavier Wise

Registered:
Posts: 981
Reply with quote  #1 
A bit of background:

A major problem I have had in the mission script is destroying ships that have been created with randomly generated names (V45, F71, X81 etc). There isn't a "Destroy all ships" command in the mission scripting XML commands. If a GM spawned multiple ships, and then wanted to clear them all, they would have to click on each individual ship and delete them one at a time. It caused even bigger issues in things I was trying to make like the Pirate mode and Patrol modes as there was no GM to delete the ships. Every single ship had to be created with a specific name, then have individual destroy commands in them. 

It took me a while to think of the solution, and really it is only the new scripting code that has allowed me to fix the problem. It uses a quirk of the new ability recall variables in comms messages using the |variableName| line. I had to share it with you guys because I know that it is a problem others have had too.

All you have to have is a way to set the variable "destroy" to 2. This could be a GM key/ button press, or added into an event (in the case of the TSN Sandbox, this would be the transition code for when ships move from one sector to the next).

Here is the code:

 

Code:

<start id_arme="1cafe167-aaa5-4989-a9ed-414bb4afe47b">
<set_variable name="firstnumber" value="0.0" integer="yes" />
<set_variable name="secondnumber" value="0.0" integer="yes" />
</start>


<folder_arme name="Cycle Numbers" id_arme="5ff67968-452f-4702-895f-9a15861dc425" />

<event name="Destroy" id_arme="333b0618-72d1-4339-95e6-049cf263ba71" parent_id_arme="5ff67968-452f-4702-895f-9a15861dc425">
<if_variable name="destroy" comparator="EQUALS" value="2.0" />
<destroy name="A|firstnumber||secondnumber|" />
<destroy name="B|firstnumber||secondnumber|" />
<destroy name="C|firstnumber||secondnumber|" />
<destroy name="D|firstnumber||secondnumber|" />
<destroy name="E|firstnumber||secondnumber|" />
<destroy name="F|firstnumber||secondnumber|" />
<destroy name="G|firstnumber||secondnumber|" />
<destroy name="H|firstnumber||secondnumber|" />
<destroy name="I|firstnumber||secondnumber|" />
<destroy name="J|firstnumber||secondnumber|" />
<destroy name="K|firstnumber||secondnumber|" />
<destroy name="L|firstnumber||secondnumber|" />
<destroy name="M|firstnumber||secondnumber|" />
<destroy name="N|firstnumber||secondnumber|" />
<destroy name="O|firstnumber||secondnumber|" />
<destroy name="P|firstnumber||secondnumber|" />
<destroy name="Q|firstnumber||secondnumber|" />
<destroy name="R|firstnumber||secondnumber|" />
<destroy name="S|firstnumber||secondnumber|" />
<destroy name="T|firstnumber||secondnumber|" />
<destroy name="U|firstnumber||secondnumber|" />
<destroy name="V|firstnumber||secondnumber|" />
<destroy name="W|firstnumber||secondnumber|" />
<destroy name="X|firstnumber||secondnumber|" />
<destroy name="Y|firstnumber||secondnumber|" />
<destroy name="Z|firstnumber||secondnumber|" />
<set_variable name="destroy" value="1.0" />
</event>

<event name="Increase 1st Number" id_arme="6f9a0e4e-f122-4326-a94d-f9d8b6d8da62" parent_id_arme="5ff67968-452f-4702-895f-9a15861dc425">
<if_variable name="destroy" comparator="EQUALS" value="1.0" />
<if_variable name="firstnumber" comparator="LESS" value="10.0" />
<set_variable name="firstnumber" value="firstnumber+1" integer="yes" />
<set_variable name="destroy" value="2.0" integer="yes" />
</event>

<event name="Increase 2nd Number" id_arme="6d702ff3-42f1-48db-94fe-16ede1b8a22e" parent_id_arme="5ff67968-452f-4702-895f-9a15861dc425">
<if_variable name="destroy" comparator="EQUALS" value="1.0" />
<if_variable name="firstnumber" comparator="EQUALS" value="10.0" />
<if_variable name="secondnumber" comparator="LESS" value="10.0" />
<set_variable name="firstnumber" value="-1" integer="yes" />
<set_variable name="secondnumber" value="secondnumber+1" integer="yes" />
</event>

<event name="Reset Numbers" id_arme="32321099-b290-4e19-8e3a-61e57e6ded99" parent_id_arme="5ff67968-452f-4702-895f-9a15861dc425">
<if_variable name="destroy" comparator="EQUALS" value="1.0" />
<if_variable name="secondnumber" comparator="EQUALS" value="10.0" />
<if_variable name="firstnumber" comparator="EQUALS" value="10.0" />
<set_variable name="firstnumber" value="0.0" integer="yes" />
<set_variable name="secondnumber" value="0.0" integer="yes" />
<set_variable name="destroy" value="0.0" integer="yes" />
</event>


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

Registered:
Posts: 2,439
Reply with quote  #2 
That is awesome. I had thought of doing something like this to generate random names, but didn't think about using it to select random names -- or in this case ALL random names. Thanks for taking the time to think this up and test it out. I think I will end up adding it to my Module_3_bases script.

I'll add that if you limit yourself to numbers between 10 and 99, you should be able to use a single variable instead of one for each of the individual digits. Of course, you have to deal with 00 and 09, which will convert to "0" through "9" when you try to use them in the name property, and won't match the object. But you could use a double digit variable to create a random object name.

EDIT: In case you missed my post on the topic earlier, I found that if you want a variable to be an integer, you should declare it in the start block. That way it won't be declared as a float later because you used it in an if_variable statement. Your variable "destroy" doesn't have to be an integer, but that would be my choice, just to save memory.

Xavier Wise

Registered:
Posts: 981
Reply with quote  #3 
I have been talking over how to use this to assign AI to groups of ships when spawned, to give particular characteristics to certain factions/fleets (there are a few different alien races in the TSN mod) and not have the standard enemy AI brainstack assigned to any new ship created and have to override that manually, one-by-one. Based on my discussion with FishEvans, I think I have pretty much got the idea figured out. It is just a matter of coding it and testing.
__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
ryleyra

Registered:
Posts: 2,439
Reply with quote  #4 

I wonder if it wouldn't be simpler to just generate a random name, and then use that to assign all applicable properties and AI commands. You could use an additional variable to choose the initial letter. And if you limit the list of used letters, you wouldn't have to include every one from A to Z. Just a thought.

It's too bad you can't detect when an enemy ship is scanned, or you could assign them an "X" for unknown, and then another letter once they're identified. [biggrin]

Xavier Wise

Registered:
Posts: 981
Reply with quote  #5 
You could do that, but then you'd end up cycling through every possible name and assigning AI to them. It would mean you have every currently spawned ship with the new AI.

What I was thinking was create a set of new ships (say three pirates) all with the name --. Assign AI to the first ship with that name, for example to predominantly go after neutral ships, and then rename the ship to a random name. Repeat the process until all ships are renamed and you're done.

For other enemy types or behaviours, you'd just alter which commands are given. So a fleet of Kraliens could be given AI to attack bases only.

__________________
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  #6 
That's really cool, Xavier!

Have you noticed that anything else gets destroyed? By that I mean anomalies and black holes are named objects, too, even though those names don't show on the science screen.

__________________
"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  #7 
Quote:
Originally Posted by Xavier Wise
You could do that, but then you'd end up cycling through every possible name and assigning AI to them. It would mean you have every currently spawned ship with the new AI.


No, if you randomly generate a name, you can then use it until you're done with it and generate a new one.

For example:

<event name="Generate Name" />
    <if_variable name="generate_name" comparator="EQUALS" value="1" />
    <set_variable name="letter" randomIntLow="1" randomIntHigh="5" />
    <set_variable name="digits" randomIntLow="10" randomIntHigh="99" />
    <set_variable name="generate_name" value="2" />
</event>
<event name="Create Ship V" />
    <if_variable name="generate_name" comparator="EQUALS" value="2" />
    <if_variable name="letter" comparator="EQUALS" value="1" />
    <create type="enemy" use_gm_position="yes" name="V|digits|" raceKeys="Kralien enemy standard" hullKeys="Cruiser small" />
    <clear_ai name="V|digits|" />
    <add_ai name="V|digits|" type="CHASE_PLAYER" />
    <set_variable name="generate_name" value="0" />
</event>
<event name="Create Ship W" />
    <if_variable name="generate_name" comparator="EQUALS" value="2" />
    <if_variable name="letter" comparator="EQUALS" value="2" />
    <create type="enemy" use_gm_position="yes" name="V|digits|" raceKeys="Kralien enemy standard" hullKeys="Cruiser small" />
    <clear_ai name="W|digits|" />
    <add_ai name="W|digits|" type="CHASE_PLAYER" />
    <set_variable name="generate_name" value="0" />
</event>

... and so on for X through Z. If you need to assign properties in a second event, then start a timer and use letter and digits again when the timer expires. You just have to make sure you don't generate another name until the timer is done.

Unfortunately there is no way to reassign a named object to a in-game randomly assigned name. But the above is almost as good.

ryleyra

Registered:
Posts: 2,439
Reply with quote  #8 
Quote:
Originally Posted by Mike Substelny
That's really cool, Xavier!

Have you noticed that anything else gets destroyed? By that I mean anomalies and black holes are named objects, too, even though those names don't show on the science screen.


I'm not really sure what anomalies and black holes are named if they aren't given a name at creation time. I suppose this could be used to test that theory though. The only other thing I can think of is they are named "Anomaly xx" or "Black Hole xx" or some such.

Enemy bases are named "Enemy Station x", IIRC, where x is a sequential number starting at 1, just like allied bases.

Monsters I suppose are all named the same, after their type. (The name "ZZ" being displayed until they are scanned)

Xavier Wise

Registered:
Posts: 981
Reply with quote  #9 
Just a quick note, after implementing this in to the TSN Sandbox, I needed to change one of the integer values to -1. I have updated this in the code above.
__________________
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  #10 
Below is the link to the post in which I create random names and assign a particular AI to a new enemy fleet.

Post - Code: Create Random Names


__________________
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  #11 
What a elegant solution!

But I have a question: is this faster and consume less CPU resources than a mass kill code based on sheer force (a bunch of "destroy" with every possible combination)?
Xavier Wise

Registered:
Posts: 981
Reply with quote  #12 
It does take time for all named ships to be destroyed as every digit must be cycled through. At some point I am going to improve this code to make it quicker and more efficient.

As for a mass kill code, I did consider that but quite honestly didn't fancy having to write it all. You'd need  destroy command for A00 - Z99, which works out to be 2600 destroy commands (100 per letter x 26 letters of the alphabet). It is possible to save time by copying and then replacing the first letter though. It would also be interesting to see if it worked in game.

__________________
Captain Xavier Wise TSN Raven (BC-014)
Link to TSN RP Community website
Link to TSN Sandbox
Link to Blog
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.