[Solved] Scripting questions (vehicle related stuff)

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

[Solved] Scripting questions (vehicle related stuff)

Post by Locutus »

Hey guys,

I've started working on some scripts for the Battlefront Pegasus projects but ran into a couple of issues I'm stuck with.

1) [SOLVED]
In Battlefront Pegasus you have the possibility to control big frigate ships flying through space by entering a certain turret. Since the frigates are too big to land anywhere I've added a secondary weapon which activation is monitored by the script. If it's shot the player will be teleported back into the capital ship.
Since the teleporting can be a bit glitchy (due to the exit velocity the player enters the capital with a very high speed which looks bad) I want to force the player into a turret which then can be left the regular way. Unfortunately the EnterVehicle() command only works with vehicles (as opposed to OnCharacterEnterVehicle() which works for turrets, too).
To deal with this, I've used regular flyer code and replaced the mesh with a turret. When a human enters this fake turret he will be teleported into the frigate before he can take off. So far so good.
The problem: The AI tends to fly away with the turrets... Is there a command to lock certain vehicles for the AI?
I know that the fake console uses a command to lock vehicles but I don't know how the necessary code would look like and if it could be restricted to AI only.



2) [SOLVED]
In order to get the frigates shooting without being controlled by a player I'm forcing AIs into them (pilottype = vehicleself crashes MP).
First, the script goes through all units on the field, (tries to) check if they are available (they are unavailable when currently in a turret or vehicle) and forces the first unit in, that's available. If there is no unit available I wait until the next one spawns.
The problem: I don't know how to check if the AI is available.

Code: Select all

[...]
pilot_is_in_vehicle = GetCharacterVehicle(pilot)
if pilot and not IsCharacterHuman(pilot) and not ship_manned_wrt_destroyer_1 and pilot_is_in_vehicle == nil then
   --[stuff]
end
The code above doesn't work the way I hoped and I don't know how else I can test whether a bot is in a vehicle or not.[/color]


3) [SOLVED]
Is there any special requirement to get vehicle collision work for turrets?
They can be shot and everything but you can fly right through them.
Hidden/Spoiler:
Image



4) Lastly, the map still suffers a severe issue caused by flyer suicide after they finish following a spline, see viewtopic.php?f=27&t=30280&p=505082#p505082
If you got any ideas or want to try sth. please respond. If you need any source files please ask.

Sorry for the wall of text.
Any help greatly appreciated:)
Last edited by Locutus on Sun Sep 28, 2014 8:20 pm, edited 3 times in total.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Scripting questions (vehicle related stuff)

Post by Maveritchell »

Trying to parse your first issue - basically, you've got large vehicles floating in space (outside a landing region) that you want to have players be able to enter. Since they never land, you need to use some other mechanism to get players in there. So far, you've used remote turrets as that mechanism.

However, I'm not understanding why you need a lua weapon to remove the players from the vehicles. I'd like to hear a little more about the first issue (which is ultimately related to the second and third issues, because the first issue is causing you to try to fit a square peg into a round hole).

As for the last issue, isn't the obvious solution to extend the flyer splines so that they take the ships following them outside instead of just to the exit?
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Scripting questions (vehicle related stuff)

Post by Locutus »

Thanks for the response, Mav!:)
You got the first issue mostly right - just I'm not using any remote vehicle. The AI tends to leave them causing the flyers to explode mid-air... (an unpiloted remote flyer not in a landed state will always explode) and I wouldn't be able to enter non-idle fighters.
On the map, when you enter a certain chair (turret), you get teleported into the vehicle (via script command). When you want to leave the vehicle at some point (that's what the secondary "weapon" is for - it seems to me the only possibility for the player to signal he wants out) I'd like the player to be back into the chair he entered to get into the vehicle.


Regarding the fourth issue: That's exactly what I did (and it's working at least so much to prevent the suicides) but it makes the AI behave even more dumb. I can never let the flyers leave the spline, no matter where on the map, they'll always go suicide.
For now, I've given them a big variance for each axis and they fire towards the enemy if one is directly in front of them but ... dogfighting looks different :/
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Scripting questions (vehicle related stuff)

Post by Maveritchell »

What you may want to do is step back and address the one problem you have with remote vehicles (AI leaving them) instead of trading that for several problems with the workaround solution. Maybe an AI team with no goals to prevent leaving? Maybe different placement of the chairs?

If you're stuck on using vehicles and swapping people around with script, then the easy solution is to have a vehicle on both ends - make your "chair" a vehicle and use EnterVehicle - I've made tons of stuff vehicles to hack around things (see: Rebel Ops and "cameras"), and that's easy to work with.

And as for your last issue, it's hard to say what might be the problem with your spline setup without seeing the whole map. However, try a couple of things:
1) Make sure you've got a node of a path nearby that you'd like the AI to follow. Once the AI reaches the end of a path, they want to keep flying, and they need something to follow.
2) Try using the "SingleDirection" parameter on your exit paths. I can't remember if this is deprecated, but it's designed for this kind of thing.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Scripting questions (vehicle related stuff)

Post by Locutus »

Remote flyers are not an option, I've spent hours with this already. Besides the AI leaving, you cannot enter (AI controlled) ships that are already flying around because they will explode before you can enter.
Having frigates "parked" for player usage isn't really an option either.

The current system works considerably well and I'm only having issues with the high-velocity teleport back and the unsafe bot check.
As I stated in my first post, making the chair a vehicle is exactly what I'm trying to do. The issue, as said before, is that the AI keeps using these vehicles to move around. I've tried changing the vehicles speed and turn rate to zero but that kept crashing the game for me.
Do you have an odf example of a non-movable vehicle for me to study?



Thanks for the spline tips, I'll keep playing around with them.
(SingleDirection works but even when used together with BranchDifferent it seemingly doesn't help on forcing the flyers not to use a certain path anymore.)
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Scripting questions (vehicle related stuff)

Post by Maveritchell »

Sure, here's an .odf I used. It's a "dummy" vehicle (which means it's invisible and invincible), and you'll obviously have to modify it a little for your own use:
Hidden/Spoiler:
[code]
[GameObjectClass]
ClassLabel = "flyer"
GeometryName = "ffx_weap_inf_grenadethermal.msh"

[Properties]
WaterEffect = "com_sfx_waterwake_sm"

FLYERSECTION = "BODY"
VehicleType = "light"



MapTexture = "alpha_icon"
HealthTexture = ""
MapScale = 1.5

HealthTexture = ""

ForceMode = 2

ExplosionName = "ffx_weap_null_exp"
GeometryName = "bgl_weap_inf_dropturret"
CollisionScale = "1.5"
CollisionThreshold = "5"
//FirstPerson = "imp\impspbk;imp_1st_cockpit_speederbike"
VehiclePosition = "common.vehiclepositions.pilot"

TakeoffTime = "1"
TakeoffSpeed = "10"
LandingTime = "1"
LandingSpeed = "10"
TakeoffHeight = "0.1"

PilotPosition = "hp_active"
Pilot9Pose = "speederbike_9pose"

MaxHealth = 999999.0
AddHealth = 50000.0

TimeRequiredToEject = "1.0"
EjectResistance = "0.01"
TimeTilReboard = "5.0"

//HitLocation = "p_crithit 0"



EnergyBar = "0"
EnergyAutoRestore = "7.5"
EnergyBoostDrain = "20"
EnergyTrickDrainSingleTap = "0"
EnergyTrickDrainDoubleTap = "0"
FirstPersonFOV = "52"
CockpitTension = "22"

PitchRate = 1.25
PitchFilter = 6.0
PitchFilterDecel = 6.0
PitchBuildupMultiplier = 1.0
TurnRate = 1.0
TurnFilter = 6.0
TurnFilterDecel = 6.0
TurnBuildupMultiplier = 1.0

BankAngle = "0.8"
BankFilter = "3.5"
LevelFilter = "1.5"
LevelFilterLanding = "5"
RollRate = "3.15"
PCPitchRate = "15"
PCSpinRate = "15"
PCTurnRate = "25"

TiltValue = "5"

AimTension = "20.0"

MoveTensionX = "0.1"
MoveTensionY = "0.1 0.1"
MoveTensionZ = "0.1"

BlurEffect = "0.9"
BlurStart = "40"
FOVEffect3rd = "90"
FOVEffect1st = "90"
Acceleraton = "40"
MinSpeed = "35"
MidSpeed = "70"
MaxSpeed = "95"
BoostAcceleration = "80"
BoostSpeed = "150"
TrickRollSpeed = "6"
TrickFlipSpeed = "6"
TrickSideRollStrafeSpeed = "30"
TrickFlipCameraDetach = "0.24"
TrickSideRollCameraDetach = "0.48"



EyePointOffset = "0.0 0.0 0.0"
TrackOffset = "0.0 0.0 0.0"
TrackCenter = "0.0 0.0 0.0"

FOVEFFectMinCamOffset3rd = "0.0 0.0 0.0"
FOVEFFectMaxCamOffset3rd = "0.0 0.0 0.0"



VOUnitType = 55
EngineSound = ""
TakeoffSound = ""
LandSound = ""
HurtSound = ""
DeathSound = ""
VehicleCollisionSound = ""
TurnOnSound = ""
TurnOffSound = ""
TurningOffSound = ""
TurnOffTime = "1.5"
ImpMusic = ""
AllMusic = ""
CisMusic = ""
MusicSpeed = ""
MusicDelay = ""
AfterburnerOnSound = ""
AfterburnerOffSound = ""
AfterburnerSpeed = ""
FoleyFXGroup = "metal_foley"
Cockpit1stPersonSound = ""
Cockpit3rdPersonSound = ""
BoostSound = ""
BoostSound = ""
BoostSound = ""
BoostSound = ""
BoostSound = ""
TrickSound = "" //Played when the flyer performs a roll
FlipSound = "" //Played when the flyer performs a flip
ProximityMinDist = "25" // Distance from target where proximity parameter of engine is 0.
ProximityMaxDist = "100" // Distance from target where proximity parameter of engine is 1.
//MinSpeed = "35" = .23
//MidSpeed = "70" = .54
//MaxSpeed = "95" = .63 contrails at .7
//BoostSpeed = "150"
[/code]
Edit: This won't address the issue you have with movement. You'll want to make sure the vehicle is completely inactive:

Code: Select all

SetProperty([vehiclename], "PhysicsActive", 0)
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Scripting questions (vehicle related stuff)

Post by Locutus »

SetProperty([vehiclename], "PhysicsActive", 0) was exactly what I needed to solve the first issue!
Thank you, Mav! :D

(If somebody got an idea for 2) and 3) I'm still all ears:))
hunpeter12
Command Sergeant Major
Command Sergeant Major
Posts: 260
Joined: Mon Apr 18, 2011 2:53 pm
Projects :: Underground City The Complex [WIP]
Games I'm Playing :: SWBF2

Re: Scripting questions (vehicle related stuff)

Post by hunpeter12 »

For the 3rd issue I found a line in a turret odf:

Code: Select all

vehiclecollision    = "p_base"
There are also soldier and ordnance collision lines. I guess you have to do something with this, but I have no clue how to use it.
And I don't quite understand your 'if' statement in the 2nd problem's LUA.
I'm not a LUA expert, but that code doesn't seem right. Wouldn't it be sth like this:

Code: Select all

pilot_is_in_vehicle = GetCharacterVehicle(pilot)
if IsCharacterHuman(pilot) == 0 and SomethingIDontKnow ~= "ship_manned_wrt_destroyer_1 (I don't know what this is for) and pilot_is_in_vehicle == nil then ... 
But again I've just been getting to know basic LUA, so I could be completely incorrect. :(
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Scripting questions (vehicle related stuff)

Post by Locutus »

Adding the current turret collision parts explicitly for vehicles as odf parameter didn't change anything in a test I made a while ago but I'll look into it again. Thanks for the hint!:)


About 2)
In this case ship_manned_wrt_destroyer_1 is a boolean type variable.
if a then equals if a == true then and if not a then equals if a==false then so I think this part should be correct.
hunpeter12
Command Sergeant Major
Command Sergeant Major
Posts: 260
Joined: Mon Apr 18, 2011 2:53 pm
Projects :: Underground City The Complex [WIP]
Games I'm Playing :: SWBF2

Re: Scripting questions (vehicle related stuff)

Post by hunpeter12 »

Ok, I didn't know about that.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Scripting questions (vehicle related stuff)

Post by [RDH]Zerted »

Locutus wrote:if a then equals if a == true then...
Not exactly true. It evaluates 'a' to a true or false value. In Lua, nil is false and False is false. Everything else evaluates to True. In some languages zero evaluates to false, but not in Lua.

http://lua-users.org/wiki/ExpressionsTutorial

Why does your #2 not work as expected? What does it display when you print out each of the values? Also, you should check 'if pilot' before you use pilot in GetCharacterVehicle().

If you can't figure out a way to get it working, you might be able to do it with another team. Whenever a vehicle spawns, manually spawn a unit on a 3rd team and put that unit inside the vehicle. Don't let that 3rd team spawn any other time.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: Scripting questions (vehicle related stuff)

Post by Anakin »

About 3)
As far as i know you just have to make a new colioson polygon, put it with the normal polygon under a null, name it c_* and hide it. Than it should work.
I' m not sure how the colison thing works when you made no colison (the warnings from munge log). But have you tried to simply remove the custom colision and let the munge bats do that job??
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Scripting questions (vehicle related stuff)

Post by Locutus »

Thanks, Zerted, the idea with spawning the units on a local team worked! :D


@Anakin: Mh, the tutorial said that collision primitives should be used. But thanks for the tip, we'll try!
Edit: Thanks, that worked great!

New SBP version on the way ;D
Post Reply