Page 1 of 1
LUA help needed
Posted: Mon May 24, 2010 9:59 pm
by myers73
Re: LUA help needed
Posted: Mon May 24, 2010 10:02 pm
by Deviss
i had it many times xD, surely end words are bad placed try moving enableheroe line up of it

Re: LUA help needed
Posted: Mon May 24, 2010 10:05 pm
by 501st_commander
Code: Select all
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)
conquest:Start()
SetUberMode(1);
testFunction = OnCharacterDeath(
function(player, killer)
SetProperty(GetCharacterClass(killer), "AddHealth", 1000) --higher than maxhealth in order to fully replinish
end
)
end
EnableSPHeroRules()
end
maybe?
Re: LUA help needed
Posted: Mon May 24, 2010 10:37 pm
by Maveritchell
You have too many "end" statements. It's good practice to write your code with a clear nesting, like you're doing, but I wonder why you thought it necessary to put your "end" (the extra one) in-line with your SetProperty command. If you meant to have an "if" statement there, you left it out.
Re: LUA help needed
Posted: Tue May 25, 2010 7:57 am
by myers73
oh yeah, I had an if statement but then decided that not how I wanted it to work.
EDIT: it munges fine, but ingame when I kill someone I dont get health.
Re: LUA help needed
Posted: Tue May 25, 2010 5:32 pm
by [RDH]Zerted
You want to add health to the killer's unit object not to its class.
Re: LUA help needed
Posted: Tue May 25, 2010 10:05 pm
by myers73
Code: Select all
testFunction = OnCharacterDeath(
function(player, killer)
SetProperty(GetCharacterUnit(killer), "AddHealth", 10)
end
)
give the unit a +10 health/sec regen rate after the first kill.
how would I make it only give health once?
EDIT:
how could GetObjectHealth be used to add health
EDIT2:
was a code that attempted to give health regen or a certain amount for a certain period of time, to reward a kill. It did not work, and I cannot generate a debug log as my disc is at a friends house.
Re: LUA help needed
Posted: Wed May 26, 2010 3:40 pm
by Fiodis
Why not use SetProperty(unit, "CurHealth", Curhealth+10)? Or something like that. It works for a single boost rather than a continue regen.
Re: LUA help needed
Posted: Wed May 26, 2010 4:21 pm
by [RDH]Zerted
The game isn't crashing, so you don't need a debug log and you don't use a CD to get one too.
AddHealth is a health regen. If you want to directly change the health of an object, use CurHealth.
Follow what Fiodis said, but use GetObjectHealth(unit)+10
So you want:
Code: Select all
testFunction = OnCharacterDeath(
function(player, killer)
if killer == nil then return end --make sure there is a killer
local unit = GetCharacterUnit(killer) --get the killer's unit object
if unit == nil then return end --make sure the killer wasn't also killed
SetProperty(unit, "CurHealth", GetObjectHealth(unit)+10) --increase the killer's unit's health by 10
end
)
Re: LUA help needed
Posted: Thu May 27, 2010 2:18 am
by lucasfart
Just curious, would anything happen if you received +10 health when you were at 100% health? Would it increase, or could you just not get anymore?
Re: LUA help needed
Posted: Thu May 27, 2010 8:23 am
by Maveritchell
lucasfart wrote:Just curious, would anything happen if you received +10 health when you were at 100% health? Would it increase, or could you just not get anymore?
It will roll over above 100% (when you have greater health than your maxhealth value it is stored in a lighter-blue flashing bar over your health bar). If you're being conscientious about your code, you'll make sure to check for hitting your maxhealth and making sure it doesn't get larger than that.
Re: LUA help needed
Posted: Thu May 27, 2010 11:45 am
by myers73
Code: Select all
testFunction = OnCharacterDeath(
function(player, killer)
if killer == nil then return end --make sure there is a killer
local unit = GetCharacterUnit(killer) --get the killer's unit object
if unit == nil then return end --make sure the killer wasn't also killed
SetProperty(unit, "CurHealth", GetObjectHealth(unit)+(MaxHealth-CurHealth))
end
)
I tried that but nothing happened, but when I replaced (MaxHealth-CurHealth) with a number it worked.
Re: LUA help needed
Posted: Thu May 27, 2010 2:08 pm
by Maveritchell
myers73 wrote:Code: Select all
testFunction = OnCharacterDeath(
function(player, killer)
if killer == nil then return end --make sure there is a killer
local unit = GetCharacterUnit(killer) --get the killer's unit object
if unit == nil then return end --make sure the killer wasn't also killed
SetProperty(unit, "CurHealth", GetObjectHealth(unit)+(MaxHealth-CurHealth))
end
)
I tried that but nothing happened, but when I replaced (MaxHealth-CurHealth) with a number it worked.
That's because you used two variables that had no definition. "MaxHealth" by itself doesn't mean anything; neither does "CurHealth."
Re: LUA help needed
Posted: Fri May 28, 2010 11:12 pm
by myers73
can a local variable that is defined in one function be called in another function?
Re: LUA help needed
Posted: Sun May 30, 2010 7:20 am
by [RDH]Zerted
Only if that other function was created in the same scope/level as the local variable. As an example, this is ok:
Code: Select all
function sayHello()
local message = "Hello"
showMsg = function()
print("showMsg() says: ", message)
end
showMsg()
end
But this won't work as expected:
Code: Select all
function sayHello()
local message = "Hello"
end
showMsg = function()
print("showMsg() says: ", message)
end
showMsg()