Question about lua function

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
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Question about lua function

Post by naru1305 »

Hello everybody!
I´m working on a map and found this in the BF2-documentation:
Hidden/Spoiler:
CharacterIssueAICommand: function (player, command_id)
This event occurs whenever a player issues a command to the AI. The command ID that is passed in must be translated into a string by calling TranslateAICommand(command_id). This function will return one of the following strings:
“getintovehicle”
“getoutofvehicle”
“waitforpickup”
“followchr”
“stopfollowchr”
so my question is if anyone has ever use this function and can tell me how it works .
Hidden/Spoiler:
sorry fo my bad english :oops:
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: question about lua function

Post by DarthD.U.C.K. »

you can use it to trigger an even when the player issues one of the listed commands
here is an example:

Code: Select all

follow = CharacterIssueAICommand(
        function(player, followchr)
		KillObject("DeservesToBeKilled")
                StartTimer(DeservesTobBeStarted)
              end
        end,
        "followme!"
        )
this code will kill the object "DeservesToBeKilled" and start the timer "DeservesToBeStarted" when the player tells an ai-soldier to follow him
please corretc me if somethings wrong, im not really experienced with scripting
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

thanks for the fast answer :D

but i´m not a master in scripting, so where must i put this in my lua?
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: question about lua function

Post by DarthD.U.C.K. »

put it inside the "ScripInit"-function. If you are unsure where to playce what or how to write a certain thing, look into the shipped campaignluas. you can find examples for all kind of functions etc. there.
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

thank you very much :bowdown:
now i placed it into the ScriptInit
Hidden/Spoiler:
function ScriptInit(follow = CharacterIssueAICommand(
function(player, followchr)
KillObject("DeservesToBeKilled")
StartTimer(DeservesTobBeStarted)
end
end,
"followme!"))

ReadDataFile("ingame.lvl")
and then comes this munge error
Hidden/Spoiler:
C:\BF2_ModTools\data_BOG\_BUILD\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\BOG\BOGc_con.lua:60: `)' expected near `='
ERROR[scriptmunge scripts\BOG\BOGc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\BOG\BOGc_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

ERROR[levelpack mission\BOGc_con.req]:Expecting bracket, but none was found.
File : munged\pc\bogc_con.script.req(1)...

ucft <--
ERROR[levelpack mission\BOGc_con.req]:Expecting bracket, but none was found.
File : munged\pc\bogc_con.script.req(1)...

ucft <--

2 Errors 0 Warnings
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: question about lua function

Post by Fiodis »

I thought it was supposed to go inside ScriptPostLoad. Anyway, if that's where you put it you're missing a whole lot of other stuff in your ScriptInit, such as team setup. The second parentheses after "followme!" closes ScriptInit.
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: question about lua function

Post by DarthD.U.C.K. »

Fiodis wrote:I thought it was supposed to go inside ScriptPostLoad.
*slaps head* yeah, of course. i meant scriptpostload, sorry :oops:
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

I'm quite desperate now :(
maybe you can tell me exactly where i must put the function and what else i must do?
against missunderstandigs, i post my whole LUA(without sound):
Hidden/Spoiler:
-- load the gametype script
ScriptCB_DoFile("ObjectiveConquest")
ScriptCB_DoFile("setup_teams")

-- REP Attacking (attacker is always #1)
REP = 1;
CIS = 2;
-- These variables do not change
ATT = REP;
DEF = CIS;


function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}



--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)

conquest:Start()

EnableSPHeroRules()

follow = CharacterIssueAICommand(
function(player, followchr)
KillObject("DeservesToBeKilled")
StartTimer(DeservesTobBeStarted)
end
end,
"followme!")

end



---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------
function ScriptInit()

ReadDataFile("ingame.lvl")


SetMaxFlyHeight(1000)
SetMaxPlayerFlyHeight (1000)

SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo
SetMemoryPoolSize ("LightFlash",118)
SetMemoryPoolSize ("WalkerBlendUnit",60)


ReadDataFile("sound\\geo.lvl;geo1cw")

ReadDataFile("dc:SIDE\\rep.lvl",
"rep_inf_ep2_rifleman",
"rep_inf_ep2_pilot",
"rep_inf_ep2_sergeant",
"rep_inf_ep2_lieutanant",
"rep_inf_ep2_captain",
"rep_hero_obiwan",
"rep_inf_ep2_commander",
"rep_fly_gunship",
"rep_walk_atte",
"rep_inf_clone_commando_Boss",
"rep_fly_jedifighter")

ReadDataFile("dc:SIDE\\cis.lvl",
"cis_inf_officer",
"cis_inf_droid",
"cis_inf_commander",
"cis_inf_droideka",
"cis_fly_geofighter",
"cis_walk_spider",
"cis_hero_jangofett")

ReadDataFile("dc:SIDE\\geo_heroes.lvl",
"rep_hero_aalya",
"rep_hero_kitfisto",
"rep_hero_kiyadimundi",
"rep_hero_luminara",
"rep_hero_macewindu",
"rep_hero_masterkoon",
"rep_hero_shaakti")

SetupTeams{
rep = {
team = REP,
units = 20,
reinforcements = 150,
soldier = { "rep_inf_ep2_rifleman",9, 25},
assault = { "rep_inf_ep2_sergeant",1, 4},
engineer = { "rep_inf_ep2_lieutanant",1, 4},
sniper = { "rep_inf_ep2_captain",1, 4},
officer = {"rep_inf_ep2_commander",1, 4},
pilot = { "rep_inf_ep2_pilot",1, 4},
special = { "rep_inf_clone_commando_Boss",0, 1},

},
cis = {
team = CIS,
units = 20,
reinforcements = 150,
soldier = { "cis_inf_droid",9, 25},
assault = { "cis_inf_officer",1, 4},
officer = {"cis_inf_commander",1, 4},
special = { "cis_inf_droideka",1, 4},
}
}
SetTeamName (3, "jedi")
AddUnitClass (3, "rep_hero_aalya", 1,1)
AddUnitClass (3, "rep_hero_kitfisto", 1,1)
AddUnitClass (3, "rep_hero_kiyadimundi", 1,1)
AddUnitClass (3, "rep_hero_luminara", 1,1)
AddUnitClass (3, "rep_hero_macewindu", 1,1)
AddUnitClass (3, "rep_hero_masterkoon", 1,1)
AddUnitClass (3, "rep_hero_shaakti", 1,1)
SetUnitCount (3, 7)
AddAIGoal(3, "Deathmatch", 100)
SetTeamAsEnemy(DEF,3)
SetTeamAsEnemy(3,DEF)
SetTeamAsFriend(ATT,3)
SetTeamAsFriend(3,ATT)

SetHeroClass(CIS, "cis_hero_jangofett")
SetHeroClass(REP, "rep_hero_obiwan")
i hope you can help me :sick:
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: question about lua function

Post by Fiodis »

From the stock documentation, which you should always read first:
CharacterIssueAICommand: function (player, command_id)
This event occurs whenever a player issues a command to the AI. The command ID that is passed in must be translated into a string by calling TranslateAICommand(command_id). This function will return one of the following strings:
“getintovehicle”
“getoutofvehicle”
“waitforpickup”
“followchr”
“stopfollowchr”
In other words you have to use TranslateAICommand along with CharacterIssueAICommand.
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: question about lua function

Post by DarthD.U.C.K. »

you know, the code i posted is an example to show what you can do with the function. do you have an object labeled "DeservesToBeKilled"? no? then nothing will happen and since you dont have a timer labeled "DeservesToBeStarted" in your lua it wont start either.
what do you want to do? i thought you just wanted to know how the function works so i gave a non-specific example.

edit: oh i overread that, my fault again, so jhers what i think should work if you have an obhect and a timer called like in this example:

Code: Select all

follow = CharacterIssueAICommand(
        function(player, command_id) == followchr then
             if TranslateAICommand(command_id)
                KillObject("DeservesToBeKilled")
                StartTimer(DeservesTobBeStarted)
            else
            end
           end
        end,
        "followme!"
        )
im not sure whether to put "followchr" in quotation marks or not. :?
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

thank you very much DarthD.U.C.K., it was a missunderstanding by me :oops:

Edit: i want one(or more) unit to follow me on my map, so i think it was a missunderstanding by me to use this function for it :oops:
i come to this idea, because sometimes on my maps, units follow me, so i want to use it(maybe for a squad)
i hope you understand me and sorry for the missunderstanding :oops:
Last edited by naru1305 on Tue Jan 25, 2011 12:02 pm, edited 3 times in total.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: question about lua function

Post by Fiodis »

If I'm understanding the documentation correctly, I think it should be more like this:

Code: Select all

follow = CharacterIssueAICommand(
        function(player, command_id) 
             command =  TranslateAICommand(command_id)
                if command == "followchr" then
                KillObject("DeservesToBeKilled")
                StartTimer(DeservesTobBeStarted)
            end
        end
        )
But then I acknowledge I'm not a coding guru. I'm probably missing an end or a comma in there somewhere. You see my point, though - that you have to check if the result of TranslateAICommand is equal to "followchr". Your code, Duck, seems analogous to a fragmented sentence - you've got if TranslateAICommand...what? Also, after == followchr you have a "then" without any "if" before it.

Again, I'm not as sure of my own code, either - but that's how I see it.
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: question about lua function

Post by DarthD.U.C.K. »

>.< argh sorry, i put the if one line below accidentally. you are right about the two ends too, i added a third one because i though the "then" should have an end. i dont think you need an extra variable for the command, the campaign-lua uses things like "self.winningTeam == DEF" as conditions and i think you need a comma after the last end but then again im ten timesless a coding-guru than you so...
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

thanks for your answers, but i hope you read my edit above
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: question about lua function

Post by DarthD.U.C.K. »

so you want to command units to follow you? you can already do that if ou press "F4" and aim at an ai-soldier.
the discussed function is triggered when you are doing this.
User avatar
naru1305
Major General
Major General
Posts: 657
Joined: Fri Jan 07, 2011 4:57 pm
Games I'm Playing :: SWBF2
Location: Germany
Contact:

Re: question about lua function

Post by naru1305 »

OMG, i´m so silly :oops: shame on me :(
but i thank you very much for your help
DarthD.U.C.K. wrote:you can find examples for all kind of functions etc. there.
now i know where i must look, when i want to use a function :bowdown:
Post Reply