Problem with roles

General discussion for players of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
Ironfist
Commander
Commander
Posts: 218
Joined: Tue Jun 28, 2011 2:16 pm
Location: London

Problem with roles

Post by Ironfist »

Guys,

Having problems with roles. A bit of background trying to script some actions for a ship building station and would like to recognise player ships that correspond to the ship types that are built at the station, so that differing actions can be provided. Whilst I can do this by using constructs like "if (player.ship.name === "xxx" !! player.ship.name === "yyy") I thought it would be easier on maintenance if I could assign a special role and use " if (player.ship.hasrole("rrr") ". However when I try this it fails, It would appear that the only role a player ship has is 'player', is this correct? NPC ships have the full list of roles when I list them in the console, but the player only ever shows 1 role, 'player'. The Wiki does not say anything about this restriction for the player ship, well in those pages I have read anyway.

Ironfist
64bit Mint 10 and Win 8 64bit on E8400 at 3.6GHz - ATI HD5750 graphics.
Concentration is the ability to think of absolutely nothing when it is absolutely necessary.
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

Re: Problem with roles

Post by Kaks »

Unfortunately it's done on purpose. The reason behind it is that NPCs tend to develop erratic behaviours if we add secondary roles to the player (specifically police & thargoid, but maybe pirate as well).


However, there is one thing you could do. Each player ship can be assigned a unique script in shipdata.plist, so you can create a ship.script containing at least the following

Code: Select all

this.name = 'testing';
this.author = 'Ironfist';
   ....
this.ironfistBuildStation = 'YAY';
you can then always check for

Code: Select all

if(player.ship.script.ironfistBuildStation == 'YAY'){
     ...
}
'Course, since it's not a standard property, it's always best to give it a fairly unique name, so no other oxps are likely to use the same property by accident...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Ironfist
Commander
Commander
Posts: 218
Joined: Tue Jun 28, 2011 2:16 pm
Location: London

Re: Problem with roles

Post by Ironfist »

Kaks,

Thanks for the suggestion I will give it a go and see whether if it offers any advantages over what I am currently doing, which is to have a piece of equipment called "Manufacturers Tag" which is standard equipment for ships produced by Oodulldoff Inc. Testing this allows the station scripts to react differently for differing ships and currently does not require writing a ship script for each type of ship. But your option may be better since I assume the equipment approach could fail if it was destroyed in combat.

Ironfist
64bit Mint 10 and Win 8 64bit on E8400 at 3.6GHz - ATI HD5750 graphics.
Concentration is the ability to think of absolutely nothing when it is absolutely necessary.
Post Reply