this.shipDied not working well

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

this.shipDied not working well

Post by Eric Walch »

I created a very simple death-actions schript.

Code: Select all

this.name      = "ups-ship-killed"; 
this.author    = "eric walch"; 
this.copyright = "© 2008 the Oolite team.";
this.description = "testscript for killing detection";
this.version   = "1.01"; 

this.shipDied = function() 
{ 
    player.commsMessage("I'll be back with help for revenge!!", 5);
}
This I attach to a test ship. Then I spawn several ships around the station with the debugMenu.

When I kill them, all scripts from ships spawn after the first, generate errors in the log about the first line after "this.shipDied = function()". In this case it is "player is not defined". But when I add a log function it says "Log not defined"

However, the script does works with the first spawn ship, even if it is killed after the others that generated errors, showing that the script by itself is OK and implemented at the right way.
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Should also add (as posted on the Scripters Cove thread), that when a function (whom) is added, whom seems to always to remain undefined, regardless of whether the kill was by the player or an NPC.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Had a look at the code regarding the whom situation and the answer could not be simpler than this: whom with ships other than the player does not work because there is no code to handle it. In the getDestroyedBy method, in ShipEntity.m, there is this:

Code: Select all

 
- (void) getDestroyedBy:(Entity *)whom context:(NSString *)context
{
	suppressExplosion = NO;		// Can only be set in death handler
	// TODO: send didBecomeDead(whom, context) script event here
	[self becomeExplosion];
}
I have added code in the trunk that broadcasts the shipDied event (didBecomeDead was the old name used), but I have a few reservations about it. LittleBear, maybe if I send you a modified 1.70 with this fix applied, you will be able to test your script and let me know if it works for you?
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Cool! If you e-mail me it I'll give it a test. I don't know how to build anything though, so it'd have to be as a replacement exe (or with some instructions! :wink: ). I've pretty much squoshed all the bugs in V.10, but would really need the whom to simplfy the whole thing.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

LB,

For the time being you can also fall back on: this.beingAttacked = function(whom). that one is already working. I tried the code below and it is working. (Only the first ship with me)

Code: Select all

this.beingAttacked = function(whom)
{ 
    player.commsMessage("Help we are being attacked by scripttesters!!", 5);
    if(whom == player) 
    {
	player.commsMessage("Hello player, whom is player", 5);
    }
}
Not just as good, but it at least detects if the played was among the attackers. Than it is just the issue of only the first ship that works. Do you have the same problem? Even when I spawn a ship, dock, load a new game and spawn again a new ship, the shipDied of the second ship is not working. The same is happening with this.beingAttacked. In both cases he complains the second time that player is not defined.

Or am I doing something wrong here?
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

LB, check your mail.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Addition to the bug. I always added the ships with debug menu. Now I added them with a script near the station on launching:
addSystemShips: testship 3 0.99

All three ship scripts were working. I killed them, re-launched so three new ones were added and those tree scripts also worked.

So the problem is in the command that added the ships. Probably normal ship adding scripts do work. But the purpose of debug menu was testing of ships and scripts of those ships should also work.
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Zip seems corrupted unfortunatley. Could you try another go? Eric's find of the this.beingAttacked should do equally well though for random hits.

I am cheating a bit, but any ship that attacks the mark gets its AI set to a harmlessAI that makes it run away. Once the mark is out of scanner range the ship reverts to its normal AI. This is necessary as otherwise victims in boyracers etc invariable fall to cops before the player finds them. This (obviously) has no effect on the player, but it means no NPC can fire more than one shot at the mark. It is still possible for a mark to be killed by an NPC (if one of Matts Navy Ships opens up with all guns for example - but I'm not too bothered if once in a blue moon the player has a wasted trip!). If I put an else condition to set the who fired to variable NPC, then the variable will only be PLAYERFIRED if the player was the last ship to shoot him before he died. :D

If I just set the status to KILLED with death_action. Then have status = KILLED, whofired = PLAYER do = This was a player kill. status = KILLED, whofired oneof NPC / undefined do = This was an NPC kill.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

LB wrote:
Eric's find of the this.beingAttacked should do equally well though for random hits.
For normal dogfight, yes. But you'll miss those occasions when a NPC ships weakens your mark and the player kills him by ramming or hitting him with a missile. But I think those will be rare and in general it will be good enough for the purpose you want to use it in Random hits (And for my ups boa mission)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

LB, your postmaster has returned 4 attempts to re-email you the file back to me. Please, download it from this address if you can:
http://terrastorage.ath.cx/Marmagka/iQT ... homFix.zip
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

Thanks that one worked fine!

EDIT. Done a script that used both methods (isbeingAttacked and shipDied). Tested the isbeingAttacked (see scripters cove). Will test the shipDied using the new build and report in.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
Post Reply