• 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!

Lua getGuildName Problem

Vinni

New Member
Joined
Mar 6, 2011
Messages
2
Reaction score
0
Code:
[15:13:36.109] [Error - CreatureScript Interface]
[15:13:36.109] data/creaturescripts/scripts/castle_kill.lua:onDeath
[15:13:36.109] Description:
[15:13:36.109] data/lib/102-castle.lua:121: attempt to call global 'getGuildName
' (a nil value)
[15:13:36.109] stack traceback:
[15:13:36.109]  data/lib/102-castle.lua:121: in function 'Castle_endEvent'
[15:13:36.109]  data/creaturescripts/scripts/castle_kill.lua:3: in function <dat
a/creaturescripts/scripts/castle_kill.lua:1>

LUA:
function Castle_endEvent(killed, damages)
	local playersOnline = getPlayersOnline()
	local dmgCount = 0
	local message = ""
	local winner = 0
	
	if (getGlobalStorageValue(castleConfig.endedStorage) ~= 1) then
		if (killed) then
			for _,value in ipairs(Castle_getAttackers()) do
				message = 

message.."\n"..getGuildName(cid)..":"..damages[Castle_getGuildPos(value)].." 

dmg"
				if damages[Castle_getGuildPos(value)] > 

dmgCount then
					winner = value
					dmgCount = 

damages[Castle_getGuildPos(value)]
				end
			end
			doBroadcastMessage("[ Castle Event End! ]\n\n> 

Statistics " .. message .."\nWINNER:"..getGuildName(winner), 

MESSAGE_INFO_DESCR)
			
			local attackers = Castle_getAttackers()
			table.insert(attackers, 

getGlobalStorageValue(castleConfig.guildOwnStorage))
			for _, plo in ipairs(playersOnline) do
				if ((isInArray(attackers, 

getPlayerGuildId(cid)) or getGlobalStorageValue(castleConfig.guildOwnStorage) 

== getPlayerGuildId(cid)) and not(tonumber(getPlayerGuildId(cid)) == 

tonumber(winner))) then
					doRemoveCondition(cid, 

CONDITION_INFIGHT)
					doTeleportThing(cid, 

getTownTemplePosition(getPlayerTown(cid)))
				end
			end
			setGlobalStorageValue(castleConfig.guildOwnStorage, 

winner)
		else
			doBroadcastMessage("[ Castle Event End! ]\n\n> Castle 

has been saved by owner.", MESSAGE_INFO_DESCR)
		end
		setGlobalStorageValue(castleConfig.endedStorage, 1)
	end
	Castle_cleanUp()
	return true
end

Castle_kill.lua
LUA:
function onDeath(cid, corpse, killer)
	if (getCreatureName(cid) == getCastleConfig("monster")) then
		Castle_endEvent(true, damages)
	end
	-- cleanup
	damages = {0,0,0}
	return true
end

I think is because is 0.4
Someone can help me to fix this?
 
i think it dont will work, because i sended a wrong piece of code.
the correct is:
LUA:
function Castle_endEvent(killed, damages)
	local playersOnline = getPlayersOnline()
	local dmgCount = 0
	local message = ""
	local winner = 0
	
	if (getGlobalStorageValue(castleConfig.endedStorage) ~= 1) then
		if (killed) then
			for _,value in ipairs(Castle_getAttackers()) do
				message = message.."\n"..getGuildName(value)..":"..damages[Castle_getGuildPos(value)].." dmg"
				if damages[Castle_getGuildPos(value)] > dmgCount then
					winner = value
					dmgCount = damages[Castle_getGuildPos(value)]
				end
			end
			doBroadcastMessage("[ Castle Event End! ]\n\n> Statistics " .. message .."\nWINNER:"..getGuildName(winner), MESSAGE_INFO_DESCR)
			
			local attackers = Castle_getAttackers()
			table.insert(attackers, getGlobalStorageValue(castleConfig.guildOwnStorage))
			for _, pid in ipairs(playersOnline) do
				if ((isInArray(attackers, getPlayerGuildId(cid)) or getGlobalStorageValue(castleConfig.guildOwnStorage) == getPlayerGuildId(cid)) and not(tonumber(getPlayerGuildId(cid)) == tonumber(winner))) then
					doRemoveCondition(cid, CONDITION_INFIGHT)
					doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
				end
			end
			setGlobalStorageValue(castleConfig.guildOwnStorage, winner)
		else
			doBroadcastMessage("[ Castle Event End! ]\n\n> Castle has been saved by owner.", MESSAGE_INFO_DESCR)
		end
		setGlobalStorageValue(castleConfig.endedStorage, 1)
	end
	Castle_cleanUp()
	return true
end
do this anyway?
 
Need help with this too! Appreciate if someone could help me out with this.

Btw, here is the Castle_getAttackers() function:

LUA:
function Castle_getAttackers()
	local ret = {}
	local query = string.explode(getGlobalStorageValue(castleConfig.attackersStorage), ",")
	for _,value in ipairs(query) do
		if isNumber(value) then
			table.insert(ret, value)
		end
	end
	return ret
end

- - - Updated - - -

Here is the thread, I think there are more who need help.
 
Back
Top