• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Simple lua error

Glecko

Advanced OT User
Joined
Aug 21, 2007
Messages
1,015
Reaction score
240
Location
Spain
Code:
		doSummonMonster(cid,"Healing Totem")
		summons = getCreatureSummons(cid)
		for i=1,#summons do
			if(getCreatureName(summons[i])=="Healing Totem") then
				local totem = summons[i]
			end
		end
		doSendMagicEffect(getCreaturePosition(totem),CONST_ME_CARNIPHILA)
		setCreatureMaxHealth(totem,getPlayerLevel(cid)*10+150)
		doCreatureAddHealth(totem,getPlayerLevel(cid)*10+50)

I'm getting the error "Creature not found" for getCreaturePosition, setCreatureMaxHealth and doCreatureAddHealth (I guess because totem stays as a nil value).

How is it possible that the creature I just summoned a line ago doesn't make getCreatureName(summons)=="Healing Totem") return true? (The name of the creature ingame is "Healing Totem", too)
I guess I'm missing something really obvious, but I've been looking for hours now and I can't fix it.

Help is very much appreciated :)
 
Lua handles local variable declarations as statements. As such, you can write local declarations anywhere you can write a statement. The scope begins after the declaration and goes until the end of the block. The declaration may include an initial assignment, which works the same way as a conventional assignment: Extra values are thrown away; extra variables get nil. As a specific case, if a declaration has no initial assignment, it initializes all its variables with nil.
Lua:
doSummonMonster(cid,"Healing Totem")
local totem -- nil
for _, m in ipairs(getCreatureSummons(cid)) do
	if (getCreatureName(m) == "Healing Totem") then
		totem = m
		break
	end
end
local hp = getPlayerLevel(cid)*10+150
doSendMagicEffect(getCreaturePosition(totem),CONST_ME_CARNIPHILA)
setCreatureMaxHealth(totem, hp)
doCreatureAddHealth(totem, hp)
-- better one
--[[
for _, m in ipairs(getCreatureSummons(cid)) do
	if (getCreatureName(m) == "Healing Totem") then
		local hp = getPlayerLevel(cid)*10+150
		doSendMagicEffect(getCreaturePosition(m), CONST_ME_CARNIPHILA)
		setCreatureMaxHealth(m, hp)
		doCreatureAddHealth(m, hp)
		break
	end
end
--]]
 
Back
Top