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

GlobalEvent Simple script but.. i think is a good idea =D!

Joined
Apr 17, 2008
Messages
1,922
Solutions
1
Reaction score
188
Location
Venezuela
Demon Castle Event (Like Mu Online [Blood Castle])

Since I said on Friday, there is the fixed, tested script and working correctly. (Tested on TFS Crying Damson 0.3.4 PL2)

Here you are people:

Execute this in SQL:
PHP:
ALTER TABLE `players` ADD `event` INT( 11 ) NOT NULL DEFAULT '0';

Add this to your function.lua:
Lua:
function getPlayerEventType(cid)
    local Info = db.getResult("SELECT `event` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
        if Info:getID() ~= LUA_ERROR then
        local event= Info:getDataInt("event")
        Info:free()
        return event
    end
     return LUA_ERROR
end

Create a file in globalevents called demon_castle.lua and add this:
Lua:
function onThink(interval, lastExecution)
	
local timeToClose = 300 --in seconds(5 minutes)
local timeToKickPlayers = 1020 --time to kick the players from the castle(1020 = 17 minutes)

	db.executeQuery("UPDATE `players` SET `event` = 1;")
	doBroadcastMessage("Demon Castle is open!, it will be closed in 5 minutes.")
	addEvent(closeCastle, (1000*timeToClose))
	addEvent(kickPlayersFromCastle, (1000*timeToKickPlayers))
	return TRUE
end

function closeCastle()

	db.executeQuery("UPDATE `players` SET `event` = 0;")
	doBroadcastMessage("Demon Castle is closed!")
	return TRUE
end

function kickPlayersFromCastle()

local position = 
{
	fromPosCastle1 = {x=81, y=121, z=7},
	toPosCastle1 = {x=84, y=128, z=7},
	fromPosCastle2 = {x=92, y=114, z=7},
	toPosCastle2 = {x=98, y=120, z=7},
	fromPosCastle3 = {x=92, y=138, z=7},
	toPosCastle3 = {x=96, y=142, z=7},
	fromPosCastle4 = {x=104, y=104, z=6},
	toPosCastle4 = {x=109, y=109, z=6},
	newPos = {x=93, y=110, z=6}
}

local weapon = {
	sword = 10022, --Divine sword of the archangel
	staff = 10023, --Divine staff of the archangel
	crossbow = 10024 --Divine crossbow of the archangel
}

local playersOnline = getPlayersOnline()

	for _, pid in ipairs(playersOnline) do
		if isInArea(getCreaturePosition(pid), position.fromPosCastle1, position.toPosCastle1) then
			doTeleportThing(pid, position.newPos)
			doPlayerRemoveItem(pid, weapon.sword, getPlayerItemCount(pid, weapon.sword))
			doPlayerRemoveItem(pid, weapon.staff, getPlayerItemCount(pid, weapon.staff))
			doPlayerRemoveItem(pid, weapon.crossbow, getPlayerItemCount(pid, weapon.crossbow))
		elseif isInArea(getCreaturePosition(pid), position.fromPosCastle2, position.toPosCastle2) then
			doTeleportThing(pid, position.newPos)
			doPlayerRemoveItem(pid, weapon.sword, getPlayerItemCount(pid, weapon.sword))
			doPlayerRemoveItem(pid, weapon.staff, getPlayerItemCount(pid, weapon.staff))
			doPlayerRemoveItem(pid, weapon.crossbow, getPlayerItemCount(pid, weapon.crossbow))
		elseif isInArea(getCreaturePosition(pid), position.fromPosCastle3, position.toPosCastle3) then
			doTeleportThing(pid, position.newPos)
			doPlayerRemoveItem(pid, weapon.sword, getPlayerItemCount(pid, weapon.sword))
			doPlayerRemoveItem(pid, weapon.staff, getPlayerItemCount(pid, weapon.staff))
			doPlayerRemoveItem(pid, weapon.crossbow, getPlayerItemCount(pid, weapon.crossbow))
		elseif isInArea(getCreaturePosition(pid), position.fromPosCastle4, position.toPosCastle4) then
			doTeleportThing(pid, position.newPos)
			doPlayerRemoveItem(pid, weapon.sword, getPlayerItemCount(pid, weapon.sword))
			doPlayerRemoveItem(pid, weapon.staff, getPlayerItemCount(pid, weapon.staff))
			doPlayerRemoveItem(pid, weapon.crossbow, getPlayerItemCount(pid, weapon.crossbow))
		end
	end
	return TRUE
end

Add this to globalevents.xml:
Lua:
	<globalevent name="DemonCastle" interval="10800" event="script" value="demon_castle.lua"/>

The NPC that will teleport you to the castle if you have the required level and item:
Lua:
<?xml version="1.0"?>

<npc name="Archangel Messenger" script="data/npc/scripts/demon_castle.lua" access="5" lookdir="1" walkinterval="2000">
    <health now="1" max="1"/>
    <look type="57" head="20" body="30" legs="40" feet="50" corpse="3128"/>
        <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|!" />
        <parameter key="message_farewell" value="Good bye." />
    </parameters>
</npc>

The npc lua-script:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local voc = {}

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg)		end
function onThink()					npcHandler:onThink()					end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid

	local eventName = ""
	local ticket = 0
	local pos = {x=0, y=0, z=0}
	if getPlayerLevel(cid) > 19 and getPlayerLevel(cid) < 61 then
		eventName = "demon castle 1"
		pos = {x=82, y=126, z=7} --casle 1 pos
		ticket = 10018 --item id of the ticket for demon castle 1
	elseif getPlayerLevel(cid) > 60 and getPlayerLevel(cid) < 81 then
		eventName = "demon castle 2"
		pos = {x=95, y=119, z=7} --casle 2 pos
		ticket = 10019 --item id of the ticket for demon castle 2
	elseif getPlayerLevel(cid) > 80 and getPlayerLevel(cid) < 101 then
		eventName = "demon castle 3"
		pos = {x=92, y=138, z=7} --casle 3 pos 
		ticket = 10020 --item id of the ticket for demon castle 3
	elseif getPlayerLevel(cid) > 100 then
		eventName = "demon castle 4"
		pos = {x=107, y=106, z=6} --casle 1 pos
		ticket = 10021 --item id of the ticket for demon castle 4
	end


	if(msgcontains(msg, 'enter') or msgcontains(msg, 'event')) then

		if getPlayerLevel(cid) < 20 then
			selfSay('You need level 20 or more to enter to the demon castle.', cid)
			talkState[talkUser] = 1
		end

		if getPlayerEventType(cid) == 1 then
			selfSay('Do you have the ticket for ' .. eventName .. '?.', cid)
			talkState[talkUser] = 1
		else
			selfSay('You cannot enter to the demon castle.', cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if getPlayerEventType(cid) == 1 then
			if getPlayerLevel(cid) > 19 then
				if getPlayerItemCount(cid, ticket) > 0 then
					selfSay('Good luck.', cid)
					doTeleportThing(cid, pos)
					doPlayerRemoveItem(cid, ticket, 1)
					talkState[talkUser] = 0
				else
					selfSay('You do not have the ticket for " .. eventName .. ".', cid)
					talkState[talkUser] = 0
				end
			else
				selfSay('You need level 20 or more to enter to the demon castle.', cid)
				talkState[talkUser] = 0
			end
		else
			selfSay('You cannot enter to the demon castle.', cid)
			talkState[talkUser] = 0
		end
		return TRUE
	end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

The npc that will give you a recompense if you give him her weapon:
Lua:
<?xml version="1.0"?>

<npc name="Wounded Archangel" script="data/npc/scripts/wounded_archangel.lua" access="5" lookdir="1" walkinterval="0">
    <health now="1" max="1"/>
    <look type="134" head="20" body="30" legs="40" feet="50" addons="3" corpse="3128"/>
        <parameters>
        <parameter key="message_greet" value="Hello courageous soldier, the creatures of the demon castle have stolen my {weapon} and without it i cannot fight, if you recover my {weapon} you will obtain a great reward!" />
        <parameter key="message_farewell" value="Good bye." />
    </parameters>
</npc>

The npc lua-script:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local voc = {}

function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)			npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)			npcHandler:onCreatureSay(cid, type, msg)		end
function onThink()					npcHandler:onThink()					end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid


	if(msgcontains(msg, 'weapon') or msgcontains(msg, 'divine weapon')) then
		if(getPlayerItemCount(cid, 10022) > 0 or getPlayerItemCount(cid, 10023) > 0 or getPlayerItemCount(cid, 10024) > 0) then
			selfSay('Really thanks!, here you are.', cid)
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_RED)
			doPlayerRemoveItem(cid, 10022, getPlayerItemCount(cid, 10031))
			doPlayerRemoveItem(cid, 10023, getPlayerItemCount(cid, 10032))
			doPlayerRemoveItem(cid, 10024, getPlayerItemCount(cid, 10033))
			doPlayerAddExperience(cid, 50000)
			talkState[talkUser] = 0	
		else
			selfSay('The creatures of the demon castle have stolen my {weapon} and without it I cannot fight, if you recover my {weapon} you will obtain a great reward!.', cid)
			talkState[talkUser] = 0
		end
	end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

These are the items required (tickets, weapons.. etc) you can create if you want. If you want create these items then follow this tutorial:

First, download the Ot Item Editor for tibia 8.42 here:
http://otland.net/f19/otitemeditor-0-3-5-8-42-a-36488/

Open your items.otb with the editor and found the itemid 1948 (parchment), click on Tools/Copy Item... (This does 4 times to create 4 tickets)

Then you will have new 4 items (from itemid 10018 to itemid 10021)

Now.. click on File/Save as... and select your items.otb and save it.

Later, add these lines to items.xml (Under itemid 10017)
Lua:
	<item id="10018" article="a" name="demon castle ticket">
		<attribute key="description" value="Needed to enter to the demon castle 1."/>
		<attribute key="weight" value="200"/>
	</item>
	<item id="10019" article="a" name="demon castle ticket">
		<attribute key="description" value="Needed to enter to the demon castle 2."/>
		<attribute key="weight" value="200"/>
	</item>
	<item id="10020" article="a" name="demon castle ticket">
		<attribute key="description" value="Needed to enter to the demon castle 3."/>
		<attribute key="weight" value="200"/>
	</item>
	<item id="10021" article="a" name="demon castle ticket">
		<attribute key="description" value="Needed to enter to the demon castle 4."/>
		<attribute key="weight" value="200"/>
	</item>

Now.. create the divine weapons (sword.. staff.. crossbow, from itemid 10022 to itemid 10024)

I create these item copying the Magic Longsword, Dark Trinity Mace and the Royal Crossbow.

Copy all these items, save your items.otb and paste this in items.xml:
Lua:
	<item id="10022" article="the" name="divine sword of the archangel">
		<attribute key="description" value="Return this weapon to the Wounded Archangel and you will have a reward."/>
		<attribute key="weight" value="3500"/>
		<attribute key="defense" value="51"/>
		<attribute key="attack" value="72"/>
	</item>
	<item id="10023" article="the" name="divine staff of the archangel">
		<attribute key="description" value="Return this weapon to the Wounded Archangel and you will have a reward."/>
		<attribute key="weight" value="7600"/>
		<attribute key="defense" value="49"/>
		<attribute key="attack" value="71"/>
	</item>
	<item id="10024" article="the" name="divine crossbow of the archangel">
		<attribute key="description" value="Return this weapon to the Wounded Archangel and you will have a reward."/>
		<attribute key="weight" value="10500"/>
		<attribute key="range" value="10"/>
		<attribute key="hitChance" value="5"/>
		<attribute key="attack" value="12"/>
	</item>

Save it and enjoy the event! :)

Pd: Please post all bugs here.
 
Last edited:
How to add chest in map and actions.xml ? And how to make 4 chest and I can take one item ? And if player go offline and come back at 20-30 minutes and demon castle is closed, then have storageID 65142 == 1 and can go to demon castle, any help ?
 
@english:
Good script dude,

Mu online rulez


@traducción a lo venezolano:
Esta arrecho el script :thumbup:

Si tienes tiempo quisiera poderte preguntar algunas cosas, es que quiero iniciarme en hacer script :p

Mu online rulez
 
[06/03/2009 01:20:41] Lua Script Error: [GlobalEvent Interface]
[06/03/2009 01:20:41] in a timer event called from:
[06/03/2009 01:20:41] data/globalevents/scripts/demon castle.lua:eek:nThink

[06/03/2009 01:20:41] data/globalevents/scripts/demon castle.lua:52: attempt to call global 'mapAreaCastle1' (a nil value)
[06/03/2009 01:20:41] stack traceback:
[06/03/2009 01:20:41] data/globalevents/scripts/demon castle.lua:52: in function <data/globalevents/scripts/demon castle.lua:37>

Somethink is wrong ?
 
wow great idea mate.... I will test it as soon as possible (tomorrow) :p reepppp

Its just rox............ can't stop comment it :p rly nice
 
then why i have this console error:

Code:
[13/06/2009 15:26:49] luaAddEvent(). Callback parameter should be a function.

[13/06/2009 15:26:49] Lua Script Error: [GlobalEvent Interface] 
[13/06/2009 15:26:49] data/globalevents/scripts/demon castle.lua:onThink

[13/06/2009 15:26:49] luaAddEvent(). Callback parameter should be a function.
 
You could change:
Lua:
addEvent(closeCastle, (1000*timeToClose))

To:
Lua:
addEvent(closeCastle, (60000*timeToClose))

Then you can just use minutes,
instead of 1020 seconds.
 
:(

Code:
[13/06/2009 16:41:50] Lua Script Error: [GlobalEvent Interface] 
[13/06/2009 16:41:50] data/globalevents/scripts/demon castle.lua:onThink

[13/06/2009 16:41:50] luaAddEvent(). Callback parameter should be a function.

Hey, somebody can help me? plz i give rep.
 
Last edited:
I agree check dont work...
darkhaos isn't better to kick all players with this storage instead of checking map?


/

Code:
19/06/2009 08:33:54] data/globalevents/scripts/volkano1.lua:47: attempt to call global 'mapAreaCastle1' (a nil value)
[19/06/2009 08:33:54] stack traceback:
[19/06/2009 08:33:54] 	data/globalevents/scripts/volkano1.lua:47: in function <data/globalevents/scripts/volkano1.lua:37>
 

Similar threads

Back
Top