Hey all,
I noticed there are no individual threads which have useful/fun .lua commands in one place, so heres a few I figured out (mostly with help from the people here at Gametoast)
This topic would be beneficial to those getting familiar with .lua functions Feel free to share other useful commands
if not ScriptCB_InMultiplayer() then
ALL = math.random(1,2)
IMP = (3 - CIS)
else
IMP = 1
ALL = 2
end
If you have local teams (like ewoks or wookies), you need to have them reference the REP/CISALL/IMP names instead of ATT/DEF. Otherwise they may attack the wrong team..
Re: The fun .LUA commands thread
Posted: Sun Mar 20, 2011 7:25 pm
by Fiodis
Before someone starts posting one-line LUA functions ("this is how you kill an object, and this is how you set a property") I'll just post this link: link. It's got a list of all LUA functions in BF2, though not their inputs.
Maveritchell wrote:Nice to see them all in one place! Now all we need to do is make a list of inputs for each of those. Nooo problem, yes?
If that's what comes of this thread, excellent. Unfortunately, that's quite a bit of work.
Re: The fun .LUA commands thread
Posted: Sun Mar 20, 2011 7:55 pm
by THEWULFMAN
I think GT can do it, what do you think asleeponduty? Think we can do this? Although, I am actually pretty bad at lua.
when addiint a unit in campaign or adding reinforcements! (just gettin started)
Re: The fun .LUA commands thread
Posted: Sun Mar 20, 2011 8:10 pm
by kinetosimpetus
THEWULFMAN wrote:
Hidden/Spoiler:
This is a great idea. While I dont want to give away all my secrets,here is one KinetosImpetus came up with.
Random CW ATT/DEF
[code]if not ScriptCB_InMultiplayer() then
CIS = math.random(1,2)
REP = (3 - CIS)
else
REP = 1
CIS = 2
end[/code]
Random GCW ATT/DEF
[code]if not ScriptCB_InMultiplayer() then
ALL = math.random(1,2)
IMP = (3 - CIS)
else
IMP = 1
ALL = 2
end[/code]
If you have local teams (like ewoks or wookies), you need to have them reference the REP/CIS/ALL/IMP names instead of ATT/DEF. Otherwisw they may attck the wrong team..
I'm not an expert at "lua", so idk if this syntax is better, worse, identical, or a necessary update, although, a quick change like this did fix a problem in an addme lua.
The original way doesn't make a munge error, but it could be a logic error that will always act as if it's true? I'm not sure...
I'm not an expert at "lua", so idk if this syntax is better, worse, identical, or a necessary update, although, a quick change like this did fix a problem in an addme lua.
The original way doesn't make a munge error, but it could be a logic error that will always act as if it's true? I'm not sure...
I don't see a what the purpose is? Sorry to sound like a noob.
edit-So sorry, I got mixed up. I understood it all along, it was less complicated than I thought is all.
Re: The fun .LUA commands thread
Posted: Sun Mar 20, 2011 8:31 pm
by kinetosimpetus
It depends on whether the function returns true/false or it returns any-integer-other-than-0/0 and whether the "not" keyword can correctly reverse the second type of return.
Logically, they are the same, I just don't know enough about lua to know which one, or if both, is more correct.
Re: The fun .LUA commands thread
Posted: Sun Mar 20, 2011 9:04 pm
by asleeponduty
THEWULFMAN wrote:I think GT can do it, what do you think asleeponduty? Think we can do this? Although, I am actually pretty bad at lua.
This is doable, its not like theres an unlimited amount of things we can do
Re: The fun .LUA commands thread
Posted: Mon Mar 21, 2011 3:01 pm
by TK432
Objectives:
I know, a objective is a whole bunch of functions. But I explain each. And the existing objective are all spread all around.
--sets that you lose if you dont hold it
if self.winningTeam == self.teamDEF then
BroadcastVoiceOver("cor_obj_24")
MissionDefeat(ATT)
elseif self.winningTeam == self.teamATT then
ShowMessageText("game.objectives.complete", ATT)
BroadcastVoiceOver("cor_obj_05")
end
end
Destruction:
Destroy 2 Targets:
Hidden/Spoiler:
--This needs to be defined before the actual objective
MainframeString = "level.myg1.obj.c2-"
--copied out of mygeeto campaign, this sets text ("2 or 1 remaining")
--This defines the props, can be in the objective, too
Yourprop = Target:New{name = "abc_prop_test"}
Yourprop1 = Target:New{name = "abc_prop_test1"}
--Sets math for text "2 or 1 remaining" we defined above
Objective1.OnSingleTargetDestroyed = function(self, target)
local numTargets = self:GetNumSingleTargets()
if numTargets > 0 then
ShowMessageText(MainframeString .. (numTargets + 1), 1)
ScriptCB_SndPlaySound("MYG_obj_04")
end
Objective4.OnStart = function(self)
--adds the props as target
Objective1:AddTarget(Yourprop)
Objective1:AddTarget(Yourprop1)
--adds circle to minimap (optional)
MapAddEntityMarker("abc_prop_test", "hud_objective_icon_circle_circle", 4.0, ATT, "YELLOW", true)
MapAddEntityMarker("abc_prop_test1", "hud_objective_icon_circle_circle", 4.0, ATT, "YELLOW", true)
-- add goals to kill them
-- and let the good guys defend a little, otherwise they stay around the object too much
DEF = AddAIGoal(CIS, "Destroy", 1000, "tst_prop_test");
ATT = AddAIGoal(REP, "Defend", 50, "tst_prop_test");
end
Objective1.OnComplete = function(self)
DeleteAIGoal(ATT)
DeleteAIGoal(DEF)
if self.winningTeam == self.teamDEF then
BroadcastVoiceOver("cor_obj_24")
MissionDefeat(ATT)
elseif self.winningTeam == self.teamATT then
ShowMessageText("game.objectives.complete", ATT)
BroadcastVoiceOver("cor_obj_05")
end
--adds reinforcements
ATT_ReinforcementCount = GetReinforcementCount(ATT)
SetReinforcementCount(ATT, ATT_ReinforcementCount + 25)
end
end
Can be with multiple targets aswell just look it up in "Destroy 2 targets"
Setting up teams (just important if you don't know how):
Hidden/Spoiler:
is simple. Just add this below the existing side definitions:
[code]teamname = 3
TST = teamname
--^^ 3-letter name for team (no own side needed)[/code]
next just add units to team, again below existing ones:
[code] tst = {
team = TST,
units = 3,
reinforcements = 3,
soldier = { "imp_inf_rifleman",2, 3},
},[/code]
and finally add enemies and friends below the part above:
[code] SetTeamName(TST, "wave1")
SetTeamAsFriend(TST, IMP)
SetTeamAsFriend(IMP, TST)
SetTeamAsEnemy(TST, ALL)
SetTeamAsEnemy(ALL, TST)
ClearAIGoals(TST)
AddAIGoal(TST, "Defend",100,"cp1_hunt")[/code]
Timer:
Hidden/Spoiler:
timername= CreateTimer("timername")
SetTimerValue(timername, (60)) --60 sekonds
StartTimer(timername)
--Leave the following line out if you dont want to see the timer in-game
ShowTimer("timername")
OnTimerElapse(
function(timer)
ShowTimer(nil)
--what happens after the timer expired
DestroyTimer(timer)
end,
timername
)
Let me know if I forgot something or have a mistake
Hope that helps for your campaign.
Beat this!
Re: The fun .LUA commands thread
Posted: Wed Mar 23, 2011 7:16 pm
by asleeponduty
Random Commands
(Commands to cause random events)
When I play a map, I want different things to happen every time I play it, be it the sky or the units, its really fun to have in place.
In this example, the name of the random event is Mousetrap, and it loads different sides.
function ScriptPostLoad()
mousetrapvariable= math.random(1,3) -- runs it once, with 4 options
mousetrap() -- says the name of the command to run outside of ScriptPostLoad
--bla bla bla
end
function mousetrap()
if mousetrapvariable== 1 then
RReadDataFile("SIDE\\rep.lvl", "rep_inf_ep3_rifleman")
elseif mousetrapvariable== 2 then
ReadDataFile("dc:SIDE\\DEL.lvl", "rep_inf_ep3_rifleman")
elseif mousetrapvariable== 3 then
ReadDataFile("dc:SIDE\\BOB.lvl", "rep_inf_ep3_rifleman")
end
end
*NOTE: each of the sides has units of the same name, so REP, DEL, and BOB all have rep_inf_ep3_rifleman units. this is so it will not go spastic when it sets up teams.
functoin ScriptPostLoad()
--bla bla bla
OnObjectDamage(function(object,attacker)
--cancel if there was no attacker (maybe fell off a tower...)
if attacker == nil then return end
--cancel if the damaged object is not on the 3rd team
if GetObjectTeam(object) ~= 3 then return end
--3rd team is now an enemy of the attacker's team
SetTeamAsEnemy(3,GetObjectTeam(attacker))
end)
--bla bla bla
end
EDIT1: The Blas have been de-blaad, tks wulfman
Re: The fun .LUA commands thread
Posted: Wed Mar 23, 2011 8:58 pm
by THEWULFMAN
I would edit those bla bla bla sections to be like //bla bla bla
I don't want to see a topic start, about some with a CTD, only to find out that they did not remove the bla bla bla from their script. :plokoon:
Re: The fun .LUA commands thread
Posted: Wed Mar 23, 2011 9:38 pm
by asleeponduty
THEWULFMAN wrote:I would edit those bla bla bla sections to be like //bla bla bla
I don't want to see a topic start, about some with a CTD, only to find out that they did not remove the bla bla bla from their script. :plokoon:
That would be a pain...
Okay, I fix!
Re: The fun .LUA commands thread
Posted: Wed Mar 23, 2011 10:54 pm
by THEWULFMAN
asleeponduty wrote:
THEWULFMAN wrote:I would edit those bla bla bla sections to be like //bla bla bla
I don't want to see a topic start, about some with a CTD, only to find out that they did not remove the bla bla bla from their script. :plokoon:
That would be a pain...
Okay, I fix!
Much Thanks :plokoon:
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 8:12 am
by skelltor
THEWULFMAN wrote:This is a great idea. While I don't want to give away all my secrets,here is one KinetosImpetus came up with.
if not ScriptCB_InMultiplayer() then
ALL = math.random(1,2)
IMP = (3 - CIS)
else
IMP = 1
ALL = 2
end
If you have local teams (like ewoks or wookies), you need to have them reference the REP/CISALL/IMP names instead of ATT/DEF. Otherwise they may attack the wrong team..
What exactly would this do ingame? randomize the cp set the team starts with or what?
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 8:35 am
by kinetosimpetus
Yes.
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 8:39 am
by skelltor
Ok I tried it out on a map and it works great I might use this in bfsm if thats allright? Also what about vehicles won't this mess their spawning up?
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 9:24 am
by DarthD.U.C.K.
not if you set the vehiclenames for both Attacker and Defender e.g. ImpATK and ImpDEF .
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 9:36 am
by skelltor
? I am talking about on stock maps.
Re: The fun .LUA commands thread
Posted: Thu Mar 24, 2011 9:45 am
by DarthD.U.C.K.
yeah, you can check the vehiclespawns there with ZE, when the names are entered for both ARK and DEF it will work. otherwise you will have zo set this property via lua.