Fun with LUA functions (FAQ)

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

Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Fun with LUA functions (FAQ)

Post by Ace_Azzameen_5 »

IIRC Zerted used it for something, I think maybe 3 playable teams?

Also, what does CreateMatrix do? I wonder if you can enter 6 values for a world position. I've always wondered if you could edit matrices stored in a 'word' (programming linguo down the brain tubes...) by having LUA serve up the component numbers to be edited mathematically...
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Fun with LUA functions (FAQ)

Post by Frisbeetarian »

Ace_Azzameen_5 wrote:IIRC Zerted used it for something, I think maybe 3 playable teams?
I couldn't find it in in his 4-team code.
Ace_Azzameen_5 wrote:Also, what does CreateMatrix do?
http://www.gametoast.com/forums/viewtop ... 89#p297189
User avatar
DarthD.U.C.K.
Master of the Force
Master of the Force
Posts: 6027
Joined: Wed Sep 27, 2006 11:05 am
Location: Duckburg, Germany

Re: Fun with LUA functions (FAQ)

Post by DarthD.U.C.K. »

this is a rather large bump, so ill hope this will be usefull to some people..
since it came up in the fun with luacommands thread that it would be nice to have the inputs for the commands and i had a bit time, i took the "LUA_Callback_Reference.txt" from psych0fred's site and filled in as many parameters as i could, most are from the campaign and objective luas. some are guesses and i might have mixed entity/object sometime.
here is what i got so far
Hidden/Spoiler:
/** Functions EXPORTED to Lua by RegisterLuaAPIFunctions
FindEntityClass(entity);
SetPS2ModelMemory(number);
SetWorldExtents(number); // for CollisionManager and TreeGrid sizes...
StealArtistHeap(number*number); --for PS2
ReadDataFile(sourcefile);
ReadDataFileInGame(lua_State* aState);
SetupTempHeap(lua_State *aState);
ClearTempHeap(lua_State *aState);
AddCameraShot(x,y,y rotx, roty, rotz);
SetCameraRotation(lua_State* aState);
SetCameraPosition(lua_State* aState);
MoveCameraToEntity(lua_State* aState);
SetMapCameraOffset(lua_State* aState);
SetMapCameraPitch(lua_State* aState);
SetMapCameraZoom(lua_State* aState);
GetMapCameraZoom(lua_State* aState);
SnapMapCamera(lua_State* aState);
SetState("Shell"); --restarts the shell
SetHistorical(); --obsolete, from swbf1
SetTeamName(team, name);
SetTeamAggressiveness(team, number);
SetMinFlyHeight(number);
SetMaxFlyHeight(number);
SetMinPlayerFlyHeight(number);
SetMaxPlayerFlyHeight(number);
SetUberMode(boolean);
SetAllowBlindJetJumps(1 or 0);
SetStationaryWaitTime(lua_State* aState); --unused
SetTeamIcon(team, icon);
SetTeamAsEnemy(team, enemyteam);
SetTeamAsNeutral(team, neutralteam);
SetTeamAsFriend(team, friendteam);
SetUnitCount(team, number);
GetUnitCount(team);
SetReinforcementCount(team, number);
GetReinforcementCount(team);
AddReinforcements(team, number);
SetTeamPoints(team, number);
GetTeamPoints(team);
AddTeamPoints(team, number);
AddFlagCapturePoints(character);
AddAssaultDestroyPoints(character);
AddSpaceAssaultDestroyPoints(character, object);
GetTeamFactionId(lua_State* aState);
AddUnitClass(team, unitclass, minunits, maxunits);

//Hero
SetHeroClass(team, heroclass);
EnableSPHeroRules(boolean);
EnableSPScriptedHeroes(boolean);
SetHeroUnlockRule(lua_State* aState);
SetHeroTeamRule(lua_State* aState);
SetHeroPlayerRule(lua_State* aState);
SetHeroRespawnRule(lua_State* aState);
UnlockHeroForTeam(teamnumber);
AcceptHero(team);

ShowAllUnitsOnMinimap(lua_State* aState); --unused
ShowTeamPoints(team, boolean);
ActivateBonus(team, bonus{energy_boost,supplies,garrison,autoturrets,bacta_tanks,combat_shielding,sabotage,advanced_blasters,leader});--not sure if these are the right strings
SetBleedRate(team, rate);
GetBleedRate(team);

SetCarrierClass(lua_State* aState); --unused
SetSpawnDelay(number, number);
SetSpawnDelayTeam(number, number, team);
SetDenseEnvironment("boolean");
SetAttackerSnipeRange(number);
SetDefenderSnipeRange(number);
SetStayInTurrets(1 or 0); --found on endor
SetMaxCollisionDistance(number); --used in combination with asterioids
SetParticleLODBias(value);

SetMemoryPoolSize(memorypool, size);

SetNumBirdTypes(lua_State* aState);
SetBirdType(lua_State* aState);
SetBirdFlockMinHeight(lua_State* aState);

SetNumFishTypes(lua_State* aState);
SetFishType(lua_State* aState);

//Asterioids --require: SetMemoryPoolSize("Asteroid", count)
FillAsteroidRegion(region, class, count, x, y, z, rotx, roty, rotz); --last values guessed
FillAsteroidPath(path, number, class, count, x, y, z, rotx, roty, rotz); --last values guessed

AddDeathRegion(region);
AddLandingRegion(region);
RemoveRegion(region);

ClearWalkers();
AddWalkerType(legpairs, number);

SetAIVehicleNotifyRadius(number);
SetAIViewMultiplier(number );
AISnipeSuitabilityDist(number);
SetGroundFlyerMap(1 or 0);

EnableAIAutoBalance();
DisableAIAutoBalance();
SetAIDifficulty(number{friends}, number{enemys});
SetAIDifficulty(number{friends}, number{enemys}, difficulty{easy,medium,hard}});

AddMissionObjective(lua_State* aState);
ActivateObjective(lua_State* aState);
CompleteObjective(lua_State* aState);
AddMissionHint(hint);

SetFlagGameplayType(type{1flag,2flag,campaign});

//SpaceAssault
SpaceAssaultEnable(boolean);
SpaceAssaultAddCriticalSystem(name, point, hudx, hudy, display hudmarker(boolean));
SpaceAssaultLinkCriticalSystems(lua_State* aState);
SpaceAssaultSetupTeamNumbers(lua_State* aState);
SpaceAssaultSetupBitmaps(bitmap1, bitmap2...);
SpaceAssaultGetScoreLimit();

IsCampaign(lua_State* aState);
GetWorldFilename(); --used in multiobjectivescontainer.lua for soundsetup

//Messages
ShowMessageText(string, team);
ShowPopup(string);
ShowObjectiveTextPopup(string);
ShowTimer(timer);
ShowSelectionTextPopup(string); --used in spa2c_c for decision making but not for pc?!

BroadcastVoiceOver(VO, team);

ScriptCB_PlayerSuicide(lua_State *aState);

//Markers
MapAddRegionMarker(region, markerclass, number, number, team, color, boolean, boolean, boolean, boolean);
MapRemoveRegionMarker(region);
MapAddEntityMarker(objectname, markerclass, number, number, team, color, boolean, boolean, boolean, boolean);
MapRemoveEntityMarker(objectname);
MapAddClassMarker(class, markerclass, number, number, team, color, boolean, boolean, boolean, boolean);
MapRemoveClassMarker(class);
MapHideCommandPosts();

EnableBuildingLockOn(object, boolean);

//Timer
FindTimer(timer);
CreateTimer(timer);
DestroyTimer(timer);
StartTimer(timer);
StopTimer(timer);
SetTimerValue(timer, value);
GetTimerValue(timer);
SetTimerRate(timer, rate);
GetTimerRate(timer);
GetTimerName(lua_State *aState); --unused

SetDefeatTimer(timer, team);
SetMissionTimer(lua_State* aState); --unused
SetVictoryTimer(timer, team);

//Object
GetObjectPtr(object);
ActivateObject(object);
DeactivateObject(object);
SetObjectTeam(object, team);
GetObjectTeam(object);
IsObjectAlive(object);
GetObjectHealth(object);
GetObjectShield(object);
GetObjectLastHitWeaponClass(object);
KillObject(object);
RespawnObject(object);

//Entity
GetEntityPtr(entity);
GetEntityName(entity);
GetEntityClass(entity);
GetEntityClassName(entity);
SetEntityMatrix(entity, matrix);
GetEntityMatrix(entity);
SetProperty(object, property, value);
CreateEntity(class, node, name);
DeleteEntity(entity);

GetEntityClassPtr(entity);
SetClassProperty(class, property, value);


--flyer = vehiclespawnname
EntityFlyerTakeOff(flyer);
EntityFlyerLand(flyer);

EntityFlyerInitAsFlying(flyer);
EntityFlyerInitAsLanded(flyer);

EnterVehicle(lua_State* aState); --unused
ExitVehicle(lua_State* aState); --unused

EnableFlyerPath(path, 1 or 0);

GetPathPoint(path, nodenumber);

GetNumTeamMembersAlive(team);

CreateMatrix(lua_State* aState);

GetScreenPosition(object);

// procedural animation callbacks
PlayAnimation(animation);
PauseAnimation(animation);
RewindAnimation(animation);
SetAnimationStartPoint(animation);
PlayAnimationFromTo(animation, startframe, endframe);

//Character
GetTeamSize(team);
GetTeamMember(team, unitindex); --returns character
GetCharacterTeam(character);
SelectCharacterTeam(character, team);
IsCharacterHuman(character);
SelectCharacterClass(character, class);
GetCharacterClass(character);
BatchChangeTeams(sourceteam, destinationteam, unitnumber);
AllowAISpawn(team, boolean);
SpawnCharacter(character, nodename);
GetCharacterUnit(character);
GetCharacterVehicle(character);
GetCharacterRemote(character);
GetCharacterControllable(character);

GetCommandPostCaptureRegion(cp);
GetCommandPostBleedValue(cp);
GetCommandPostTeam(cp);

MissionVictory(team);
MissionDefeat(team);

SetMissionEndMovie(sourcefile, movieanme);

//AI Goal management functions
ClearAIGoals(team);
DeleteAIGoal(goal);
AddAIGoal(team, goal, weight);
//dynamic congraph functions
TogglePlanningGraphArcs(connection);
BlockPlanningGraphArcs(connection);
UnblockPlanningGraphArcs(connection);
//dynamic barrier functions
ToggleBarriers(barrier);
EnableBarriers(barrier);
DisableBarriers(barrier);

ForceAIOutOfVehicles(team, boolean);
AICanCaptureCP(cp, team, boolean);
SetAIDamageThreshold(object, number);

//Translate AI command ID's to strings
TranslateAICommand(lua_State* aState); --unused

// space boarding party functions
AddShieldStrength(lua_State* aState);

// set the north angle on the minimap
SetMapNorthAngle(angle, number);
SetMapNorthAngle(angle);

//for this map, forces all the non-AI players to join team 1
ForceHumansOntoTeam1();

//
CanCharacterInteractWithFlag(character);
GetFlagCarrier(flag);

//

SetMapRangeOverall(lua_State *aState);
SetMapRangeShooting(lua_State *aState);
SetMapRangeViewCone(lua_State *aState);
SetMapViewConeAngle(lua_State *aState);

DisableSmallMapMiniMap();

// effects
CreateEffect(effectfile);
RemoveEffect(effect);
AttachEffectToObject(effect, object);
AttachEffectToMatrix(effect, matrix/nodename);
GetEffectMatrix(effect);
SetEffectMatrix(lua_State* aState);
IsEffectActive(lua_State* aState);
SetEffectActive(lua_State* aState);
if you can add anything or correct something, you can post the updated list and ill remove theone in my post.

i hope this is usefull to someone.....
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am
Games I'm Playing :: SWBF2
Location: Princeton, NJ

A small discovery for MP

Post by razac920 »

Hi, I don't know how relevant this is to most modders, but I need players to be able to switch sides sometimes, so the default MP option "Auto-Assign" really messes me up, and most people do not adjust this setting. Anyway I found out that the command ScriptCB_SetCanSwitchSides(1) will override auto-assign and allow player switches. Sorry if someone had posted this before, but I hadn't seen it, and it will be very useful for my Gun Game mode. Thanks!
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: A small discovery for MP

Post by Noobasaurus »

Oh wow this is really awesome! Great find!
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Fun with LUA functions (FAQ)

Post by LRKfm946 »

While this topic's been bumped, I might as well contribute my findings:

GetWorldPosition(unit) is quite a useful function. It outputs the x, y, and z coordinates of the given unit, and these can be used and manipulated however you want, unlike GetEntityMatrix. GetEntityMatrix outputs a UserData type, which can only be used by very specific LUA functions, and you can't access the individual coordinates. GetWorldPosition can be used very creatively for things like the Camper Killer function I made for the Hunger Games mod (thanks again Zerted for helping me with this :P). Noobasaurus also used it in a pretty cool way here: http://www.gametoast.com/viewtopic.php? ... 6&start=20

Camper Killer:
Hidden/Spoiler:
[code] local unitLocations = {}
local minChange = 10

CamperKiller = function(self)
print("\nChecking for campers...")

local CampCheck = function( player, unit )
print("Checking player ", player)
if (player == nil) or (unit == nil) then return end --check input
local x, y, z = GetWorldPosition(unit)
local currentPosition = {x, y, z}
local previousPosition


--start tracking a new player
if unitLocations[player] == nil then
print("\tStarting to track player")
unitLocations[player] = currentPosition
--PrintMatrix(unitLocations[player])
return
else
--previous location = last stored location
print("\tPlayer is already being tracked.")
previousPosition = unitLocations[player]
end

--see if the player has been camping
if math.abs(previousPosition[1] - currentPosition[1]) < minChange
and math.abs(previousPosition[2] - currentPosition[2]) < 20
and math.abs(previousPosition[3] - currentPosition[3]) < minChange then
print("\tPlayer has not moved.")
--they've now been stationary for another interval, raise interval count
players_alive[player].intervalCount = players_alive[player].intervalCount + 1
print("\tPlayer has been in stationary for this many intervals:", players_alive[player].intervalCount)

--If they've been camping for long enough (90 seconds), then they're in trouble.
if players_alive[player].intervalCount >= 12 then
print("\tPlayer is camping, applying health degen.")

--They might have full health, so the health degen has to be triggered; take away 1 health unit
if players_alive[player].hurtCount == 0 then
unitHealth = (GetObjectHealth(unit) - 1)
SetProperty(unit, "CurHealth", unitHealth)
end
SetProperty(unit, "AddHealth", -10)

--they are now camping
if not players_alive[player].isCamping then
players_alive[player].isCamping = true
end

end


print(" ")
return

else -- their position has changed more than 10 units
print("\tPlayer has moved.")

--if they WERE camping
if players_alive[player].isCamping then

-- they're moving now so reduce the damage
SetProperty(unit, "AddHealth", -5)

--increase the number of intervals they've been hurt but moving
print("\tThe player was camping, so track amount of time they're still being hurt for.")
players_alive[player].hurtCount = players_alive[player].hurtCount + 1

--if they've kept moving while being hurt for 3 intervals, then they've had enough
if players_alive[player].hurtCount > 3 then
print("\tThey've kept moving, so stop hurting them and reset their info.")
-- reset everything
SetProperty(unit, "AddHealth", 0)
players_alive[player].isCamping = false
players_alive[player].hurtCount = 0

else -- if they haven't been hurt for long enough, keep hurting them
print("\tPlayer has been hurt for "..players_alive[player].hurtCount.." intervals.")
end

end
-- they've moved, so we need to record their new position
print("\tRecording their current position.\n")
players_alive[player].intervalCount = 0
unitLocations[player] = currentPosition
return
end
end

--run camp check for each player alive
local i, v
for i, v in pairs(players_alive) do
CampCheck(i, GetCharacterUnit(i) )
end

end


CamperKillerTimer = CreateTimer("CamperKillerTimer")
SetTimerValue(CamperKillerTimer , 10)
OnTimerElapse(
function(timer)
CamperKiller()
SetTimerValue(CamperKillerTimer, 10)
StartTimer(CamperKillerTimer)
end,
"CamperKillerTimer"
)[/code]

You can also redefine functions that are already in the game (more thanks for Zerted's help here). Here's what I did in Hunger Games to keep people from cheating with Freecam:
Hidden/Spoiler:
[code] if not check_map then
--REDEFINE FREE CAM FUNCTION
--prevent cheaters from free caming to find other people
RealFreeCamFn = ScriptCB_Freecamera

ScriptCB_Freecamera = function(...)

print("\nSOMEONE'S CHEATING!!!")
print("Inflicting punishment: ")

print("\tKilling the player.")
ScriptCB_PlayerSuicide(0)
print("\tScolding them for their poor decisions.")
ShowMessageText("level.HGS.cheater1")
ShowMessageText("level.HGS.cheater2")

return RealFreeCamFn(unpack(arg))
end
end[/code]
This makes the player kill themself and shows them a message whenever they click the freecam button in the pause menu.

A bit off topic: If you're wondering, that "if not check_map then" is there because I wanted to be able to use freecam when I was checking the map itself, for taking screenshots and what not. This is something I'd recommend to anyone who's doing lots of scripting in their maps because it allows you to bypass the scripting and check the map layout, etc. by simply changing check_map from false to true.
Sporadia
Corporal
Corporal
Posts: 151
Joined: Thu Jan 24, 2019 11:02 pm
Projects :: No Mod project currently
Games I'm Playing :: None
xbox live or psn: No gamertag set

Re: Fun with LUA functions (FAQ)

Post by Sporadia »

All the ScriptCB commands in interface_util.lua because I've noticed they don't appear on here. There may be more in other interface files.
ScriptCB_AddIFBorder
ScriptCB_AddIFContainer
ScriptCB_AddIFFlashyText
ScriptCB_AddIFImage
ScriptCB_AddIFMaskImage
ScriptCB_AddIFModel
ScriptCB_AddIFScreen
ScriptCB_AddIFText
ScriptCB_EndIFObj
ScriptCB_EndIFScreen
ScriptCB_IFBorder_SetRect
ScriptCB_IFBorder_SetTexCoords
ScriptCB_IFBorder_SetTexture
ScriptCB_IFFlashyText_SetBackground
ScriptCB_IFFlashyText_SetBackgroundRightJustify
ScriptCB_IFFlashyText_SetBackgroundSize
ScriptCB_IFFlashyText_SetTextColor
ScriptCB_IFFlashyText_Setup
ScriptCB_IFFlashyText_StartFlashiness
ScriptCB_IFImage_SetRect
ScriptCB_IFImage_SetTexCoords
ScriptCB_IFImage_SetTexture
ScriptCB_IFMaskImage_SetMaskTexture
ScriptCB_IFModel_AttachModel
ScriptCB_IFModel_SetAnimation
ScriptCB_IFModel_SetAnimationBanks
ScriptCB_IFModel_SetDepth
ScriptCB_IFModel_SetLighting
ScriptCB_IFModel_SetModel
ScriptCB_IFModel_SetOmegaY
ScriptCB_IFModel_SetRotation
ScriptCB_IFModel_SetScale
ScriptCB_IFModel_SetTranslation
ScriptCB_IFObj_CreateHotSpot
ScriptCB_IFObj_GetCPointer
ScriptCB_IFObj_GetVis
ScriptCB_IFObj_MouseOver
ScriptCB_IFObj_SetAlpha
ScriptCB_IFObj_SetColor
ScriptCB_IFObj_SetEnabled
ScriptCB_IFObj_SetPos
ScriptCB_IFObj_SetRotation
ScriptCB_IFObj_SetScreenPosition
ScriptCB_IFObj_SetUseSafezone
ScriptCB_IFObj_SetVis
ScriptCB_IFObj_SetZOrder
ScriptCB_IFObj_TestHotSpot
ScriptCB_IFText_GetDisplayRect
ScriptCB_IFText_GetTextExtent
ScriptCB_IFText_SetFont
ScriptCB_IFText_SetJustify
ScriptCB_IFText_SetLeading
ScriptCB_IFText_SetString
ScriptCB_IFText_SetTextBox
ScriptCB_IFText_SetTextBreak
ScriptCB_IFText_SetTextScale
ScriptCB_IFText_SetTextStyle
ScriptCB_IFText_SetUString
ScriptCB_SetIFScreenViewport
User avatar
cbadal
Corporal
Corporal
Posts: 155
Joined: Sun Jan 18, 2015 5:23 pm
Projects :: SWBF2 XBOX Mod Environment
Games I'm Playing :: SW Battlefront 2
xbox live or psn: No gamertag set
Contact:

Re: Fun with LUA functions (FAQ)

Post by cbadal »

I have a rundown of all of the ScriptCB_ functions (by platform) here too:
https://github.com/BAD-AL/SWBF2_Xbox_mo ... tFunctions

All found by looking through the executable files.
Post Reply