Page 1 of 1

spawning a cargo container with random goods

Posted: Thu Aug 07, 2014 9:50 am
by dertien
Hello all,

I found this line in a script file of an oxp that I have installed, I think it is the falcon and kestrel one.

Code: Select all

this.ship.spawn("explosive_shrapnel", 6);
Instead I would like it to spawn a cargo container with a random content. I just lack the knowledge to write the correct code, or even where to look.

is there a one line way to do this like with the shrapnel ? I have a destroyable cargo bay subentitiy on the Cobra MK 3 that I would like to spawn some cargo when destroyed.
Adding "likely_cargo" to the shipdata.plist entry of the subentity didn't seem to work.

Re: spawning a cargo container with random goods

Posted: Thu Aug 07, 2014 10:28 am
by spara
dertien wrote:
Hello all,

I found this line in a script file of an oxp that I have installed, I think it is the falcon and kestrel one.

Code: Select all

this.ship.spawn("explosive_shrapnel", 6);
Instead I would like it to spawn a cargo container with a random content. I just lack the knowledge to write the correct code, or even where to look.

is there a one line way to do this like with the shrapnel ? I have a destroyable cargo bay subentitiy on the Cobra MK 3 that I would like to spawn some cargo when destroyed.
Adding "likely_cargo" to the shipdata.plist entry of the subentity didn't seem to work.
Do you mean that you want to write a shipscript that has a this.shipDied function containing something like this:

Code: Select all

system.addShips("cargopod", 1, this.ship.position, 0);
Totally untested.

Re: spawning a cargo container with random goods

Posted: Thu Aug 07, 2014 10:47 am
by dertien
Yes something like that, only not when the ship dies, but only when the subentity on that ship does.

Here is the javacript that I used from Eric's version of Griff's Sidewinder with the destroyable entities:

It works great, but I would like to add some funtionality to it:

Code: Select all

this.name      = "hpc_co3_subent"; 
this.author    = "griff"; 
this.copyright = "� 2008 griff."; 
this.version   = "1.01";

this.shipDied = function () 
{ 
    switch(this.ship.primaryRole)
    {
    case "port_cargobay": 
        {
            this.ship.owner.commsMessage("System Destroyed - cargobay");
			this.ship.spawn("explosive_shrapnel", 6);
            break;
        }
		case "starboard_cargobay": 
        {
            this.ship.owner.commsMessage("System Destroyed - cargobay");
			this.ship.spawn("explosive_shrapnel", 6);
            break;
        }
		case "port_dockclamp": 
        {
            this.ship.owner.commsMessage("System Destroyed - dockclamp");
            break;
        }
		case "starboard_dockclamp": 
        {
            this.ship.owner.commsMessage("System Destroyed - dockcklamp");
            break;
        }
		case "port_dockhook": 
        {
            this.ship.owner.commsMessage("System Destroyed - dockinghook");
            break;
        }
		case "starboard_dockhook": 
        {
            this.ship.owner.commsMessage("System Destroyed - dockinghook");
            break;
        }
		case "port_bottomthruster": 
        {
            this.ship.owner.commsMessage("System Destroyed -  bottomthruster PRT");
            break;
        }
		case "starboard_bottomthruster": 
        {
            this.ship.owner.commsMessage("System Destroyed -  bottomthruster STB");
            break;
        }
		case "port_topthruster": 
        {
            this.ship.owner.commsMessage("System Destroyed -  topthruster PRT");
            break;
        }
		case "starboard_topthruster": 
        {
            this.ship.owner.commsMessage("System Destroyed -  a topthruster STB");
            break;
        }
		case "port_wingtip": 
        {
            this.ship.owner.commsMessage("System Destroyed - wingtip");
            break;
        }
		case "starboard_wingtip": 
        {
            this.ship.owner.commsMessage("System Destroyed - wingtip");
            break;
        }
		case "port_shieldgenboxcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - shieldgenbox cover");
            break;
        }
		case "starboard_shieldgenboxcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - shieldgenbox cover");
            break;
        }
		case "fuelscoopcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - scoopcover");
            break;
        }
		case "port_milshieldcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - mil shield cover");
            break;
        }
		case "starboard_milshieldcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - mil shield cover");
            break;
        }
		case "dorsalcover": 
        {
            this.ship.owner.commsMessage("System Destroyed - dorsalcover");
            break;
        }
		case "toruscover": 
        {
            this.ship.owner.commsMessage("System Destroyed - toruscover");
            break;
        }
		case "msllaunchertop": 
        {
            this.ship.owner.commsMessage("System Destroyed - MSL Rack 01");
            break;
        }
		case "msllauncherbottom": 
        {
            this.ship.owner.commsMessage("System Destroyed - MSL Rack 02");
            break;
        }
		case "gundoorastb": 
        {
            this.ship.owner.commsMessage("System Destroyed -  Gunbay Door A STB");
            break;
        }
		case "gundoorbstb": 
        {
            this.ship.owner.commsMessage("System Destroyed -  Gunbay Door B STB");
            break;
        }
		case "gundooraprt": 
        {
            this.ship.owner.commsMessage("System Destroyed -  Gunbay Door A PRT");
            break;
        }
		case "gundoorbprt": 
        {
            this.ship.owner.commsMessage("System Destroyed -  Gunbay Door B PRT");
            break;
        }
		case "pulselaser": 
        {
            this.ship.owner.commsMessage("System Destroyed - PLS LSR");
            break;
        }
		case "beamlaser": 
        {
            this.ship.owner.commsMessage("System Destroyed - BEAM LSR");
            break;
        }
		case "mininglaser": 
        {
            this.ship.owner.commsMessage("System Destroyed - MIN LSR");
            break;
        }
		case "militarylaser": 
        {
            this.ship.owner.commsMessage("System Destroyed - MIL LSR");
            break;
        }
		case "navlightprt": 
        {
            this.ship.owner.commsMessage("System Destroyed - NAV PRT");
            break;
        }
		case "navlightstb": 
        {
            this.ship.owner.commsMessage("System Destroyed - NAV STB");
            break;
        }
		case "floodlightstb": 
        {
            this.ship.owner.commsMessage("System Destroyed - FLOOD STB");
            break;
        }
		case "floodlightprt": 
        {
            this.ship.owner.commsMessage("System Destroyed - FLOOD PRT");
            break;
        }case "toplightprt": 
        {
            this.ship.owner.commsMessage("System Destroyed - FLOOD REAR PRT");
            break;
        }
		case "toplightstb": 
        {
            this.ship.owner.commsMessage("System Destroyed - FLOOD REAR STB");
            break;
        }
		case "lightbottom": 
        {
            this.ship.owner.commsMessage("System Destroyed - FLOOD BTM");
            break;
        }
		/*
	case "griff_krait_extra_eu":
        {
            // npc have no extra_eu, remove booster instead.
            // (Or remove the EQ_SHIELD_ENHANCER)
            this.ship.owner.commsMessage("System Destroyed - enery unit.");
            this.ship.owner.removeEquipment("EQ_SHIELD_BOOSTER");
            break;
        }
    case "griff_krait_fuel_injectors": 
        {
            this.ship.owner.commsMessage("System Destroyed - fuel injector.");
            this.ship.owner.removeEquipment("EQ_FUEL_INJECTION");
            break;
        }
    case "griff_krait_fuel_scoop": 
        {
            this.ship.owner.commsMessage("System Destroyed - fuel scoop.");
            this.ship.owner.removeEquipment("EQ_FUEL_SCOOPS");
            break;
        }
    case "griff_krait_laser": 
        {
            this.ship.owner.commsMessage("System Destroyed - laser.");
            // no need to remove something as this subent realy contains the laser.
            break;
        }
		*/
        default: break
    }
};
The shrapnel at that location does its work, but I don't want to use the shrapnel, just some cargo pods instead. If you have an oxp that demonstrates what you are saying, I will definitely have a look.

I am just trying to copy paste some scripts together, to get full functionality, needless to say that my trial and error way of doing this is very time consuming. I wish my modeling and javascript knowledge were more balanced.

Re: spawning a cargo container with random goods

Posted: Thu Aug 07, 2014 11:09 am
by spara
Ok. If the script already works, then just change "explosive_shrapnel" to "cargopod" and it should do the trick. And if you just want one cargopod, then change that 6 to 1.

Re: spawning a cargo container with random goods

Posted: Thu Aug 07, 2014 11:35 am
by dertien
Halleluja, that worked; thank you Spara.

<thumbs up>