PDA

View Full Version : Help on this sio/mas res script



Slayer2k91
06-26-2013, 08:20 PM
Hey guys, I'm trying to learn lua and I made this function to heal with mas res/exura sio, but for some reason it only works when there are no monsters on screen, and it sometimes doesn't randomize the hp correctly.
could someone that knows what they're doing take a look?

-----Pacman's sio/mas res script


local playerstoheal = {"Bubble"} --name of the players to heal
local hppct = 75 --target hp percent to heal him/mas res
local hpself = 80 --self hp percent to heal others (if below this and the nigga is close it'll mas res)
local manapcself = 40 --self mp percent to do shit


----only touch below this line if you know what the fuck you are doing----
math.randomseed(os.time())
local hppctr = hppct + math.random(-5, 5)
function checkheal ()
local specs = Self.GetSpectators(false)
for i = 1, #specs do
local healtarget = specs[i]
if healtarget:isPlayer() then
for z = 1, #playerstoheal do
if healtarget:Name() == playerstoheal[i] then
local hppctr = hppct + math.random(-5, 5)
if healtarget:HealthPercent() <= hppctr then
print("healed at "..hppctr.."% expected")
local smppc = math.floor(Self.Mana() / Self.MaxMana()*100)
if smppc >= manapcself then
local shppc = math.floor(Self.Health() / Self.MaxHealth()*100)
if shppc <= hpself then
local htpos = healtarget:Position()
local difx = math.abs(Self.Position().x - htpos.x)
local dify = math.abs(Self.Position().y - htpos.y)
local mrarea = (dify + difx)
if mrarea <= 4 and (difx <= 3) and (dify <= 3) then
if Self.CanCastSpell("exura gran mas res") then
Self.Cast("exura gran mas res", 300)
end
end
else
Self.Say("Exura sio \""..healtarget:Name())
wait(200,400)
end
end
end
end
end
end
end
end

--i dunno how to do modules with delay inside of them yet :(
while true do
checkheal()
wait(400, 800)
end

pixie_frigo
06-26-2013, 08:34 PM
;) playerstoheal[i] should be playerstoheal[z]

I cleaned up your script a little !
There is a function table.find and self.cast already checks if you can cast it or not :)
Also there is a cool lua thing:

for index,value in ipairs(table) do
end

that works the same as



for index = 1, #list do
value = list[i]
end





function checkHeal()
local spcs = Self.GetSpectators(false)
for i, healtarget in ipairs(specs) do
if healtarget:isPlayer() and table.find(playerstoheal,healtarget:Name()) then
local hppctr = hppct + math.random(-5, 5)
local smppc = math.floor(Self.Mana() / Self.MaxMana()*100)
if healtarget:HealthPercent() <= hppctr and smppc >= manapcself then
print("healed at "..tostring(hppctr).."% expected")
local shppc = math.floor(Self.Health() / Self.MaxHealth()*100)
if shppc <= hpself then
local htpos = healtarget:Position()
local difx = math.abs(Self.Position().x - htpos.x)
local dify = math.abs(Self.Position().y - htpos.y)
local mrarea = (dify + difx)
if mrarea <= 4 and (difx <= 3) and (dify <= 3) then
Self.Cast("exura gran mas res", 300)
end
else
Self.Cast("Exura sio \""..healtarget:Name())
end
end
end
end
end

Spectrus
06-26-2013, 08:38 PM
I always feel bad when it's the little things...

http://i.imgur.com/q3BRWAz.jpg

Slayer2k91
06-26-2013, 08:41 PM
Thanks for the help guys! i feel so dumb for missing that the last two days

Spectrus
06-26-2013, 08:46 PM
Thanks for the help guys! i feel so dumb for missing that the last two days

Wasn't me! Thank pixie!

pixie_frigo
06-26-2013, 08:52 PM
hehe you're welcome :)
But on things like this I would use in ipairs then you can't make small annoying mistakes like that ^^ Just tips !
But looks better then my scripts a few months back haha

Slayer2k91
06-26-2013, 09:10 PM
hehe you're welcome :)
But on things like this I would use in ipairs then you can't make small annoying mistakes like that ^^ Just tips !
But looks better then my scripts a few months back haha

thanks for the tips dude, I'm still trying to wrap my head around ipars, but i'll try to use them anyway.

Offtopic: do you think anyone would be interested in a directional spell script i made? the code is even worse than this one, but it works pretty well. (I also got lazy and didn't implement aoe runes or single target spells, but that should be easy enough), or do you guys mind taking a look at it?



EDIT: Here it is anyway.


--Pacman's shitty area spell caster thingamajig
spell = {}
area = {}



--CONFIG
spell[1] = {words = "exevo frigo hur",
manacost = 25,
area = {{0,0,0,1},
{0,1,1,1},
{1,1,1,1},
{0,1,1,1},
{0,0,0,1}},
creaturecount = 2}

spell[2] = {words = "exevo gran frigo hur",
manacost = 170,
area = {{0,1,1},
{1,1,1},
{0,1,1}},
creaturecount = 1}





--initializing shit (i'm too shit at lua to know how to do this for sure inside the script :C)
e = 0
n = 0
s = 0
w = 0
largest = 0

print("Pacman's shit directional spell caster thingamajig")

function inarea(posc, sn)
sarea = spell[sn].area
compensatey = math.ceil((#sarea/2))
for y =1, #sarea do
for x=1, #sarea[1] do
if sarea[y][x] > 0 then
correctedy = y - compensatey
if posc.x == Self.Position().x + x and posc.y == Self.Position().y + correctedy then
e = e + sarea[y][x]
end
if posc.x == Self.Position().x - x and posc.y == Self.Position().y + correctedy then
w = w + sarea[y][x]
end
if posc.x == Self.Position().x + correctedy and posc.y == Self.Position().y + x then
s = s + sarea[y][x]
end
if posc.x == Self.Position().x + correctedy and posc.y == Self.Position().y - x then
n = n + sarea[y][x]
end
end
end
end
end



function findtargets(sn)
local creatures = Self.GetSpectators(false)
for i = 1, #creatures do
local cre = creatures[i]
if cre:isMonster() then
local crepos = cre:Position()
inarea(cre:Position(), sn)
end
end
largest = e
dir = "east"
if largest < s then
largest = s
dir = "south"
end
if largest < w then
largest = w
dir = "west"
end
if largest < n then
largest = n
dir = "north"
end
scount = spell[sn].creaturecount
swords = spell[sn].words
if largest >= scount and Self.CanCastSpell(swords) then
castaspell = true
end
e = 0
n = 0
s = 0
w = 0
largest = 0
end



while true do
for sn = 1, #spell do
findtargets(sn)
if castaspell then
Walker.Delay(1200)
setTargetingEnabled(false)
wait(200, 300)
Self.Turn(dir)
wait(300, 400)
Self.Cast(spell[sn].words, spell[sn].manacost)
wait(300, 400)
setTargetingEnabled(true)
wait(1600, 1900)
castaspell = false
end
wait(200, 400)
end
end