Using a single Lua event for scoring

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
Whicker
Posts: 665
Joined: Tue Jun 19, 2018 9:54 pm

Using a single Lua event for scoring

Post by Whicker »

I've been playing around with using a single lua event to handle scoring, so far it works pretty well.

I wrote a bit on it here:

https://commandops.github.io/posts/lua-scoring-example/

example of the code in an action triggered by unit destroyed:
-- blue unit destroyed
local side = "Blue"
local currentScore = ScenEdit_GetScore(side)
local points = 0 --default
local unit = ScenEdit_UnitX()

if unit.type == "Weapon" then
return --exit if destroyed unit is really a weapon
end

if -- initial score setup, defaults
unit.type == "Aircraft" then points = -10
elseif
unit.type == "Ship" then points = -50
elseif
unit.type == "Submarine" then points = -50
elseif
unit.type == "Facility" then points = -5
end

if unit.subtype == '4015' or unit.subtype == '4013' or unit.subtype == '4010' then points = -250 -- lha/lpd/lsd
elseif
unit.subtype == '3401' then points = -20 --rib/mk6
elseif
unit.subtype == '2010' then points = -125 --sub
elseif
unit.subtype == '3203' then points = - 150 -- ddg
elseif
unit.subtype == '3106' then points = -175 --cg
elseif
unit.subtype == '3306' then points = -100
elseif
unit.subtype == '7002' or unit.subtype == '8001' or unit.subtype == '4002' then points = -43 -- awacs/jstar/kc135
elseif
unit.subtype == '8201' then points = -5 --scaneagle
end

if unit.name == "Air Force 1" then points = -1000
end

if string.match(unit.name, "F%-15") then points = -17
end

currentScore = currentScore + points
print(unit.name.. " ("..UnitX().classname.." Sub Type: "..unit.subtype.." ) Destroyed - Points: "..points) --not required, prints to luahistory log
ScenEdit_SetScore(side, currentScore, unit.name.. " ("..unit.classname.." Sub Type: "..unit.subtype.." ) Destroyed - Points: "..points)
Attachments
LuaScoreKeeping.zip
(58.33 KiB) Downloaded 35 times
Post Reply

Return to “Lua Legion”