Awardingcargo on ships death

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Awardingcargo on ships death

Post by Rustybolts »

In below code i want to award cargo on death of ship. the code works to the extent of setting mission variable but wont award the cargo. I have tried many different permiatations of doing this but cant get it to work. How do i do this?
Many thanks in advance.

Code: Select all

this.shipDied = function() 
	{
		if (missionVariables.bolts_targetdead == 'TRUE' && mission_bolts == 'STAGE1'){
			player.awardCargo("Gold", 20);
			missionVariables.bolts='STAGE2';
			mission.setInstructionsKey = null;
		}
			if (missionVariables.witness_targetdead == 'TRUE' &&  mission_bolts == 'STAGE5'){
				missionVariables.bolts='STAGE6';
				mission.setInstructionsKey ('bolts5');
			}
		
	}
Last edited by Rustybolts on Sun Aug 16, 2009 1:12 pm, edited 1 time in total.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Code: Select all

player.ship.awardCargo("GOLD",20)
Seems to work. I have always to check it on my own - forgetting the right spelling within a few minutes :-)

btw: You should install Debug.oxp. It's a lot easier to test then.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Svengali wrote:

Code: Select all

player.ship.awardCargo("GOLD",20)
Seems to work. I have always to check it on my own - forgetting the right spelling within a few minutes :-)

btw: You should install Debug.oxp. It's a lot easier to test then.
Thanks but

Code: Select all

this.shipDied = function() 
	{
		if (missionVariables.bolts_targetdead == 'TRUE' && mission_bolts == 'STAGE1'){
			player.ship.awardCargo("GOLD",20);
			missionVariables.bolts='STAGE2';
			mission.setInstructionsKey = null;
		}
			if (missionVariables.witness_targetdead == 'TRUE' &&  mission_bolts == 'STAGE5'){
				missionVariables.bolts='STAGE6';
				mission.setInstructionsKey ('bolts5');
			}
		
	}

Does not seem to work
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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 »

Svengali wrote:

Code: Select all

player.ship.awardCargo("GOLD",20)
Seems to work. I have always to check it on my own - forgetting the right spelling within a few minutes :-)

btw: You should install Debug.oxp. It's a lot easier to test then.

Code: Select all

player.ship.awardCargo("Gold",20)
should also work and is better as it uses the same casing as the on screen tekst. However it must be player.ship, not player. But even without ship it still should work in current oolite. It only leaves a deprication message in the log. In this case I think something else in your code is wrong and that award line is never executed.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Two scenarios :-) Your cargohold is already full or the conditions are not matched.

btw: if mission_bolts is another missionVariable you should use

Code: Select all

missionVariables.bolts
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Svengali wrote:
Two scenarios :-) Your cargohold is already full or the conditions are not matched.

btw: if mission_bolts is another missionVariable you should use

Code: Select all

missionVariables.bolts
Conditions must have been matched as the mission variable bolts = "stage2"
and mission briefing is initiated upon docking at main station. Cargo hold is empty.


You were quite correct my condition can't of been met. I forgot i also updated missionvariable in shipdata.plist slipped my mind.
:oops:
My apologies
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Great that it works now, Rustybolts .-)
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Svengali wrote:
Great that it works now, Rustybolts .-)
Not quite ive got it to work by (but its not instantanious)

Code: Select all

this.tickle = function() 
   { 
      if (missionVariables.target == 'TRUE'){ 
         player.ship.awardCargo("Gold",20); 
         mission.setInstructionsKey = null; 
         missionVariables.target = 'TRUE1'; 
      } 
      if (missionVariables.witness == 'TRUE'){ 
         mission.setInstructionsKey ('bolts5'); 
         missionVariables.witness = 'TRUE1'; 
      } 
       
   }
but i wanted it to run using

Code: Select all

this.shipDied = function() 
   { 
      if (missionVariables.target == 'TRUE'){ 
         player.awardCargo("Gold", 20);  
         mission.setInstructionsKey = null;
         missionVariables.target = 'TRUE1'; 
      } 
    if (missionVariables.witness == 'TRUE'){ 
         mission.setInstructionsKey ('bolts5'); 
         missionVariables.witness = 'TRUE1'; 
      } 
       
   }
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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 »

Rustybolts wrote:
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
No, it is because this.shipDied() only fires when the player dies. To let it fire for that ship, you must give that ship a script of its own. But that death_actions are not executed but must also get handled in shipDied(). And you must check who killed the ship. Look in some oxp's for examples.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Eric Walch wrote:
Rustybolts wrote:
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
No, it is because this.shipDied() only fires when the player dies. To let it fire for that ship, you must give that ship a script of its own. But that death_actions are not executed but must also get handled in shipDied(). And you must check who killed the ship. Look in some oxp's for examples.
TY for clearing this up for me :D
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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 »

Rustybolts wrote:
TY for clearing this up for me :D
For an example look in ups-courier.oxp. and than the upsBoa.js script.

Look at the setInstructionsKey. You use it wrong here. And when not called from within the main script, you must specify the mainscript this instruction belong to.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Originally i thought this.shipDied was an event handler if any ships died. so thanks for clearing that up.
I was unclear after looking at upsBoa.js how oolite knew which ship it was for until i went in shipdata.plist.
So in your shipdata.plist

Code: Select all

"boa3_ptt" = {
        "aft_weapon_type" = "WEAPON_MILITARY_LASER"; 
        "ai_type" = "route1UpsBoaAI.plist"; 
        bounty = 0; 
        exhaust = ("14.75 1.5 -57.5 9.0 9.0 9.0", "-14.75 1.5 -57.5 9.0 9.0 9.0"); 
        "forward_weapon_type" = "WEAPON_BEAM_LASER"; 
        "has_cloaking_device" = "0.33"; 
        "has_ecm" = 1; 
        "has_energy_bomb" = 1; 
        "has_escape_pod" = 1; 
        "has_fuel_injection" = 1; 
        "has_military_scanner_filter" = 1; 
        "has_shield_booster" = "0.75"; 
        "has_shield_enhancer" = "0.75"; 
        "like_ship" = "boa-mk2"; 
        "missile_role" = "EQ_HARDENED_MISSILE"; 
        model = "boa2_ptt.dat"; 
        pilot = eric; 
        roles = "boa_ptt boa_ptt_hard"; 
        "scoop_position" = "0.0 -15.0 -20.0"; 
        script = "upsBoa.js"; 
    };

the last line tells it upsBoa.js is associated with it, is this true?
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
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 »

Rustybolts wrote:
the last line tells it upsBoa.js is associated with it, is this true?
Yes. ship scripts replace the legacy script actions in ship data. When a script is defined none of deach_actions, launch_actions etc is executed. They all have equivalent js handlers.

The beauty of event handlers is of cause their code is only triggered when needed. This in difference to legacy script that evaluates every bit of code, over and over again. The only trick is of cause to create oolite in a way that every important event triggers such an handler.
And part of the "events" in that boa script are triggered by calls from the AI.

Look also at world_script_handlers
This list only contains the handlers that are also used by the player. Meaning the handlers that can be used in the normal world_script. We miss still a wiki page for NPC only handlers. Or even station-only handlers.

Things starting with player are player only, things starting with ship can also be used in ship scripts.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The last line (script = <whatever>.js) associates the given javascript with that particular ship entity. this.shipDied can be used with any ship, not just the player, as long as it's in the script associated with that ship (if it's just in a general worldscript, then it is associated with the player ship).

If you put this.shipDied into the script for a given ship, then it is triggered when that ship dies. If you want an example of this, look at the constrictor in the trunk shipdata.plist and its associates script ("oolite-constrictor.js").

But if you use a script with a ship, then the shipdata.plist actions (setup_actions, death_actions etc) don't fire, as the script supercedes them.

In your case, I would personally associate a script with your ship, and then use that ship and this.shipDied to set your variables and do your assignment of cargo etc.
Last edited by Thargoid on Sun Aug 16, 2009 6:52 pm, edited 1 time in total.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

TY Guys thats crystal unlike the wiki lol
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
Post Reply