Before and After: Lylek Drone
Here's an example of a mob with some progs, and what they'd look like once converted to lua. Note that each lua block would be combined into a single lprog, they're just separated here for easier comparison.
Fight Prog
1>fight_prog 99
if rand(13)
mpecho The lylek drone lashes out violently with a tentacle!
if isaffected($n) == sanctuary
mpechoat $n Your serene vitality softens the creature's blow.
mpdamage $n 75
else
if isaffected($n) == shockshield
mpechoat $n Harnessing your fury, you ignore the pain of the creature's blow.
mpdamage $n 75
else
mpdamage $n 150
endif
endif
endif
self:onFight(function(self, target) if math.random(100) <= 13 then -- Using {} tokens in echo means we can put the name of the mob and target -- in easily, rather than typing out any names here. self:echo("{1} lashes out violently at {2} with a tentacle!", self, target) -- Note that we don't check for damage-reducing effects because this damage -- function automatically accounts for them. -- Also, let's make it a little fancier by randomizing the damage. -- Instead of always 150, this will be 101-200 target:damage(100+math.random(100), self) end end)
Death Prog
2>death_prog 100
mpgain $n 3 20000
self:onDeath(function(self, killer) killer:gainExp("bounty hunting", 20000) end)
Greet Prog
3>all_greet_prog 100
if ispc($n)
mpecho A Lylek drone snarls with a high pitched, aggressive hiss!
mpkill $n
endif
self:onGreet(function(self, ch) if ch:isPC() then self:echo("{1} snarls with a high pitched, aggressive hiss!", self) self:attack(ch) end end)
Death-on-Stun Prog
4>act_prog 'is stunned, but will probably recover.'
mpdamage $n 800
self:onAct("is stunned, but will probably recover", function(self, ch) -- Let's add a message so it's less mysterious to others in the room. self:echo("{1} capitalizes on {2.'s} injuries and unleashes a sudden attack!", self, ch) ch:slay(self) -- We intend to hospitalize them here, so just do it directly instead of using damage end)
Anti-Aim Prog
5>act_prog 'begins drawing a bead on you!'
mpkill $n
mpecho The lylek drone lashes out violently with a tentacle!
mpforce $n stop
if isaffected($n) == sanctuary
mpechoat $n Your serene vitality softens the creature's blow.
mpdamage $n 75
else
if isaffected($n) == shockshield
mpechoat $n Harnessing your fury, you ignore the pain of the creature's blow.
mpdamage $n 75
else
mpdamage $n 150
endif
endif
self:onAct("begins drawing a bead on you!", function(self, ch) self:attack(ch) self:echo("{1} lashes out violently at {2} with a tentacle!", self, ch) ch:damage(100+math.random(100), self) -- interrupt() is a built-in function for stopping an action. When available, always use built-in -- functions like interrupt and drop rather than forcing the command, as this bypasses things that -- might block the player from executing the action normally. ch:interrupt() end)
Anti-Grab Prog
6>act_prog p grabs ahold of you!
struggle
emote lashes out with a snarl!
mpdamage $n 300
struggle
self:onAct("grabs ahold of you!", function(self, ch) self:force("struggle") self:emote("lashes out with a snarl!") ch:damage(300, self) self:force("struggle") end)