Author Topic: Script Name from Target: Request for assistance  (Read 750 times)

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Script Name from Target: Request for assistance
« on: December 24, 2019, 09:56:50 PM »
I am having trouble figuring out how to grab the script filename from pTarget. Anyone have any ideas? I looked in App.py but could not really find what I'm looking for..

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Script Name from Target: Request for assistance
« Reply #1 on: December 25, 2019, 08:31:34 AM »
If pTarget is already casted to ShipClass, you can call
Code: [Select]
pTarget.GetScript()
This returns the relative path and name of the ship-script as a string. E.g.,
Quote
ships.BirdOfPrey

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #2 on: December 25, 2019, 11:28:34 AM »
I don't think that is going to work in this case, because the file calls for example: Model = "Name" and not Model = pTarget.GetScript()

I did try the GetScript but I think I forgot to cast the shipclass, so I will try that. Basically trying to change PodModel of the AbandonShip mod from a static value to dynamic value based upon pTarget script "Name" so that the name inserted matches the name of whatever ship is being targeted

It's probably going to be something much simpler, like calling the shipFile or abbrev attribute of the pTarget scripts.Custom.Ships.ShipName.py and getting thats string inserted into the "Name" location...

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Script Name from Target: Request for assistance
« Reply #3 on: December 25, 2019, 12:44:34 PM »
Something like that already exists:
https://www.gamefront.com/games/bridge-commander/file/escape-pods-varied

With that mod, the escape pods used are determined by the (foundation)Race of the ship, or an Ftech field in the ship's plugin.

It's pretty great and also adds additional escape pods.  :)

Edit:
You could take a look at the LibQBautostart file, specifically the GetShipType function.

Oh, also:
Happy Christmas  :D

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #4 on: December 25, 2019, 07:06:16 PM »
Thanks I will check that out, Happy Holidays also

Just had a look at the files and I think this is not what I am looking for. What I would be looking for would be to launch a pods in variation from a single ship, dependent upon pTarget ship type. I'm not sure I understand how loadpacehelper.CreateShip works as there are some variables in the () that I cannot successfully make any change to. I suppose I will be looking into loadspacehelper.

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #5 on: December 26, 2019, 12:17:39 PM »
I suppose a last resort fix would be to if statement every ship model in the game and if there is a match to one of them, load that model in. I can see that being at least 100 if statements in a single def, which is absolutely tragic but the only idea I can come up with at present, since I cant particularly figure out how to add ship model without first comparing it to the target ship model. Gonna take a good day to get those if statements written, but I do think its possible. I will first test a single if statement for a specific model, I have had some success changing the PodModel file "name" but no success getting it to read the file name from pTarget.

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #6 on: December 26, 2019, 05:02:52 PM »
Alternatively, I think I could go about it by updating all ship hardpoints .SetModelFilename("name") and then grab that text by using .GetModelFilename() and try inserting it into the PodModel code.

I just tried this and I did have some success, testing it like this:

Code: [Select]
sShipName = "USSCentury"
PodModel = (sShipName) # default "EscapePod"
Which seemed to work so long as I can keep the information within the ""

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Script Name from Target: Request for assistance
« Reply #7 on: December 27, 2019, 10:16:33 AM »
I still don't seem to understand what exactly you want to do:

Do you want to alter the escape pod used base on the targeted (enemy) ship,
or do you want to change the display name of the created escape pod based on the targeted ship,
or something else entirely?

If it is the first, I'd suggest to do that via an FTech field in the ships plugin, similar to what the linked mod does.
If it is the second, the loadspacehelper method you mentioned has the "pcIdentifier" argument for that:
Code: [Select]
###############################################################################
# CreateShip
#
# Creates a new ship.
#
# Args: pcScript - the ship's script file
# pSet - the set in which to place this ship.  If NULL, it's not placed in a set.  Careful with this..
# pcIdentifier - the name for this ship
# pcLocationName - the name of the initial location for this ship
# iWarpFlash - whether or not to create a warp flash for this
#   ship.
# bGrabPreloaded - True if this should grab ships from the mission's
#   cache of precreated ships (if possible).  False if not.
#   Only the mission should pass 0 for this, when it's
#   first creating its precreated ships.
#
# Return: ShipClass * - the newly-created ship
###############################################################################
def CreateShip(pcScript, pSet, pcIdentifier, pcLocationName, iWarpFlash = 0, bGrabPreloaded = 1):

That can be used with pTarget's GetName or GetDisplayName functions. (IIRC at least one of those exists).

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #8 on: December 27, 2019, 01:03:48 PM »
It is neither of those, I am trying to bypass the escape pod altogether and spawn a brand new ship model based on the ship model of pTarget. So we have pTarget locked and we press our button, what should happen is my ship should change into a duplicate of pTarget.

pcIdentifier I believe only changes the in game display name. I have successfully made changes to pcIdentifier to fix display names when escape pods are launched based on player id (it used to not update your display name, old ship named "Player"). I am trying to alter the pcScript used, which would be the first arg of CreateShip, however I can't seem to find out where to grab the necessary text from, or what set of commands to grab the text for me and insert it into display text...

PodModel = "modelname" is what I need to change dynamically based on pTarget, which would be the pcScript

Thought: Perhaps I can create the text necessary as a global and assign the podname that way...

UPDATE: It appears that TargetCast will work for what I want to do, but the code will be significantly longer because I have to check AND double check ALL ships rather than grabbing the model name from text... I will play around with this, but I have successfully changed my ship into the target ship. Now I need to go about loading in the old hardpoint to the new ship model...

Code: [Select]
# clear AI, this ship is abandoned (can we not do this yet? just in case we fail... idk)
pShip.ClearAI()

# (Holo-emitter checklist)
# Akira
if (pTargetCast.GetScript() == "ships.Akira"):
loadspacehelper.PreloadShip("Akira", CreateShipsNum)
# StartAbandonShip(pShip)

# USS Century
if (pTargetCast.GetScript() == "ships.USSCentury"):
loadspacehelper.PreloadShip("USSCentury", CreateShipsNum)
# StartAbandonShip(pShip)
else:
return

Code: [Select]
# Create the Pod (Holo-emitter checklist)

# Akira
if (pTargetCast.GetScript() == "ships.Akira"):
AS_EscapePod = loadspacehelper.CreateShip("Akira", pSet, PodName, PodLaunchPoint)
# else:
# return

# USS Century
if (pTargetCast.GetScript() == "ships.USSCentury"):
AS_EscapePod = loadspacehelper.CreateShip("USSCentury", pSet, PodName, PodLaunchPoint)
# else:
# return
# AS_EscapePod = loadspacehelper.CreateShip("USSCentury", pSet, PodName, PodLaunchPoint)

# Disable Collisions
AS_EscapePod.EnableCollisionsWith(pShip, 0)
AS_EscapePod.DisableCollisionDamage(1)

Offline KrrKs

  • Posts: 461
  • Cookies: 25
Re: Script Name from Target: Request for assistance
« Reply #9 on: December 27, 2019, 03:51:41 PM »
So, why don't you use the GetShipType function from LibQBautostart?
That basically returns exactly what you'd want to use there. I.e., the name of the ship file in scripts/ships -without the relative path information.

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Script Name from Target: Request for assistance
« Reply #10 on: December 27, 2019, 04:56:48 PM »
It was really that easy? I had tried before, but that was also before I used TargetCast.. using TargetCast I am able to now use GetShipType. Working very well so far, going to do more tests. I suppose casting is very important, I will keep it in mind in the future. I feel like we are making good progress here :)