Hi A_C, I've been testing the modded build you sent me. Sorry about the delay in getting back to you, had quite a bit of RL stuff to do last week!
I've put the Java Scripts I've used at the end of this post and also put the post on the Scripters Cover thread.
I'm using both thisBeingAttacked and thisShipDied. These are the results:-
thisShipDied on the new build works perfectly. It records who killed, however the ship died. Even if the player hit the ship with an e-bomb / missile / q-bomb "whom" is recorded as the player rather than the e-bomb / missile / q-bomb. Even if the death is caused by the player ramming the ship, the killer is still recorded as the player. It also works for recording a kill by an NPC even if the NPC used a missile.
thisBeingAttacked does not work quite as well. It regards a laser blast as an attack, but does not record a missile / e-bomb / q-mine or collison as an attack. If the ship is killed by these means the variable remains undefined. For 1.1 of Random Hits I'll use the thisBeingAttacked to test the killer. It works as well as thisShipDied because I'm reseting the variable every time the ship is hit. It therefore records the last ship to shoot the target before its death (which is the same as who killed it). I then use the undefined status to test for a e-bomb / q-mine kill.
One oddity on both build has been touched on by Eric above. The game will not read a Java Script attached to the
second ship to be added with the spawn command. It
always reads a script attached to a ship if the ship has been added with addSystemShips. On the death of the target ship (on a dice role) I spawn his pod. This works fine the first time by the second time (in the same game session) I spawn a ship, I get this error log:-
Code: Select all
2008-01-26 12:24:10.703 oolite.exe[600] [js.test.died]: RandomHits.OXP Pod Killed by [Player "Naval Imperial Courier" ID: 100 position: (-6063.97, 4209.98, 7157.24) scanClass: CLASS_PLAYER status: STATUS_IN_FLIGHT]. Command does not work on 1.70 or lower so I detect who killed him by using the last ship to shoot at the Pod before it died!
2008-01-26 12:25:05.593 oolite.exe[600] [script.debug.onOff]: SCRIPT debug messages ON
2008-01-26 12:25:05.609 oolite.exe[600] [script.debug.onOff]: SCRIPT debug messages OFF
2008-01-26 12:25:27.171 oolite.exe[600] [js.test.died]: RandomHits.OXP Pod Killed by [Player "Naval Imperial Courier" ID: 100 position: (10840.9, -4442.25, 4578.56) scanClass: CLASS_PLAYER status: STATUS_IN_FLIGHT]. Command does not work on 1.70 or lower so I detect who killed him by using the last ship to shoot at the Pod before it died!
2008-01-26 12:25:27.343 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: missionVariables is not defined
2008-01-26 12:25:27.343 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 9.
2008-01-26 12:25:46.718 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:46.718 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 30.
2008-01-26 12:25:46.875 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:46.875 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 30.
2008-01-26 12:25:47.015 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:47.015 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 30.
2008-01-26 12:25:47.156 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:47.156 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 30.
2008-01-26 12:25:47.296 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:47.296 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 30.
2008-01-26 12:25:47.421 oolite.exe[600] [script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: player is not defined
2008-01-26 12:25:47.421 oolite.exe[600] [script.javaScript.exception.1]: AddOns/RandomHits251.oxp/Scripts/oolite-random-hits-pod1.js, line 15.
2008-01-26 12:25:50.906 oolite.exe[600] [unclassified.MyOpenGLView]: Found mode {Height = 768; RefreshRate = 0; Width = 1024; }
2008-01-26 12:25:51.906 oolite.exe[600] [gameController.exitApp]: .GNUstepDefaults synchronized. Exiting.
On the first kill the pod's scipt worked fine. For testing I'm adding a victim ship by the w/s beacon on every Jump. When I jump and kill the ship for the second time. The SHIP's script works fine (as it was added with addShips), but as the pod is spawned, the SECOND time its spawned the error comes up. If I save and restart Oolite however then the next ship spawned works fine. It looks like you can only SPAWN (as opposed to ADD) one ship with a JS attached in the same game session.
In play this won't matter too much, as it would only arrise if the player took a random hits mission AND the mark podded AND he then took another one AND killed the next victim AND the second victim also podded. As long as the player took a break and restarted Oolite after completing the first mission then there would be no problem. Still odd though. Other than that though the JS and "who" seem to be working fine.
This is the Script for the Target Ship:-
Code: Select all
this.name = "oolite-random-hits-mark2";
this.author = "LittleBear";
this.copyright = "2008 - But do what you like with it in your OXPs!";
this.description = "Tests who killed a RandomHits OXP Victim Ship and how they did it. The main script acts on the setting of variables."
this.version = "1.1";
this.shipDied = function(whom)
{
LogWithClass("js.test.died", "RandomHits.OXP Pod Killed by " + whom +". Command does not work on 1.70 or lower so I detect who killed him by using the last ship to shoot at the Pod before it died!");
if(Math.random() < 0.99) // Role the Dice to see if the Victim made it to his Pod.
{
missionVariables.random_hits_status = "PODED" // Victim made it to his Pod! Set the variable to reflect that the player still needs to kill or scoop the Pod!
system.legacy_spawn("random_hits_pod3", 1); // Spawn a Pod. Any shooting or scooping of the Pod is handled by the Pod's own Script.
delete this.shipDied
}
else
{
missionVariables.random_hits_status = "KILLED" // Victim died with his ship. Set the variable to reflect this.
system.legacy_spawn("random_hits_qbomb", 1); // Spawn a Q-Mine which taunts the player before exploding! Nasty!
delete this.shipDied
}
}
this.beingAttacked = function(whom)
{
if(whom == player)
{
missionVariables.random_hits_whoshot = "PLAYER_ATTACK" // Shooter was the player not using an e-bomb, q-mine or cloak. The variable remains undefined if the player e-bombs, q-mines or kills the victim whilst cloaked as thisBeingAttacked does not get run. The main script then awards the player the credit for the kill, but fines him for dishonerable conduct!
delete this.beingAttacked
}
else
{
missionVariables.random_hits_whoshot = "NPC_ATTACK" // Shooter was NPC ship. Every time the victim is hit, the variable is reset. Once he's dead the variable is not longer reset. So the last ship to hit him was also the killer!
delete this.beingAttacked
}
}
This is the script for the Target Ship's Pod:-
Code: Select all
this.name = "oolite-random-hits-pod1";
this.author = "LittleBear";
this.copyright = "2008 - But do what you like with it in your OXPs!";
this.description = "Tests who killed or scooped a RandomHits OXP Escape Pod carring the mission target and how they did it. The main script acts on the setting of variables."
this.version = "1.1";
this.shipSpawned = function ()
{
missionVariables.random_hits_store_showship = "random_hits_pod1" // The ship the victim is flying is shown on mission briefing screens. So I switch the ship to a Pod as he's now abandoned ship.
delete this.shipSpawned
}
this.shipDied = function(whom)
{
if(whom == player)
{
missionVariables.random_hits_status = "KILLED" // Record the fact that the Pod has died! If whom worked on this.ShipDied I'd set the variable directly here to COMPLETE.
delete this.shipDied
}
else
{
missionVariables.random_hits_status = "KILLED" // Record the fact that the Pod has died! If whom worked on this.ShipDied I'd set the variable directly here to NPCKILL.
delete this.shipDied
}
}
this.beingAttacked = function(whom)
{
if(whom == player)
{
missionVariables.random_hits_whoshot = "PLAYER_ATTACK" // Shooter was the player not using an e-bomb, q-mine or cloak. The variable remains undefined if the player e-bombs, q-mines or kills the victim whilst cloaked as thisBeingAttacked does not get run. The main script then awards the player the credit for the kill, but fines him for dishonerable conduct!
delete this.beingAttacked
}
else
{
missionVariables.random_hits_whoshot = "NPC_ATTACK" // Shooter was NPC ship. Every time the victim is hit, the variable is reset. Once he's dead the variable is not longer reset. So the last ship to hit him was also the killer!
delete this.beingAttacked
}
}
this.shipWasScooped = function(scooper)
{
if (scooper == player)
{
missionVariables.random_hits_whoscooped = "PLAYER" // Scooper was the player.
delete this.shipWasScooped
}
else
{
missionVariables.random_hits_whoscooped = "NPC" // Scooper was an NPC.
delete this.shipWasScooped
}
}