How to make a shield passable/not passable for a certain team

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
RedlineFox
Posts: 2
Joined: Sat Nov 11, 2023 5:05 pm
Projects :: BF 2142 Titan
Games I'm Playing :: Too many games
xbox live or psn: No gamertag set

How to make a shield passable/not passable for a certain team

Post by RedlineFox »

Hello everyone,

I wanted to share one possibility how to make shield passable for certain teams work.
Even if I got this idea many years later and after a lot of thinking... I got a lightning idea and like the English people say better than never.
I thought it would be never possible, but after research with try and error and a little help with lua scripting, I've found a way to make it work with a never used function(as far as I know).

Do you wish to let a certain team through your shield and another team not?
Then listen carefully, because here is a tutorial how to do it in Battlefront 2.

In order to make this work in battlefront 2, you will need three things.

Two ODF files with collision and one without collision(types you want like soldiers and or vehicles - there is no need to double the msh files with different names), some editor placing patient and a part of lua scripting.
Let's start. (This tutorial example is based on my modding project BF2142 Titan)

1. Take a shield odf file whatever you wish to make accessable for your team and copy it and name it.
The two odf files are in my case:
eu_titan_corridor_shield = no collision for soldiers

Code: Select all

[GameObjectClass]		

ClassLabel	=	"destructablebuilding"
GeometryName	=	"eu_titan_forceshield_corridor1.msh"

[Properties]		

GeometryName	=	"eu_titan_forceshield_corridor1"

MaxHealth           = "999999999.0"

SoldierCollision = "CLEAR"

SoundProperty = "shield_amb"
eu_titan_corridor_shield_col with collision for all types

Code: Select all

[GameObjectClass]		

ClassLabel	=	"destructablebuilding"
GeometryName	=	"eu_titan_forceshield_corridor1.msh"

[Properties]		

GeometryName	=	"eu_titan_forceshield_corridor1"

MaxHealth           = "999999999.0"

SoundProperty = "shield_amb"
You can try if other classlabel work. I just can confirm because of tests, that this method works. I didn't test other ways.
All I can say is that the RespawnObject function doesn't work for all ClassLabels. I'm not going to list them.

(Important to mention: For this tutorial make the ClassLabel a destructablebulding and very high health, so it can never be destroyed in any future time)

2. (In Editor) Place both shield in exact the same position and rename for example them like:
shield_clr (Shield without soldier collision)
shield_col (Shield with soldiercollsion)

These are the reference names which will be needed for other lua scripting part.
(You can name it whatever you want, it's just an example)

If you wish to make for vehicles as well, then add VehicleCollision = "CLEAR" in the odf "NO" collision file as well.
There is one other scenario that you could use it for which was going through my brain:
For example you could make it possible to deny a certain team to land on a enemy ship until the shields are down.
(Remember then you would just need to deactivate the region if the shields fail and the other way around reactivate the region if they are up again)
Might add some more exciting action to the game.
Just be creative!
PS: In case of the CIS main ship I would suggest to make two functions for each side of the hangar according to this tutorial. This will ensure that the region becomes
triggered correctly.

Update(02.04.2024):
Import Note: if you plan to use this for vehicles, use for the col odf:
ClassLabel = "destructablebuilding" - (Can be killed/respawned for Space battles and normal ground maps)

and for collision clear in ground battles odf use:
ClassLabel = "destructablebuilding" - (Can be killed/respawned for normal ground maps)
For collision clear in space battles odf use:
ClassLabel = "prop" (for Space use Prop - because props can't be killed, so make sure the shields are in one in Space battles )
Reason:
Collision clear only works in Space for a Prop with UseVCollForFlyers = 1 (Still not find a better way to do it in Space Battles so far)
But the result will be still the same and look the same if shield are exact close together.
To due this finding you don't need to kill the clear odf within your lua.

(Tested and verified also works with bots)

Next:
Before you go into LUA scripting add a thin(in my case named "shield1") region and just put it around the shields shield_clr and shield_col.

3. Lua Scripting part(determine which team can passing through shield and enter region)
(Also here you can be creative and add additional function lines which shall be excuted by the team recognition or add more teams which shall be excluded or included through condition of the IF and combine them with OR)
Add these code lines to your ScriptPostLoad()

Code: Select all

         ActivateRegion("shield1")
	 shield1 = OnEnterRegion(
            function(team,character)
			team = GetCharacterTeam(character)    
                        if team == 1 then
			        RespawnObject("shield1_clr")
                                KillObject("shield1_col")					  
			elseif team == 2 then
				RespawnObject("shield1_col")	
			        KillObject("shield1_clr")							   
                       end
            end,
            "shield1"
            )   
            
Notes(Nice to know):
GetCharacterTeam(character) => The function gets the team number information of your character (It doesn't matter if it's a bot or player)
ActivateRegion("shield1") is an important part, but if you kill the object through ScriptPostLoad() with another Script function just remember to deactivate the region or else the result of this tutorial will be still the same for the teams.

4. Redo this tutorial with different reference names if you wish to have for more shield behaviours like this.
You can reuse the ODF files as longest as they've different reference names in the editor.

Enjoy and be creative in making your maps with this new possibility!
Post Reply