Freedom Reborn Archive

Freedom Force Forums => Scripting Forum => Topic started by: Mystik on July 19, 2007, 03:41:43 PM

Title: Updated Attribute: Driver
Post by: Mystik on July 19, 2007, 03:41:43 PM
check last post
Title: Re: Help plz
Post by: Mystik on July 19, 2007, 05:05:02 PM
sorry meant to post this in the scripting, could a mod possibly move it?
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on July 20, 2007, 06:12:41 PM
no help? :(

well if you cant get driver to work,this attribute works,
just make 2 attributes in ffedit "pilot" and "jet"
copy and paste the script into the ffx file

create a character called ff_cruiser and give it the jet attribute
Title: Re: Scripting Help plz. (pilot attribute)
Post by: catwhowalksbyhimself on July 20, 2007, 06:19:34 PM
Dude, you posted  your original post yesterday.  Chill.  Be patient.  Give someone a chance to actually respond.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on July 20, 2007, 06:45:13 PM
Yeah TR, the guys that are really great at scripting don't get on but a couple times a day, so they probably just haven't seen this yet. :)
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on July 20, 2007, 07:06:30 PM
sorry :oops:
Title: Re: Scripting Help plz. (pilot attribute)
Post by: catwhowalksbyhimself on July 20, 2007, 09:12:58 PM
Sometimes it even takes several days.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on July 20, 2007, 10:34:03 PM
Yep, ha, I often wait for a couple days for answers to EZScript questions, because these fellows are busy. ^_^
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Lunarman on July 21, 2007, 11:32:53 PM
Couldn't you do something akin to the Matrix mod, where moving objects could be controlled by scripting? I'd take a look at that if I were you.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on July 22, 2007, 09:33:43 AM
The basic problem is that Driver/Vehicle is currently very much broken, so any adaptation is an exercise in frustration at this point. Sorry. :(
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on July 22, 2007, 11:12:52 AM
actually my script works, I am able to summon my jet and get in, I just want to adjust the position and movement of my spawned jet

driver works too, there is a line of code that looks like this :

def initdriver(char,update=0):
    #find their vehicle
    template=getVehicle(char)
    name=getFormName()
    FFX_Spawn(name,template,char)
    OnEnterVehicle(name,char)
    Mission_CustomAction('CUSTOM_ENTERVEHICLE',char,name,'OnEnterVehicle',5,0)
    Mission_CustomAction('CUSTOM_EXITVEHICLE',name,name,'OnExitVehicle',5,0)
    Object_SetVar(name,'driver',char)


it should look like this:

def initdriver(char,update=0):
    #find their vehicle
    template=getVehicle(char)
    name=getFormName()
    FFX_Spawn(name,template,char)
    Mission_CustomAction('CUSTOM_ENTERVEHICLE',char,name,'OnEnterVehicle',5,0)
    Mission_CustomAction('CUSTOM_EXITVEHICLE',name,name,'OnExitVehicle',5,0)
    Object_SetVar(name,'driver',char)
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on July 22, 2007, 11:23:37 AM
Hmm....then that may actually be the key to getting the FFX attribute to work, which would be pretty awesome.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Lunarman on July 22, 2007, 11:14:49 PM
Oh yes! Well done Thor.

The problem you're having I'm sure can be solved but the problem you have solved is the big one :)
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Previsionary on July 23, 2007, 01:02:28 AM
couldnt you simply add some code to find the summoner's/pilot's location and then "Object_SpawnAt" to spawn it at the pilot's direct location and finally use a hover code? Just an idea.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on July 24, 2007, 01:39:43 PM
right now I'm working on a rider and bike/horse attribute if I get it work I'll post the script here
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on July 24, 2007, 01:59:22 PM
I'm very interested in these advances, maybe there is hope for the vehicles in DCU after all?
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on July 29, 2007, 12:21:25 PM
well i got the biker rider to half way work, I am able to get my rider to spawn with the bike beside it, then use a custom command to hop on  but I cant my rider to hop off when I my custom exitbite command

def initBike(char,update=0):
    #remove a portrait if there is one
    FFX_AdjustPortrait(char,0)
    Object_SetAttr(char,'heroPoints',Object_GetAttr(char,'heroPoints')-1) #Ep. 2006-08-25: bug patc


def initrider(char,update=0):
    #find their Bike
    template=getBike(char)
    name=getFormName()
    FFX_Spawn(name,template,char)
    Mission_CustomAction('CUSTOM_ENTERBike',char,name,'OnEnterBike',5,0)
    Object_SetVar(name,'rider',char)

def OnEnterBike(target,char):
    #make the Rider dissappear
    Object_SetPrimaryState(char,PCSTATE_EXILE,10000,0)
    Object_SetSecondaryState(char,SCSTATE_INVISIBLE,10000,0)
    Object_SetPrimaryState(target,PCSTATE_EXILE,10000,0)
    Object_SetSecondaryState(target,SCSTATE_INVISIBLE,10000,0)
    #find their BikeRider
    template=getBikeRider(char)
    name2=getFormName()
    FFX_Spawn(name2,template,char)
    FFX_AdjustPortrait(char,0)
    RegTimer('OnEnterBike2',1,0,name2)
    regDeath(name2,'OnBikeDie')
    Mission_CustomAction('CUSTOM_EXITBike',name2,name2,'OnExitBike',5,0)
    Object_SetVar(name,'bike',name2)

def OnEnterBike2(event):
    name2=event.object
    FFX_AdjustPortrait(name2,1)
    Mission_SelectHero(name2)
    AIEnable(name2) ###!Ep 2006-02-12: bug corrected

def OnBikeDie(event):
    Bike=event.object ###!Ep 2006-07-10: Jet wasn't definedz
    Rider=Object_GetVar(Jet,'rider') ###!Ep 2006-07-10: changed char to Jet
    Mission_RemoveCustomAction('CUSTOM_ENTERJet',rider,Jet)
    if FFX_HasPortrait(Jet):
        OnExitJet('',Jet)

def OnExitBike(dummy,char):
    #figure out who our rider is...
    rider=Object_GetVar(char,'rider')
    pos=Get_ObjectPos(char)
    FFX_Teleport(rider,pos)
    alignWith(rider,char)
    Object_SetPrimaryState(rider,PCSTATE_EXILE,0,REMOVE_STATE)
    Object_SetSecondaryState(rider,SCSTATE_INVISIBLE,0,REMOVE_STATE)
    FFX_AdjustPortrait(char,0)
    AIDisable(char)
    RegTimer('OnEnterBike2',0.5,0,rider)
    template=getBike(char)
    name=getFormName()
    FFX_Spawn(name,template,char)
    Mission_CustomAction('CUSTOM_ENTERBike',char,name,'OnEnterBike',5,0)


def getBike(char):
    temp=getByTemplate(char,FFX_BIKER_CUSTOM,1)
    return temp

def getBikeRider(char):
    temp=getByTemplate(char,FFX_BIKER_CUSTOM,2)
    return temp

FFX_BIKER_CUSTOM=[
["default","ff_cruiser","microwave",""],
]





any help would be truly helpful
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on August 11, 2007, 02:34:08 PM
bump

I surprised no one even tested the working driver code
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on August 11, 2007, 05:27:03 PM
Sorry man, I've been pretty busy the last week (not like I'd be any help to begin with, but still).
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Previsionary on August 11, 2007, 06:30:04 PM
It might actually help if you posted some log files (after you tried the attribute of course) so coders and such can actually get an idea about what kind of help to offer.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Zorro on August 11, 2007, 07:21:18 PM
Well, at least this explains why I was never able to get Tony Stark with a Driver attribute into his armor that had the vehicle attribute.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on August 13, 2007, 10:33:11 PM
Quote from: Thor Reborn on August 11, 2007, 02:34:08 PM
bump

I surprised no one even tested the working driver code
I finally did. (Little time and even less energy available for coding recently.) Your workaround works indeed very well, kudos! This fix changes the behaviour Dr Mike had in mind, i.e., only the vehicle appears at the beginning, but it does work (and personally, I might even prefer it working the way you fixed it).

Here's a slightly updated version, which prevents the car from running on its own at the beginning. (Also, the vehicle shouldn't appear on the same exact spot as the hero.)
def initdriver(char,update=0):
    #find their vehicle
    template=getVehicle(char)
    name=getFormName()
    pos=Get_ObjectPos(char)
    pos=(pos[0]+30, pos[1]+30, pos[2])
    cshelper.spawn(name, template, pos)
    alignWith(name, char)
    Mission_CustomAction('CUSTOM_ENTERVEHICLE',char,name,'OnEnterVehicle',5,0)
    Mission_CustomAction('CUSTOM_EXITVEHICLE',name,name,'OnExitVehicle',5,0)
    Object_SetVar(name,'driver',char)
    AIDisable(name)


def OnExitVehicle(dummy,char):
    #figure out who our driver is...
    driver=Object_GetVar(char,'driver')
    pos=Get_ObjectPos(char)
    pos=(pos[0]+20, pos[1]+20, pos[2])
    FFX_Teleport(driver,pos)
    alignWith(driver,char)
    Object_SetPrimaryState(driver,PCSTATE_EXILE,0,REMOVE_STATE)
    Object_SetSecondaryState(driver,SCSTATE_INVISIBLE,0,REMOVE_STATE)
    FFX_AdjustPortrait(char,0)
    AIDisable(char)
    RegTimer('OnEnterVehicle2',0.5,0,driver)
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on August 13, 2007, 11:01:03 PM
Note: I just made a quick test with your pilot code, but probably due to the quick hack I used, I had a few major errors. Since it's very late, I'll call it quit for now. So the only immediate "help" I can provide is asking very basic questions:

Do the attributes create traceback errors in script.log?

Did you try adding print commands (e.g. print "OnEnterBike() step 1") at various points in your code so you could hopefully pinpoint the exact line where things stop working?

P.S.: Maybe a this should be moved to the script forum?
Title: Re: Scripting Help plz. (pilot attribute)
Post by: stumpy on August 13, 2007, 11:21:33 PM
Quote from: Epimethee on August 13, 2007, 11:01:03 PMP.S.: Maybe a this should be moved to the script forum?

Good point. Moved.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on August 14, 2007, 07:25:48 AM
actually I'm still pretty new at this so I dont even know where to view the log files
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Previsionary on August 14, 2007, 07:32:04 AM
Quote from: Thor Reborn on August 14, 2007, 07:25:48 AM
actually I'm still pretty new at this so I dont even know where to view the log files

FF.log and script.log are two text files that are located in the FFVTTR main folder.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: stumpy on August 14, 2007, 07:35:43 AM
Check. See the >stickied topic< (http://freedomreborn.net/archive/index.php?topic=41006.msg572262#msg572262) at the top of the Technical Issues forum for details on this.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on August 16, 2007, 09:23:36 PM
Thor, don't hold your breath (RL getting in the way), but I'm trying to add options to the existing Driver/Vehicle so it might do something like what you want. bump the thread or PM me if I don't get back to you soon enough for your mod work.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on August 17, 2007, 11:50:03 AM
thank you for the effort :thumbup:
well I'm gonna keep my fingers crossed
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on September 19, 2007, 07:55:26 PM
just a bump to see if you had the chance to make any progress
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on September 23, 2007, 08:09:40 PM
Didn't have the time to complete it; RL got in the way, sorry... I also got a bit ambitious. :P

I'll try to see if I can make progress in the next few days
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on October 19, 2007, 10:26:17 PM
just a bump

don't wanna be a nag
Title: Re: Scripting Help plz. (pilot attribute)
Post by: lmalonsof on October 20, 2007, 01:47:12 AM
I'm very interested in this and I'd help you if I could... but I know nothing about python. Eventhough I'll try the script to see what happens.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on October 20, 2007, 06:52:13 AM
Sorry for taking this long. I was stalled by some frustrating bugs. I should have a bit of time this weekend, so I'll get back to work. If the extras features are still buggy, I'll just remove them.
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on October 21, 2007, 08:32:28 PM
Not tested nearly enough, but solved my bug (which were two; same effect, unrelated causes)! Hopefully, it works correctly.  :D

This replaces the previous version of Driver/Vehicle, fixes bugs and adds new bugs, err... I mean, customization options. What's new:

Additional FFX_DRIVER_CUSTOM parameter: interface method
FFX_DRIVER_CUSTOM=[
["default","cat jalopy","","","beside"],
["types","UVehicle 1","UVehicle 2","UVehicle 3","AMethod"],
]
"beside": vehicle appears next to driver
"inside": vehicle replaces driver
"away": vehicle is away and will need to be called; if the vehicle can fly, it will come by air
"spawn": vehicle pops out of thin air when called
You'll need to update your ffxcustom2.py file manually to replace the existing default with the new version; if you already have entered customizations, merge them and add the new interface method. Ex:
FFX_DRIVER_CUSTOM=[
["default","cat jalopy","","","beside"],
["batman","batwing","","","away"],
["types","UVehicle 1","UVehicle 2","UVehicle 3","AMethod"],
]



New FFX_VEHICLE_CUSTOM:
Cargo mass determines the max number of passengers to allow in addition to the driver
FFX_VEHICLE_CUSTOM=[
["default", "500"],
["types", "ACargo (lbs)"],
]

You'll need to update your ffxcustom2.py file manually to add the above code.

In strings.txt, you'll need to add:
CUSTOM_SUMMONVEHICLE_01, call vehicle
CUSTOM_SUMMONVEHICLE_DESC_01, bring your vehicle near you
CUSTOM_UNSUMMONVEHICLE_01, send away
CUSTOM_UNSUMMONVEHICLE_DESC_01, send back your vehicle from where it came
CUSTOM_PASSENGERINVEHICLE_01, enter vehicle
CUSTOM_PASSENGERINVEHICLE_DESC_01, hitch a ride


In ffx.py, under Driver/Vehicle (the working version just above Spellcaster), replace the existing code by the following:
[spoiler]###################### vehicle and driver ##########################
# Dr. Mike's code, with some bugfixes and tweaks by Ep. inspired by Thor Reborn.
# Updated FFX 3.3 alpha
# status: 2.0
# TODO: M25 AI character code (yeah, right).

### Driver / Vehicle customization updated to include more options; this breaks the version in FFX 3.2 - using fallback code for this, though.
# Valid interface method names are "beside", "inside", "spawn" and "away"; set the default to "beside"
# contrarily to Dr Mike's intention, since his Driver demo character CatLaser also has the Utility Belt attribute.
# beside: vehicle appears next to driver
# inside: vehicle replaces driver
# away: vehicle is away and will need to be called
# spawn: vehicle pops out of thin air when called

def initvehicle(char,update=0):
    #remove a portrait if there is one
    FFX_AdjustPortrait(char,0)
    Object_SetAttr(char,'heroPoints', 0) #Ep.: I suppose the idea with this line was to prevent issues with "destroyed" vehicles

def initdriver(char,update=0):
    #find their vehicle
    template=getVehicle(char)
    name=getFormName()
    pos=Get_ObjectPos(char)
    try: #for compatibility with the shorter list format in FFX 3.2
        method = getByTemplate(char, FFX_DRIVER_CUSTOM, 4)
    except:
        method = 'beside'
        print "Driver attribute non-fatal error:"
        print "    '%' is not a valid interface method name, Please update yout FFX_DRIVER_CUSTOM configuration." % method
    if method == 'inside':
        RegTimer('OnSetVehicleInside', 0.5, 0, name)
    elif method == 'beside':
        pos = (pos[0]+30, pos[1]+30, pos[2])
    elif method == 'away':
        RegTimer('OnSetVehicleAway', 2.5, 0, name) #increased delay is necessary to get the vehicle to move all the way
    elif method == 'spawn':
        RegTimer('OnSetVehicleSpawn', 0.5, 0, name)
    else:
        Mission_StatusText('driver attribute error: invalid method %s' % method)
        print 'driver attribute fatal error:'
        print "    '%' is not a valid interface method name" % method
        return
    cshelper.spawn(name, template, pos)
    if (method == 'away') or (method == 'spawn'):
        #vehicle invisibility should kick in immediately
        Object_SetSecondaryState(name, SCSTATE_INVISIBLE, 10000, 0)
    alignWith(name, char)
    Mission_CustomAction('CUSTOM_ENTERVEHICLE',char,name,'OnEnterVehicle',5,0)
    Mission_CustomAction('CUSTOM_EXITVEHICLE',name,name,'OnExitVehicle',5,0)
    Object_SetVar(name,'vehicle_getDriver',char)
    AIDisable(name)


#Ep. 2007-08-16: adds a delay to make OnEnterVehicle() work
def OnSetVehicleInside(event):
    target = event.object
    char = Object_GetVar(target, 'vehicle_getDriver')
    OnEnterVehicle(target, char)


def OnSetVehicleAway(event):
    vehicle = event.object
    driver = Object_GetVar(vehicle, 'vehicle_getDriver')
    Object_SetVar(driver, 'driver_getVehicle', vehicle)
    #vehicle should be invisible when first sent away
    Object_SetSecondaryState(vehicle, SCSTATE_DISPLACE_IMAGE, 10000, 0)
    OnUnsummonVehicleAway(vehicle, driver)

def OnSummonVehicleAway(driver, dummy):
    vehicle = Object_GetVar(driver, 'driver_getVehicle')
    #make the vehicle reappear if needed
    Object_SetSecondaryState(vehicle, SCSTATE_DISPLACE_IMAGE, 0, REMOVE_STATE)
    Object_SetSecondaryState(vehicle, SCSTATE_INVISIBLE, 0, REMOVE_STATE)
    #recall the vehicle
    pos = Get_ObjectPos(driver)
    movementType = m25ai.AIDetermineMoveType(vehicle, "", 10000) #flying vehicles should fly
    Trigger_Move(vehicle, movementType, (pos[0]+30, pos[1]+30, pos[2]+20))
    Mission_CustomAction('CUSTOM_UNSUMMONVEHICLE', driver, vehicle, 'OnUnsummonVehicleAway', 50, 1)

def OnUnsummonVehicleAway(vehicle, driver):
    #make the vehicle go away
    movementType = m25ai.AIDetermineMoveType(vehicle, "", 10000)
    Trigger_Move(vehicle, movementType, getNearestMapSide(vehicle))
    Mission_CustomAction('CUSTOM_SUMMONVEHICLE', driver, driver, 'OnSummonVehicleAway', 1, 1)


def OnSetVehicleSpawn(event):
    vehicle = event.object
    driver = Object_GetVar(vehicle, 'vehicle_getDriver')
    Object_SetVar(driver, 'driver_getVehicle', vehicle)
    OnUnsummonVehicleSpawn(vehicle, driver)

def OnSummonVehicleSpawn(driver, dummy):
    vehicle = Object_GetVar(driver, 'driver_getVehicle')
    pos = Get_ObjectPos(driver)
    pos = (pos[0]+30, pos[1]+30, pos[2])
    FFX_Teleport(vehicle, pos)
    alignWith(vehicle, driver)
    #make the vehicle reappear
    Object_SetPrimaryState(vehicle, PCSTATE_EXILE, 0, REMOVE_STATE)
    Object_SetSecondaryState(vehicle, SCSTATE_INVISIBLE, 0, REMOVE_STATE)
    Mission_CustomAction('CUSTOM_UNSUMMONVEHICLE', driver, vehicle, 'OnUnsummonVehicleSpawn', 5, 1)

def OnUnsummonVehicleSpawn(vehicle, driver):
    #make the vehicle disappear
    Object_SetPrimaryState(vehicle, PCSTATE_EXILE, 10000, 0)
    Object_SetSecondaryState(vehicle, SCSTATE_INVISIBLE, 10000, 0)
    Mission_CustomAction('CUSTOM_SUMMONVEHICLE', driver, driver, 'OnSummonVehicleSpawn', 1, 1)

 
def OnEnterVehicle(vehicle, driver):
    #make the driver disappear
    Object_SetPrimaryState(driver, PCSTATE_EXILE, 10000, 0)
    Object_SetSecondaryState(driver, SCSTATE_INVISIBLE, 10000, 0)
    FFX_AdjustPortrait(driver, 0)
    RegTimer('OnEnterVehicle2', 2, 0, vehicle) #Increased delay to reduce risk of losing control of character
    regDeath(vehicle, 'OnVehicleDie')
    #for passengers; would need to be updated if Driver ever gets M25 AI
    maxMass = float( getByTemplate(vehicle, FFX_VEHICLE_CUSTOM, 1) ) / 2.2
    FFX_ObjectSetAttr(vehicle, 'vehiclePassengerMass', 0)
    for hero in GetAllHeroes():
        if hero not in (driver, vehicle):
            if Object_GetAttr(hero, 'mass') <= maxMass:
                Mission_CustomAction('CUSTOM_PASSENGERINVEHICLE', hero, vehicle, 'OnPassengerEnterVehicle', 5, 0)

#used for both entering (where target is the vehicle) and exiting (where it's the driver)
def OnEnterVehicle2(event):
    target=event.object
    FFX_AdjustPortrait(target,1)
    Mission_SelectHero(target)
    AIEnable(target)


def OnPassengerEnterVehicle(vehicle, passenger):
    if not FFX_HasPortrait(vehicle):
        Mission_StatusText("Wait for the driver!")
        return
    maxMass = float( getByTemplate(vehicle, FFX_VEHICLE_CUSTOM, 1) ) / 2.2
    currentMass = FFX_ObjectGetAttr(vehicle, 'vehiclePassengerMass')
    passengerMass = Object_GetAttr(passenger, 'mass')
    if (currentMass + passengerMass) > maxMass:
        Mission_StatusText("Not enough place left in vehicle!")
        Mission_StatusText("Left: %i  you: %i" % ( (maxMass-currentMass)*2.2, passengerMass*2.2 ))
        return
    FFX_ObjectGetAttr(vehicle, 'vehiclePassengerMass', currentMass + passengerMass)
    #make the passenger disappear
    Object_SetPrimaryState(passenger, PCSTATE_EXILE, 10000, 0)
    Object_SetSecondaryState(passenger, SCSTATE_INVISIBLE, 10000, 0)
    FFX_AdjustPortrait(passenger, 0)
    currentPassengers = missionobjvar.Object_GetVar(vehicle, 'vehicle_getPassengers', {'passenger1': '', 'passenger2': '', 'passenger3': '', })
    nbr = 0
    #simulates an ordered dictionary
    while nbr < 4:
        nbr = nbr + 1
        k = 'passenger%i'%nbr
        if currentPassengers[k] == '':
            currentPassengers[k] = passenger
            break
    missionobjvar.Object_SetVar(vehicle, 'vehicle_getPassengers', currentPassengers)
    Mission_CustomAction('drop %s' % getCharDisplayNameFromDAT(passenger), vehicle, vehicle, 'OnPassenger%iExitVehicle'%nbr, 1, 1)

def OnPassenger1ExitVehicle(vehicle, dummy):
    OnPassengerXExitVehicle(vehicle, 1)

def OnPassenger2ExitVehicle(vehicle, dummy):
    OnPassengerXExitVehicle(vehicle, 2)

def OnPassenger3ExitVehicle(vehicle, dummy):
    OnPassengerXExitVehicle(vehicle, 3)

# find the passenger associated with the custom command and remove it for the dictionary
def OnPassengerXExitVehicle(vehicle, nbr):
    currentPassengers = missionobjvar.Object_GetVar(vehicle, 'vehicle_getPassengers')
    passenger = currentPassengers['passenger%i'%nbr]
    currentPassengers['passenger%i'%nbr] = ''
    missionobjvar.Object_SetVar(vehicle, 'vehicle_getPassengers', currentPassengers)
    OnPassengerExitVehicle(vehicle, passenger)

def OnPassengerExitVehicle(vehicle, passenger):
    currentMass = FFX_ObjectGetAttr(vehicle, 'vehiclePassengerMass')
    passengerMass = Object_GetAttr(passenger, 'mass')
    FFX_ObjectGetAttr(vehicle, 'vehiclePassengerMass', currentMass - passengerMass)
    pos = Get_ObjectPos(vehicle)
    posOffset = (-50, -40, -30, 30, 40, 50)
    pos = (pos[0] + posOffset[randint(0,5)], pos[1] + posOffset[randint(0,3)], pos[2])
    FFX_Teleport(passenger, pos)
    alignWith(passenger, vehicle)
    Object_SetPrimaryState(passenger, PCSTATE_EXILE,0,REMOVE_STATE)
    Object_SetSecondaryState(passenger, SCSTATE_INVISIBLE,0,REMOVE_STATE)
    RegTimer('OnEnterVehicle2', 0.5, 0, passenger)


def OnVehicleDie(event):
    vehicle=event.object
    driver=Object_GetVar(vehicle,'vehicle_getDriver')
    Mission_RemoveCustomAction('CUSTOM_ENTERVEHICLE',driver,vehicle)
    RegTimer('OnVehicleDie2', 0.2, 0, vehicle)
    if FFX_HasPortrait(vehicle):
        OnExitVehicle('',vehicle)

def OnVehicleDie2(event):
    vehicle=event.object
    Trigger_Explosion(vehicle, 'ffx_ex_fire_small')
    Object_PlayEffect(vehicle, 'effect_buildingfire', '', 0, 0, 'centre')


def OnExitVehicle(dummy,vehicle):
    #figure out who our driver is...
    driver = Object_GetVar(vehicle, 'vehicle_getDriver')
    pos = Get_ObjectPos(vehicle)
    pos = (pos[0]+30, pos[1]+30, pos[2])
    FFX_Teleport(driver, pos)
    alignWith(driver, vehicle)
    Object_SetPrimaryState(driver, PCSTATE_EXILE,0,REMOVE_STATE)
    Object_SetSecondaryState(driver, SCSTATE_INVISIBLE,0,REMOVE_STATE)
    FFX_AdjustPortrait(vehicle, 0)
    AIDisable(vehicle)
    RegTimer('OnEnterVehicle2', 0.5, 0, driver)
    #drop all passengers still in vehicle
    currentPassengers = missionobjvar.Object_GetVar(vehicle, 'vehicle_getPassengers', {'passenger1': '', 'passenger2': '', 'passenger3': '', })
    for k in currentPassengers.keys():
        if currentPassengers[k] != '':
            OnPassengerExitVehicle(vehicle, currentPassengers[k])
            currentPassengers[k] = ''
    missionobjvar.Object_SetVar(vehicle, 'vehicle_getPassengers', currentPassengers)
    #remove custom commands from former and would-be passengers - doesn't work?
    for hero in GetAllHeroes():
        Mission_RemoveCustomAction('CUSTOM_PASSENGERINVEHICLE', hero, vehicle)
    for hero in getAllDisabledCharacters(): #not really the list of heroes (disabled don't have portraits), but rather of every disabled char
        Mission_RemoveCustomAction('CUSTOM_PASSENGERINVEHICLE', hero, vehicle) # repeats the for hero in GetAllHeroes() above in case of timing issues
        Mission_RemoveCustomAction('drop %s' % getCharDisplayNameFromDAT(hero), vehicle, vehicle)
    try: #for compatibility with the shorter list format in FFX 3.2
        method = getByTemplate(driver, FFX_DRIVER_CUSTOM, 4)
    except:
        method = 'beside'
    if method == 'spawn':
        Mission_CustomAction('CUSTOM_SUMMONVEHICLE', driver, driver, 'OnSummonVehicleSpawn', 1, 1)
    elif method == 'away':
        Mission_CustomAction('CUSTOM_SUMMONVEHICLE', driver, driver, 'OnSummonVehicleAway', 1, 1)


#Ep. 2006-03-31: Added optional randomisation, using the unused list entries. Inspired by a request by Benton Grey.
def getVehicle(char):
    templates = []
    for i in (1, 2, 3):
        temp = getByTemplate(char, FFX_DRIVER_CUSTOM, i)
        if temp != '':
            templates.append(temp)
    return templates[ randint(0, len(templates)-1) ]


[/spoiler]

Still in ffx.py, you'll need to add the following three utility functions:


# Returns the nearest (in 2D) corner of the map object; this point might or might not be reachable.
# (Note that the SkXMapInfo calipers info isn't used here, as it isn't reliable for interior maps.)
# Z-Axis value is returned, but it shouldn't be relied upon, as we're working from the bounding box's
# dimensions, not actual corners.
# Added FFX 3.3 alpha
def getNearestMapCorner(obj):
    objPos = Get_ObjectPos(obj)
    #datfiles.Mission_GetMapExtents() is more precise but doesn't work for the built-in maps,
    #which are zipped into missions.ff; in this case, use SkXMapInfo instead
    try:
        mapExtents = datfiles.Mission_GetMapExtents()
    except:
        mapExtents = ff.MapInfo['mapExtents']
    mapCorners = [(mapExtents[0], mapExtents[1], mapExtents[5]),
                  (mapExtents[0], mapExtents[4], mapExtents[5]),
                  (mapExtents[3], mapExtents[1], mapExtents[5]),
                  (mapExtents[3], mapExtents[4], mapExtents[5])]
    closest = 10000000
    closestCorner = (0,0,0)
    for c in mapCorners:
        dist = distanceSqPos2D(c, objPos)
        if dist < closest:
            closest = dist
            closestCorner = c
    return closestCorner

# Returns the edge/side position of the map nearest to the object, using getNearestMapCorner();
# cf. notes on this function.
# Added FFX 3.3 alpha
def getNearestMapSide(obj):
    objPos = Get_ObjectPos(obj)
    corner = getNearestMapCorner(obj)
    x = corner[0] - objPos[0]
    y = corner[1] - objPos[1]
    if x > y:
        return (objPos[0], corner[1], corner[2])
    #else:
    return (corner[0], objPos[1], corner[2])

(I suggest putting them between the distanceSqPos2D() function definition and the empty FFQ_LIGHTSOURCES = [] list.)


# New FFX 3.3: find all characters which are exiled and invisible;
# characters which are image displaced and invisble are not returned
# checkLiving: if at 1, k.o.'ed characters won't be returned
# lures: if set to 1, lures will be returned among the characters
# specialCharacters: if set to 0, tiggots, etc., won't be returned
def getAllDisabledCharacters(checkLiving = 1, lures = 0, specialCharacters = 1):
    chars = []
    for object in getAllCharacters(checkLiving, lures, specialCharacters):
        if ( Object_GetSecondaryStates(object) & SCSTATE_INVISIBLE ) and ( Object_GetPrimaryState(object) == PCSTATE_EXILE ):
            chars.append(object)
    return chars

(This one could go between getAllCharacters() and getAllVillains().)

EDIT: removed the FFX_DRIVER/VEHICLE_CUSTOM entries in ffx.py
Title: Re: Scripting Help plz. (pilot attribute)
Post by: lmalonsof on October 22, 2007, 12:07:59 AM
Impressive! I'll test it ASAP!
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on October 22, 2007, 10:25:28 AM
I'm speechless

gonna test right now
Title: Re: Scripting Help plz. (pilot attribute)
Post by: BentonGrey on October 22, 2007, 12:28:00 PM
Ohh.....so freakin' awesome!  I really wish I had the time to put this through its paces.  I'll get to it as soon as I'm able though, and Batman will finally ride in style!
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Mystik on October 22, 2007, 01:20:10 PM
okay  it works but only if I do the customization in the ffx file and not the ffxcustom2
Title: Re: Scripting Help plz. (pilot attribute)
Post by: Epimethee on October 22, 2007, 05:21:58 PM
Quote from: Thor Reborn on October 22, 2007, 01:20:10 PM
okay  it works but only if I do the customization in the ffx file and not the ffxcustom2
Oops. I forgot to remove the FFX_DRIVER_CUSTOM and FFX_VEHICLE_CUSTOM entries in ffx.py itself. Since they were read after the ffxcustom2.py file, they overwrote it.

The above ffx.py has been updated.
Title: Re: Updated Attribute: Driver
Post by: Mystik on October 31, 2007, 09:41:26 AM
just wanted to say thanx again

its so cool to see the batwing just fly in
or have some avengers load a quinjet
Title: Re: Updated Attribute: Driver
Post by: Epimethee on October 31, 2007, 05:40:07 PM
Thanks for the kind words; you just made my day. :)
Title: Re: Updated Attribute: Driver
Post by: BentonGrey on January 05, 2008, 03:23:58 PM
Okay, I finally have a chance to put this through its paces, but I have a couple questions.  First, do we still set up the vehicles as characters?  Second, how do we customize the driver and vehicles?  I see some things in Em's explanation there, but where do I put the multiple vehicle entries for someone like Batman?
Title: Re: Updated Attribute: Driver
Post by: Epimethee on January 05, 2008, 03:46:48 PM
Yes, you still need the vehicle attribute. Multiple vehicles for Bat would be:

FFX_DRIVER_CUSTOM=[
["default","cat jalopy","","","beside"],
["batman","batwing","batmobile","batwhatever","away"],
["types","UVehicle 1","UVehicle 2","UVehicle 3","AMethod"],
]


FFX_VEHICLE_CUSTOM=[
["default", "500"],
["batmobile", "500"],
["batwing", "300"],
["batwhatever", "2000"],
["types", "ACargo (lbs)"],
]

This would randomly spawn either the Batmobile, Batwing or Batwhatever. The vehicle would fly/dry to Batman from the side of the map when calls it. The numbers for cargo mean that there would be place in the B-Wing (...) for one big dude plus negligible additional mass (I'm talking to you, Ray Palmer!); two to three passengers could enter the Batmobile; a bunch could enter the "whatever" vehicle.
Title: Re: Updated Attribute: Driver
Post by: BentonGrey on January 05, 2008, 04:05:08 PM
Thanks Em!  That's a big help, I think I get it all now!