Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Scripting requests

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

User avatar
Thargoid
Thargoid
Thargoid
Posts: 5526
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The problem was more if two OXPs mark one system and then one of them unmarks it again, the marks from both are removed hence the other OXP thinks the system is marked but it isn't any longer.

The different colours etc though could be a nice extension to the proposal.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5526
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Can we have some way of suppressing or denying docking requests?

Just tweaking TCAT a bit more, as one thing that has been noted is that you can auto-dock (shift-C) with them and also request docking clearance (shift-L). The former can just about be worked around (thanks A_C) with a bit of fudging, but the latter still responds and looks odd in this case.

Some way to make hostile or alien stations/carriers not accept docking or clearance requests would be nice please.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

I'd like to renew a scripting request that wasn't yet granted in 1.74:

A new event handler (world and ship scripts) as complement of shipBeingAttacked, which is sent to the attacked ship. The new handler should at the same time be sent to the attacker, with a parameter containing the entity that was hit. Should work for lasers and probably for plasma balls as well.

Syntax could be shipHittingOther(other), or possibly shipTargetHit(target) or shipTargetAttacked(target). However, at least the player can also hit something without having targetted it first, and NPCs can at least miss their target and hit something else instead, therefore a syntax containing "Target" could be misleading.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Script actions required please.

Post by Killer Wolf »

right, got my new station working, so i now need scripty bits (or/and advice) on how to get it working how i want.

- i've got 2 types of craft i want to defend the station : i gather i use the "defense ship" option, but is it possible to define more than one ship like this?

- is there a way to control how these ships launch? i've noticed when shooting a Cori, the police can be very slow and sparse in appearing, i want a fast launch of a lot of craft. ideally also, i'd like one type of ship to be launched for say every 10 of the the other type.

- being a piratey type thingy, is it possible to control how the station/ships react to the player : i'd like the station/ships to be docile if the player is carrying Food or whatever, but aggressive if they're not.

- regarding the station itself, i want it somewhere around (say w/in 20km) on the wichpoint, entrace oriented towards the sun ~ how'd i do that?

- i want them to appear in say 25% of systems w/ a tech level of 7+, but how do i script it so that it picks the same systems each time the script runs, ie not have one TL7 picked one time, then not the next time you jump in?

think that's about it, cheers
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Script actions required please.

Post by Eric Walch »

Killer Wolf wrote:
right, got my new station working, so i now need scripty bits (or/and advice) on how to get it working how i want.

- i've got 2 types of craft i want to defend the station : i gather i use the "defense ship" option, but is it possible to define more than one ship like this?

- is there a way to control how these ships launch? i've noticed when shooting a Cori, the police can be very slow and sparse in appearing, i want a fast launch of a lot of craft. ideally also, i'd like one type of ship to be launched for say every 10 of the the other type.
Use defense_ship_role instead of defense_ship. And with the role you can set the weight factor for each individually ship.
- being a piratey type thingy, is it possible to control how the station/ships react to the player : i'd like the station/ships to be docile if the player is carrying Food or whatever, but aggressive if they're not.
Should be possible with 1.74. But you need to add a JS script that evaluates if the player has certain commodities on board.
- regarding the station itself, i want it somewhere around (say w/in 20km) on the wichpoint, entrace oriented towards the sun ~ how'd i do that?
For the orientation part, put the following in the js script for the station:

Code: Select all

this.shipSpawned = function ()
{
    var targetVector = system.sun.position.subtract(this.ship.position).direction();
    var angle = this.ship.heading.angleTo(targetVector);
    var cross = this.ship.heading.cross(targetVector).direction();
    // align the heading to the targetVector 
    this.ship.orientation = this.ship.orientation.rotate(cross, -angle);

    system.legacy_addShipsAtPrecisely("myBuoy", 1, "abs", this.ship.position.add(this.ship.heading.multiply(10E3)));
    delete this.shipSpawned;
}
As bonus I added a line that also puts a buoy in front of the dock when you want. (Or delete that line if not wanted)
- i want them to appear in say 25% of systems w/ a tech level of 7+, but how do i script it so that it picks the same systems each time the script runs, ie not have one TL7 picked one time, then not the next time you jump in?
Use one of the pseudoRandom numbers. They are not really random as they are the same for each individual system.

Hope it helps, cheers
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

many thanks Eric, i'll have a play w/ that stuff. never thought about a bout but that's just given me a little idea for something to try.

BTW, that pseudo number :
" pseudoRandomNumber

pseudoRandomNumber : Number (read-only)

A random number between 0 and 1 that is always the same for a given system. "

should that not be "between 0 and NUMBER" (ie, so you can have varying degrees of randomicity)? or is it just a standard decimal fraction to however many places?
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Killer Wolf wrote:
should that not be "between 0 and NUMBER" (ie, so you can have varying degrees of randomicity)? or is it just a standard decimal fraction to however many places?
Decimal fraction between 0.0000000000000 and 1 (actually 0.99999999999999999999 come to think of it). If you want something between 0 and NUMBER(arbitrary number) you can build it fairly easily with pseudoRandomNumber...

Code: Select all

myPseudoRandom = function (NUMBER){
     return Math.floor((NUMBER+1)* System.pseudoRandomNumber);
}
the function above will return an integer between 0 and NUMBER inclusive.

If you want to be more adventurous, however, you can use the flexibility that decimal fractions give you to create this other pseudo random number function:

Code: Select all

myNewPseudoRandom = function (fromNumber, toNumber){
     return fromNumber + (toNumber-fromNumber) * System.pseudoRandomNumber;
}
with this second functon you get all sort of more interesting options, as can be seen from this js console log :):

> this.myNewPseudoRandom = function (fromNumber, toNumber){
return fromNumber + (toNumber-fromNumber) * System.pseudoRandomNumber;
}

> this.myNewPseudoRandom (-1.5,1.5)
-0.8556272983551025
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

As discussed at length starting here, using the pseudoRandomNumber (or any other stable property) directly to determine a spawning probability is a Bad Idea, because it will cause clustering of things spawned by different OXPs.

My suggested solution is here. It will give a different stable-per-system number for each “salt” value, with no very obvious relationship between them.

In fact, I’m going to add a version of that code to 1.75.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

ta much for the code : i've now got the station to generate, and my ships as defense craft. the prob of apathy still remains tho : i fire at the station, go red alaert, and after 30~60 seconds, a craft appears, maybe another a good while later : i want a swarm of craft to pile out almost immediately ~ is this possible?
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

KW: yep! Your station needs to have a js script, and you need to use the alertConditionChanged event.

In there you can check that the alert level changed to red & if so you can make the station send out a bunch of extra defenders using one of the new launch commands:

Code: Select all

this.ship.launchDefenseShip();
as always, the wiki is your friend...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

mint, thanks Kaks, i'll play w/ that when i get home.

As an aside, that says it launches all defense ships w/ a given role, which is exactly what i want, but i wonder if it sh/could be expanded to launch them in waves too? say you have 30 defense ships : you could specify a wave amount, say 10, and ten would launch, and when they were killed the next 10 would launch etc etc.
User avatar
JazHaz
---- E L I T E ----
---- E L I T E ----
Posts: 2991
Joined: Tue Sep 22, 2009 11:07 am
Location: Enfield, Middlesex
Contact:

Post by JazHaz »

Killer Wolf wrote:
As an aside, that says it launches all defense ships w/ a given role, which is exactly what i want, but i wonder if it sh/could be expanded to launch them in waves too? say you have 30 defense ships : you could specify a wave amount, say 10, and ten would launch, and when they were killed the next 10 would launch etc etc.
Possibly launching all ships in a role means that you can't do waves, but possibly you could have all police ships launch first, and followed by bounty hunters in a second wave? Failing that, it might be worth looking at the code for Random Hits, as that does something similar.
JazHaz

Gimi wrote:
drew wrote:
£4,500 though! :shock: <Faints>
Cheers,
Drew.
Maybe you could start a Kickstarter Campaign to found your £4500 pledge. 8)
Thanks to Gimi, I got an eBook in my inbox tonight (31st May 2014 - Release of Elite Reclamation)!
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2268
Joined: Tue Jan 02, 2007 12:38 pm

Post by Killer Wolf »

well i misread that, it only launches one ship :-(

i've got this script, one of Thargoid's that i butchered amateurishly :

this.alertConditionChanged = function(newCondition, oldCondition)
{
switch(newCondition)
{
case 0: // we're docked
case 1: // we're at green alert
case 2: // or we're at yellow alert
{
break;
}
case 3: // we're at red alert
{
this.ship.launchDefenseShip();
}
}
}


can someone tell me how to stick in a "repeat...until" type thing there (or better alternative) cos i'm thinking i can put in a bit that repeats teh launch until dockedDefenders = 0 .

cheers!
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Code: Select all

this.alertConditionChanged = function(newCondition, oldCondition)
{
    function startTimer()
    {
        if (!this.launchDefenseShipTimer && this.ship.dockedDefenders > 0)
        {
            this.launchDefenseShipTimer = new Timer(this, function()
            {
                this.ship.launchDefenseShip();
                if (this.ship.dockedDefenders == 0)  stopTimer();
            },
            0, 5);  // Every five seconds, starting immediately
        }
    }
    
    function stopTimer()
    {
        if (this.launchDefenseShipTimer)
        {
            this.launchDefenseShipTimer.stop();
            delete this.launchDefenseShipTimer;
        }
    }
    
    if (newCondition == 3)
    {
        // Red alert.
        startTimer();
    }
    else
    {
        // Not red alert.
        stopTimer();
    }
}
(None of that testing luxury, of course.)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5526
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

The problem you will still have is that the launch sequence I think has some built-in gaps between ship launches anyway, so the station won't just spit out ships in a string. At least that's my experience of this kind of thing.

Depending on how you want to do it, it is possible to have the station launch an entity which upon launch spawns several ships and then puts them into the station's group etc. They aren't really defense ships as such, but something like that may be more what you're looking for. Although that is a little more complicated to code.
Post Reply