I´m working on a map and found this in the BF2-documentation:
Question about lua function
Moderator: Moderators
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Question about lua function
Hello everybody!
I´m working on a map and found this in the BF2-documentation:
so my question is if anyone has ever use this function and can tell me how it works .
I´m working on a map and found this in the BF2-documentation:
Hidden/Spoiler:
Hidden/Spoiler:
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
you can use it to trigger an even when the player issues one of the listed commands
here is an example:
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
here is an example:
Code: Select all
follow = CharacterIssueAICommand(
function(player, followchr)
KillObject("DeservesToBeKilled")
StartTimer(DeservesTobBeStarted)
end
end,
"followme!"
)please corretc me if somethings wrong, im not really experienced with scripting
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
thanks for the fast answer
but i´m not a master in scripting, so where must i put this in my lua?
but i´m not a master in scripting, so where must i put this in my lua?
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
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.
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
thank you very much
now i placed it into the ScriptInit
and then comes this munge error
now i placed it into the ScriptInit
Hidden/Spoiler:
Hidden/Spoiler:
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: question about lua function
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.
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
*slaps head* yeah, of course. i meant scriptpostload, sorryFiodis wrote:I thought it was supposed to go inside ScriptPostLoad.
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
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):
i hope you can help me 
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:
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: question about lua function
From the stock documentation, which you should always read first:
In other words you have to use TranslateAICommand along with CharacterIssueAICommand.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”
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
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:
im not sure whether to put "followchr" in quotation marks or not. 
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!"
)- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
thank you very much DarthD.U.C.K., it was a missunderstanding by me
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
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
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
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
Last edited by naru1305 on Tue Jan 25, 2011 12:02 pm, edited 3 times in total.
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: question about lua function
If I'm understanding the documentation correctly, I think it should be more like this:
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.
Code: Select all
follow = CharacterIssueAICommand(
function(player, command_id)
command = TranslateAICommand(command_id)
if command == "followchr" then
KillObject("DeservesToBeKilled")
StartTimer(DeservesTobBeStarted)
end
end
)Again, I'm not as sure of my own code, either - but that's how I see it.
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
>.< 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...
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
thanks for your answers, but i hope you read my edit above
- DarthD.U.C.K.
- Master of the Force

- Posts: 6027
- Joined: Wed Sep 27, 2006 11:05 am
- Location: Duckburg, Germany
Re: question about lua function
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.
the discussed function is triggered when you are doing this.
- naru1305
- Major General

- Posts: 657
- Joined: Fri Jan 07, 2011 4:57 pm
- Location: Germany
- Contact:
Re: question about lua function
OMG, i´m so silly
shame on me
but i thank you very much for your help
but i thank you very much for your help
now i know where i must look, when i want to use a functionDarthD.U.C.K. wrote:you can find examples for all kind of functions etc. there.
