• 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 onKill Doesn't work properly

Tachi

New Member
Joined
Aug 4, 2007
Messages
376
Reaction score
2
Location
USA, Missouri
For some reason the server i am using [TFS 0.3.7 Crying Damson 9.70] the onKill Function sometimes works and sometimes it doesn't work..

Ill list the scripts iv tryed using below... Maybe something in the main sources is messed up?... but other then that would there be anything that could effect the onKill function from working properly?.....

Also when i create more then 1 onKill function neither of them will work, so what i did was craft a HUGE mod onKill script.. Which this is it
Code:
	<event type="kill" name="Zombies" event="script"><![CDATA[
		domodlib('ZombieConfig')
		domodlib('Zombielib')
		function onKill(cid, target)
			local name = getCreatureName(target):lower()
			local monster = monsters[getCreatureName(target):lower()]
			local t = inqconf.monboss[getCreatureName(target):lower()]
			if isInRange(getThingPos(cid), {x = 1536, y = 1413, z = 7}, {x = 1573, y = 1440, z = 7}) then
				setGlobalStorageValue(config.zombieCounter, getGlobalStorageValue(config.zombieCounter)-1)
				if getGlobalStorageValue(config.zombieCounter) == 0 then
					doCreatureSay(cid, "There are no Zombie Left. Please wait for the next round.", TALKTYPE_ORANGE_1)
				elseif getGlobalStorageValue(config.zombieCounter) == 1 then
					doCreatureSay(cid, "There is "..getGlobalStorageValue(config.zombieCounter).. " Zombie Left.", TALKTYPE_ORANGE_1)
				else
					doCreatureSay(cid, "There are "..getGlobalStorageValue(config.zombieCounter).. " Zombies Left.", TALKTYPE_ORANGE_1)
				end
			elseif (name == "troll" and getPlayerStorageValue(cid, 76669) == 2) then
				if getPlayerStorageValue(cid, monster) < 60 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 60 Trolls.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 60 trolls.")
					setPlayerStorageValue(cid, 21000, 1)
					setPlayerStorageValue(cid, 76669, 3)
				end
			elseif (name == "ghoul" and getPlayerStorageValue(cid, 76669) == 5) then
				if getPlayerStorageValue(cid, monster) < 100 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 100 Ghouls.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 100 ghouls.")
					setPlayerStorageValue(cid, 21001, 1)
					setPlayerStorageValue(cid, 76669, 6)
				end
			elseif ((name == "orc" or name == "orc beserker" or name == "orc leader" or name == "orc spearsman" or name == "orc warlord" or name == "orc warrior" or name == "orc rider" or name == "orc shaman") and getPlayerStorageValue(cid, 76669) == 8) then
				if getPlayerStorageValue(cid, monster) < 150 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 150 Orcs.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 150 orcs.")
					setPlayerStorageValue(cid, 21002, 1)
					setPlayerStorageValue(cid, 76669, 9)
				end
			elseif ((name == "minotaur" or name == "minotaur archer" or name == "minotaur guard" or name == "minotaur mage") and getPlayerStorageValue(cid, 76669) == 11) then
				if getPlayerStorageValue(cid, monster) < 200 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 200 minotaurs.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 200 minotaurs.")
					setPlayerStorageValue(cid, 21003, 1)
					setPlayerStorageValue(cid, 76669, 12)
				end
			elseif ((name == "dwarf" or name == "dwarf soldier" or name == "dwarf guard" or name == "dwarf geomancer") and getPlayerStorageValue(cid, 76669) == 14) then
				if getPlayerStorageValue(cid, monster) < 300 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 300 Dwarfs.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 300 dwarfs.")
					setPlayerStorageValue(cid, 21004, 1)
					setPlayerStorageValue(cid, 76669, 15)
				end
			elseif ((name == "dragon" or name == "dragon lord" or name == "dragon hatchling" or name == "dragon lord hatchling") and getPlayerStorageValue(cid, 76669) == 17) then
				if getPlayerStorageValue(cid, monster) < 500 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 500 Dragons.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 500 dragons.")
					setPlayerStorageValue(cid, 21005, 1)
					setPlayerStorageValue(cid, 76669, 18)
				end
			elseif ((name == "demon" and getPlayerStorageValue(cid, 76669) == 20) then
				if getPlayerStorageValue(cid, monster) < 500 then 
					local killedMonsters = getPlayerStorageValue(cid, monster)
					if(killedMonsters == -1) then
						killedMonsters = 1
					end
					if(killedMonsters == 0) then
						killedMonsters = 1
					end
					setPlayerStorageValue(cid, monster, killedMonsters + 1)
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed " .. (killedMonsters) .. " of 666 Demons.")
				else
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have killed 666 demons.")
					setPlayerStorageValue(cid, 21006, 1)
					setPlayerStorageValue(cid, 76669, 21)
				end
			elseif(name == "igor the recruiter") then
				local teleport = doCreateTeleport(inqconf.teleportId, t.ptp, t.pp)
				doItemSetAttribute(teleport, "uid", t.uid)
				doCreatureSay(cid, inqconf.message, TALKTYPE_ORANGE_1)
				setPlayerStorageValue(cid, 76670, 8)
				setPlayerStorageValue(cid, 21007, 1)
				addEvent(removeTeleport, 60 * 1000)
			elseif (isPlayer(target) or isSummon(target)) then -- if target is not player and summon 
					if getCreatureStorage(cid, config.kills) == -1 then -- start from 0
						doCreatureSetStorage(cid, config.kills, 0) 
					end 
					doCreatureSetStorage(cid, config.kills, getCreatureStorage(cid, config.kills) + 1) --add monster kills
					doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "So far you have "..getCreatureStorage(cid, config.kills) .. " monsters killed.") --message
			end
		return true
		end
		function removeTeleport()
			local teleport = getTileItemById({x=1470, y=1450, z=8, stackpos=1}, 1387)
			if teleport.uid > 0 then
				doRemoveItem(teleport.uid)
			end
		end
		
	]]></event>

But i tryed crafting a simple mod and regular lua script to test out, when the onKill stops working, yet nothing still happens..
MOD version
Code:
	<event type="kill" name="Zombies" event="script"><![CDATA[
		domodlib('ZombieConfig')
		domodlib('Zombielib')
		function onKill(cid, target)
			doCreatureSetStorage(cid, config.kills, getCreatureStorage(cid, config.kills) + 1) --add monster kills
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "So far you have "..getCreatureStorage(cid, config.kills) .. " monsters killed.") --message
			return true
		end


		
	]]></event>
Regular Version
Code:
function onKill(cid, target)
	doCreatureSetStorage(cid, config.kills, getCreatureStorage(cid, config.kills) + 1) --add monster kills
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "So far you have "..getCreatureStorage(cid, config.kills) .. " monsters killed.") --message
	return true
end
 
Iirc ages ago I had the same problem, I ended up using an onDeath on the creature in question with a check instead. Only problem I can see with that is if your server isnt really amazing, it might lag.
 
Back
Top