| Config/script.js | this.name           = "tracker_worldScript.js";
this.author         = "Thargoid";
this.copyright      = "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description    = "World script for the tracker OXP";
this.version        = "1.00";
"use strict";
this.compassTargetChanged = function(whom, mode) {
    if (player.ship.equipmentStatus("EQ_TRACKER") !== "EQUIPMENT_OK" || 
        player.ship.equipmentStatus("EQ_ADVANCED_COMPASS") !== "EQUIPMENT_OK") 
        return; 
    
    if (mode && mode === "COMPASS_MODE_BEACONS" && whom && whom.name === "Tracker")
        if(whom.target) { 
            player.consoleMessage("Tracked entity - " + whom.target.displayName, 5); 
        }
}
    
this.equipmentDamaged = function(equipment) {
    var _taggedShips, i;
    if (equipment === "EQ_TRACKER" || 
       (equipment === "EQ_ADVANCED_COMPASS" && player.ship.equipmentStatus("EQ_TRACKER") === "EQUIPMENT_OK")) {
        _taggedShips = system.shipsWithRole("tracker_beacon");
        i = _taggedShips.length;
        while (i--)
            _taggedShips[i].remove();
    }
}    
 | 
                
                    | Scripts/tracker_beacon.js | "use strict";
this.name        = "tracker_beacon.js";
this.author      = "Thargoid";
this.copyright   = "CC BY-NC-SA 3.0";
this.description = "Beacon script.";
this.version     = "1.04";
this.$tracked;
this.$trackedName;
//
// Event Handlers
//
//--------------------------------------------------------------------------------------------//
this.shipSpawned = function _shipSpawned() { 
    if (!this.ship || !this.ship.isValid || !this.ship.target) {
        log(this.name, "Incomplete tracker beacon:"+this.ship+(this.ship ? ", "+this.ship.isValid+", "+this.ship.target : ""));
        return;
    }
    log(this.name, "Tracker for "+this.ship.target.displayName+" spawned, adding collision exception and setting up beacon label");
    this.ship.addCollisionException(this.ship.target);
    this.$tracked = this.ship.target;
    this.$trackedName= this.ship.target.displayName;
    this.ship.beaconCode = "Tracker: "+this.$trackedName;
    this.ship.beaconLabel = "Tracker: "+this.$trackedName;
    this.callbackID = addFrameCallback(this.repositionTracker.bind(this)); 
}
//--------------------------------------------------------------------------------------------//
this.shipWillEnterWitchspace = function _shipWillEnterWitchspace() {
    log(this.name, "Tracker for " + this.$trackedName + " entering wormhole");
}
//--------------------------------------------------------------------------------------------//
this.shipDied = function _shipDied(whom, why) { 
    if (why && why === "scrape damage" && whom && this.ship && this.$tracked && whom === this.$tracked) {
        // in cases where the tag does manage to collide with the tracked entity, respawn the tag.
        var Tag = this.ship.spawnOne("tracker_beacon");
        Tag.target = this.$tracked;
        log(this.name, "Tracker for "+this.$trackedName+" collided with ship and was destroyed, creating a new one");
    } else {
        log(this.name, "Tracker for "+this.$trackedName+" was destroyed by '"+whom+"' with '"+why+"'");
    }
}
//
// Internal Functions
//
//--------------------------------------------------------------------------------------------//
this.repositionTracker = function _repositionTracker() {
    if (!this.ship || !this.ship.isValid || !this.$tracked || !this.$tracked.isValid) {
        // something has gone wrong
        if (this.ship && this.ship.isValid)
            // tracker is OK, but the tracked ship is not
            log(this.name, this.$trackedName+" is no more, removing tracker (tracker target:"+this.ship.target+")");
        else if (this.ship)
            // tracker exists but is not valid anymore
            log(this.name, "Tracker for "+this.$trackedName+" is not valid anymore, removing");
        else
            // tracker does not exist anymore but this FCB is still being called
            log(this.name, "Tracker undefined:"+this.ship+", tracked:"+this.$trackedName);
        if (this.callbackID) {
            removeFrameCallback(this.callbackID);
            delete this.callbackID;
        }
        this.ship.remove();
        return;
    }
        
    this.ship.position = this.$tracked.position
}
    
 | 
                
                    | Scripts/tracker_trigger.js | "use strict";
this.name        = "tracker_trigger.js";
this.author      = "Thargoid";
this.copyright   = "CC BY-NC-SA 3.0";
this.description = "Script for setting up the tracker";
this.version     = "1.05";
//-----------------------------------------------------------------------------//
this.activated = function() {
    var _ship = player.ship;
    if (!_ship) return
    if  (!_ship.target) {
        player.commsMessage("No target to track.", 8)
        return;
    }   
    if (_ship.target.dataKey === "telescopemarker") {
        player.commsMessage("Target beyond range to attach/recall tracker.", 8)
        return;
    }
    var _target = _ship.target;
    var _tagArray = system.shipsWithPrimaryRole("tracker_beacon", _target, _target.collisionRadius) 
    // check if the target is already tagged - if so then activation is to remove it
    if (_tagArray.length > 0) {
        log(this.name,"Removing tracker from "+_tagArray[0].target);
        _tagArray[0].remove();
        player.commsMessage("Tracker called back from "+_target.displayName+".", 8);
        return;
    }
    
    if (system.countShipsWithPrimaryRole("tracker_beacon") > 4) {// if there are already 5 active tags in the system
        player.commsMessage("No trackers available.", 8);
        log(this.name, "Already tracking 5 ships:"+system.shipsWithPrimaryRole("tracker_beacon"));
        return;
    }
    
    // if we get this far, we're setting up tracking on the target
    var Tag = _target.spawnOne("tracker_beacon");
    if (!Tag)
        log(this.name, "Couldn't spawn tracker beacon for "+_target.displayName);
    else {
        Tag.target = _target;
        log(this.name, "Created tracker for "+_target.displayName+":"+Tag);
        player.commsMessage("Tracker attached to "+_target.displayName+".", 8);
    }
}
 |