Changing words?

Post Reply
icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Changing words?

Post by icesteruk » Tue Mar 11, 2014 1:24 am

Unsure an easy way to explain this but I'll try my best.. in the game I play, You deal certain afflictions such as..

"rightlegmodbruised", "rightarmbroken", "rightarmbruised", "rightarmcritbruised",

My question is, How can I take away the 'bruised, broken, modbruised, critbruised' from the above and seperaet rightarm to be 'right arm' but keep record of both?

This also works for torso, rightleg, leftleg, head, leftarm.. The way im using is a BIG script and wondering if I could make it smaller.. it all runs of a list such as

combat.normal = {"rightlegmodbruised", "leftlegbroken", "leftarmbruised", "rightlegcritbruised",}

at present I'm using 3 different 'local' and gsubs to seperate them out
Code: [show] | [select all] lua
local afflimb = nextSmash[1]:gsub("rightleg", ""):gsub("rightarm", ""):gsub("leftleg", ""):gsub("leftarm", ""):gsub("head", ""):gsub("torso", "")
local hitlimb = nextSmash[1]:gsub("rightarm", "right arm"):gsub("leftarm", "left arm"):gsub("rightleg", "right leg"):gsub("leftleg", "left leg")
local teraaff = hitlimb:gsub("modbruised", ""):gsub("bruised", ""):gsub("crit", ""):gsub("broken", "")
the nextSmash[1] calls from the combat.normal on the one it can deliver..

Jor'Mox
Posts: 1099
Joined: Wed Apr 03, 2013 2:19 am

Re: Changing words?

Post by Jor'Mox » Tue Mar 11, 2014 11:50 am

You could use table lookups... like this:
Code: [show] | [select all] lua
local afflictions = {
	rightlegbruised = {"right leg", "bruised"},
	rightlegmodbruised = {"right leg", "modbruised"},
	rightlegcritbruised = {"right leg", "critbruised"},
	rightlegbroken = {"right leg", "broken"},
	
	leftlegbruised = {"left leg", "bruised"},
	leftlegmodbruised = {"left leg", "modbruised"},
	leftlegcritbruised = {"left leg", "critbruised"},
	leftlegbroken = {"left leg", "broken"},
	
	rightarmbruised = {"right arm", "bruised"},
	rightarmmodbruised = {"right arm", "modbruised"},
	rightarmcritbruised = {"right arm", "critbruised"},
	rightarmbroken = {"right arm", "broken"},
	
	leftarmbruised = {"left arm", "bruised"},
	leftarmmodbruised = {"left arm", "modbruised"},
	leftarmcritbruised = {"left arm", "critbruised"},
	leftarmbroken = {"left arm", "broken"},
	
	headbruised = {"head", "bruised"},
	headmodbruised = {"head", "modbruised"},
	headcritbruised = {"head", "critbruised"},
	headbroken = {"head", "broken"},
	
	torsobruised = {"torso", "bruised"},
	torsomodbruised = {"torso", "modbruised"},
	torsocritbruised = {"torso", "critbruised"},
	torsobroken = {"torso", "broken"},
}
local part, condition, result

result = afflictions[nextSmash[1]]
part, condition = result[1], result[2]
It is a bit larger in a sense, but it will run very quickly, is easy to debug and to modify as needed. Also, if you are dealing with this same stuff in multiple places, it could potentially save space code wise. Obviously, for the purposes of making it easy to read, I made the table declaration rather spread out, but it could be substantially condensed. Like this:
Code: [show] | [select all] lua
local afflictions = {}
for k,v in ipairs({"leftleg","leftarm","rightarm","rightleg","head","torso"}) do
	for k2, v2 in ipairs({"bruised","modbruised","critbruised","broken"}) do
		afflictions[v..v2] = {v:gsub("right","right "):gsub("left","left "), v2}
	end
end

User avatar
keneanung
Site Admin
Posts: 94
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Changing words?

Post by keneanung » Tue Mar 11, 2014 11:56 am

I'd do something like this:
Code: [show] | [select all] lua
local pattern = rex.new("^(left|right)?(arm|leg|torso|head)(modbruised|bruised|crit|broken)$")
local side, limb, aff = pattern:match(nextSmash[1])
local hitlimb = (side and (side .. " ") or "") .. limb

--[[
Now the variables contain:
aff - the affliction (modbruised, bruised...)
side - The side (left, right) or false, if no side is given (for torso and head)
limb - the limb (head, torso, arm, leg)
hitlimb - side and limb seperated by whitespace. (Use a similar thing for side and limb glued together without whitespace)
Mind you, this is untested code!

The idea behind this is to ge the three seperate parts into a variable each and recombine them as necessary.

There are probably other ways. And possibly other ways to represent what you want, but I can't suggest better representations without deeper knowledge in your system.


...And ninja'd by Jor'Mox

Jor'Mox
Posts: 1099
Joined: Wed Apr 03, 2013 2:19 am

Re: Changing words?

Post by Jor'Mox » Tue Mar 11, 2014 12:28 pm

Code: [show] | [select all] lua
local pattern = rex.new("^(left|right)?(arm|leg|torso|head)((?:mod|crit)?bruised|broken)$")
local side,limb, aff = pattern:match(nextSmash[1])
local hitlimb = (side and (side .. " ") or "") .. limb

--[[
Now the variables contain:
aff - the affliction (modbruised, bruised...)
side - The side (left, right) or false, if no side is given (for torso and head)
limb - the limb (head, torso, arm, leg)
hitlimb - side and limb seperated by whitespace. (Use a similar thing for side and limb glued together without whitespace)
Fixed the pattern for you, it wasn't catching critbruised. Otherwise it works fine.

User avatar
keneanung
Site Admin
Posts: 94
Joined: Mon Mar 21, 2011 9:36 am
Discord: keneanung#2803

Re: Changing words?

Post by keneanung » Tue Mar 11, 2014 12:33 pm

Ah. I missed that crit was actually a modifier... Yay for reading comprehension :P

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: Changing words?

Post by icesteruk » Tue Mar 11, 2014 12:40 pm

Thanks guys :)

Jor'Mox
Posts: 1099
Joined: Wed Apr 03, 2013 2:19 am

Re: Changing words?

Post by Jor'Mox » Tue Mar 11, 2014 1:10 pm

Because I'm bored, here is another way to do it:
Code: [show] | [select all] lua
local result = rex.gsub(nextSmash[1],"((right|left)(arm|leg|head|torso)((?:crit|mod)bruised|broken","%1 %2 %3")
result = string.split(result," ")
local side, limb, aff = result[1], result[2], result[3]

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests