How to get infos from destroyed ships?

The place to discuss scripting and game modifications for X³: Reunion.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Tomcat
Posts: 53
Joined: Mon, 22. Dec 03, 05:30
x3tc

How to get infos from destroyed ships?

Post by Tomcat »

When a ship is destroyed, is there an event raised for the ship? If yes which one is it and how would i make a script scanning for those events, so i can record the data i.e. when i killed the ship i want to record the kill for statiscal stuff.
User avatar
Red Spot
Posts: 3461
Joined: Fri, 4. Feb 05, 13:44
x3

Post by Red Spot »

singals killed and captured ..

and I dont think you want a script 'scanning' for those events ..

if you want to 'register' all kills and captures you could make a global variable and when a ship gets killed it gets added to an array stored in the global var .. than make an other script that can read this global .. write it to your log/logfile and clear the global ..

however if you would not clean the global every so often it might affect performance cause it would become huge in time ..



G
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 22437
Joined: Sun, 14. Nov 04, 23:26
x4

Post by Cycrow »

yeah its very easy to attach a script to the killed signal which can then increment a counter
TycHouse
Posts: 488
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by TycHouse »

Use a setup file to make global attatchments

setup.myscript.xml

Code: Select all

001   $done_already = get global variable: name='anyname'
002   if not $done_already
003      $priority = 100
004      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Argon, script='my.signal.killed.handler', prio=$priority
005      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Boron, script='my.signal.killed.handler', prio=$priority
006      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Split, script='my.signal.killed.handler', prio=$priority
007      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Paranid, script='my.signal.killed.handler', prio=$priority
008      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Teladi, script='my.signal.killed.handler', prio=$priority
009      global script map: set: key=SIGNAL_KILLED, class=Ship, race=Pirates, script='my.signal.killed.handler', prio=$priority
010      set global variable: name='anyname' value='done_it'
011   end
012   return null
my.signal.killed.handler.xml

Code: Select all

001   * this script will be run by a ship that is going to die but just prior to the object actually being removed from the universe.
002   $stats = get global variable: name='my.stats.array'
003   if not $stats
004      $stats = array alloc: size=100
005      set global variable: name='my.stats.array' value=$stats
006   end
007   $attacker = [This] -> get attacker
008   $stats[0] = $attacker
009   * any other info you need to get goes here
....
xxx   return null
You will need to write the handler script first so that it can be selected when writing the setup script.
You will need to store the info somewhere, global variables are simple to use but you will need to dream up a way/format to do this. Note there is no need to use another 'set' command, changes made to the $stats variable are now linked directly to the global var 'my.stats.array'

good luck

Edit: line 10 of setup file, you can set any value i've used 'done_it'. Originally had a variable here which was wrong.
Last edited by TycHouse on Wed, 11. Jan 06, 16:56, edited 1 time in total.
AMD FX-8350 Eight-Core 4.0GHz Processor
ASrock Extreme 3 R2.0 Motherboard
8Gb memory
2 x AMD HD7770 Graphics (Crossfire not enabled)
Windows Vista Ultimate 64bit SP2
Tomcat
Posts: 53
Joined: Mon, 22. Dec 03, 05:30
x3tc

Post by Tomcat »

That's a good start, thank you very much. I will try some stuff after getting a rest :D
acrh2
Posts: 734
Joined: Sun, 30. Nov 03, 07:51
x3

Post by acrh2 »

Shouldn't the priority be 10,000?
C2Q 6700 @ 3.50 GHz, OCZ 2x2GB @ 400, EVGA Nforce 680 sli,
EVGA gtx 280 FTW , Mitsu DP 2070SB 22"
X-FI Fatal1ty, Klipsch 5.1 UIltra, Sennheiser HD555
2 x WD Raptor 74 + 2 x 150 GB Raid0, 850W + 430W PS
TycHouse
Posts: 488
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by TycHouse »

acrh2 wrote:Shouldn't the priority be 10,000?
No, script priority 99 is used for the 'fight' (as in self defence) therefore 100 would be more than enough.
AMD FX-8350 Eight-Core 4.0GHz Processor
ASrock Extreme 3 R2.0 Motherboard
8Gb memory
2 x AMD HD7770 Graphics (Crossfire not enabled)
Windows Vista Ultimate 64bit SP2
acrh2
Posts: 734
Joined: Sun, 30. Nov 03, 07:51
x3

Post by acrh2 »

TycHouse wrote:
acrh2 wrote:Shouldn't the priority be 10,000?
No, script priority 99 is used for the 'fight' (as in self defence) therefore 100 would be more than enough.
I don't know. I'm just going by what MSCI Handbook says, and it says 10,000.
C2Q 6700 @ 3.50 GHz, OCZ 2x2GB @ 400, EVGA Nforce 680 sli,
EVGA gtx 280 FTW , Mitsu DP 2070SB 22"
X-FI Fatal1ty, Klipsch 5.1 UIltra, Sennheiser HD555
2 x WD Raptor 74 + 2 x 150 GB Raid0, 850W + 430W PS
Tomcat
Posts: 53
Joined: Mon, 22. Dec 03, 05:30
x3tc

Post by Tomcat »

I just tried to get it to work, i used your example scripts. I only expanded the setup script (do i need to run it manually or is it run whenever i load a game?) with xenon and khaak races. I changed the handler script so that whenever it is called it sends me an incoming message, i know that could cause spam, lol, but it's only for testing if it works.

Well, it doesn't work yet, i will try with a higher priority.
AalaarDB
Posts: 2282
Joined: Thu, 29. Jan 04, 08:19
x3tc

Post by AalaarDB »

It's bad form to intercept signals for ships that you haven't created. What happens when someone wants to run 2 scripts that both intercept it?
TycHouse
Posts: 488
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by TycHouse »

The setup script is run automatically when you load your game and simply attatches your handler script to that event. Obviously once you've coded the scripts you will need to reload your game so that the event has been attatched.
I've never tried this sort of thing with an incoming message, for now you could just try writing to logbook to see if it works.
Don't forget in my example the class it is attatched to is simply 'Ships' you may want to be more specific ie Small Ships or Movable Ships.
AMD FX-8350 Eight-Core 4.0GHz Processor
ASrock Extreme 3 R2.0 Motherboard
8Gb memory
2 x AMD HD7770 Graphics (Crossfire not enabled)
Windows Vista Ultimate 64bit SP2
TycHouse
Posts: 488
Joined: Wed, 6. Nov 02, 20:31
x3tc

Post by TycHouse »

acrh2 wrote:Shouldn't the priority be 10,000?
According to the MSCI handbook page 35 you are correct, convention appears to be 10,000 for a killed event. Given that all other scripts will have terminated and the next thing to happen is the removal of the object priority of 0 would do the job as the priority is simply to make sure that 'this' script is executed and with a priority of 0 being the only script on the stack it would be, however i will bow to convention and thank arch2 to pointing it out :)
AMD FX-8350 Eight-Core 4.0GHz Processor
ASrock Extreme 3 R2.0 Motherboard
8Gb memory
2 x AMD HD7770 Graphics (Crossfire not enabled)
Windows Vista Ultimate 64bit SP2

Return to “X³: Reunion - Scripts and Modding”