Help w/ LUA aigoal seting weapon

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
Syth
General
General
Posts: 784
Joined: Thu Apr 13, 2006 8:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: happy fun island

Help w/ LUA aigoal seting weapon

Post by Syth »

I want to make a weapon that sets ai goals, here is what i have so far LUA wise
Hidden/Spoiler:
--////////////// Commands setup
command = 0;
OnCharacterDispensePowerup(
function(character,powerup)
CommandDM = "Command_Deathmatch_ord"
CommandCon = "Command_Conquest_ord"
CommandDef = "Command_Defend_ord"
CommandDes = "Command_Destroy_ord"
CommandRes = "Command_Reset_ord"
Toggle = "Toggle_Command_ord"

if GetEntityClass(powerup) == GetEntityClassPtr(CommandRes) then
ClearAIGoals(ATT)
elseif GetEntityClass(powerup) == GetEntityClassPtr(CommandDef) then
AddAIGoal(ATT, "Defend", 500)
elseif GetEntityClass(powerup) == GetEntityClassPtr(CommandDes) then
AddAIGoal(ATT, "Destroy", 500)
elseif GetEntityClass(powerup) == GetEntityClassPtr(CommandDM) then
AddAIGoal(ATT, "Deathmatch", 500)
elseif GetEntityClass(powerup) == GetEntityClassPtr(CommandCon) then
AddAIGoal(ATT, "Conquest", 500)
elseif GetEntityClass(powerup) == GetEntityClassPtr(Toggle) then
if command == 0 then
SetProperty("rep_inf_ep3_commander", "WeaponName4", "Command_Deathmatch")
command = 1;
elseif command == 1 then
SetProperty("rep_inf_ep3_commander", "WeaponName4", "Command_Defend")
command = 2;
elseif command == 2 then
SetProperty("rep_inf_ep3_commander", "WeaponName4", "Command_Destroy")
command = 3;
elseif command == 3 then
SetProperty("rep_inf_ep3_commander", "WeaponName4", "Command_Reset")
command = 4;
else
SetProperty("rep_inf_ep3_commander", "WeaponName4", "Command_Conquest")
command = 0;
end
end
end
)
This is snip-bits of code i found else where on gt edited and added to try to get what im going for (im no LUA master :P )

I have a toggle weapon that will toggle commands so i can have more then 4, but this isnt what im concerned with.

The problem is when i use the powerup item that's suppose to trigger the aigoal, the game crashes (it does with the toggle weapon too).
RepSharpshooter
Gametoast Staff
Gametoast Staff
Posts: 1351
Joined: Tue Jul 10, 2007 4:10 pm

Re: Help w/ LUA aigoal seting weapon

Post by RepSharpshooter »

I'm no lua master either, but I thought zerted told me that SetProperty is for a specific instance of a unit whereas SetClassProperty affects the entire class such as rep_inf_ep3_commander
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: Help w/ LUA aigoal seting weapon

Post by MasterSaitek009 »

Yeah your right Rep'. SetProperty is for instance properties like health. SetClassProperty will work for anything that carries over across classes, like weapons and anim sets.
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: Help w/ LUA aigoal seting weapon

Post by [RDH]Zerted »

Yes you should be using SetClassProperty(), which also means that anyone using that class+weapon will change it for every other unit of that class. In addition to that, messing with weapon properties and weapon 'layouts' normally cause crashing when used online. You should test your idea with multiple players before releasing the map its in. One more thing, I think the max amount of AI goals is 7 (maybe 9, I forget...). Once you go over that, the game crashes.

Your weapon could work, but unless its for SP only, you need to rethink your toggle idea.

It should be crashing with something in the error log. Whats in it?
Syth
General
General
Posts: 784
Joined: Thu Apr 13, 2006 8:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: happy fun island

Re: Help w/ LUA aigoal seting weapon

Post by Syth »

Again the toggle idea was just kinda added on a whim and i know about the its current draw backs.
So there is a limit on AI goals? e.g. you could only add the goal "conquest" added so many times?
I could just make it each time a goal is issued any other goals are cleared. While on the subject of aigoals, what does the number following the goal mean?

EDIT2: Okay i doofed. Apparently i made some change in the dispenser's odf that caused a crash. Whatever.. it works now at least.
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: Help w/ LUA aigoal seting weapon

Post by [RDH]Zerted »

Yes, there is an AI goal limit. One thing you can do is store and delete the last AI goal the weapon set. AddAIGoal() returns the added goal then you can use RemoveAIGoal() on it. Something like:

if storedGunGoal then
RemoveAIGoal( storedGunGoal )
end
storedGunGoal = AddAIGoal()

would would keep the AI goal count down. The number is the percentage of AI that should follow the goal. Its based off the max value, so a value of 500 doesn't mean 500%. If you do AddAIGoal( XXX, 500 ) and AddAIGoal( xxx, 1000 ), then 500 means 1/3 of the total AI bots (500 is one third of 1500).
Post Reply