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

Action Spawning 3 demons when use lever!

Ates.tr

Im back
Joined
Nov 11, 2007
Messages
1,046
Reaction score
2
Location
Sweden
I tried one new one, also learning me , and thats why i release, first see if it work!


Code:
-- Script by Ates, [Spawn_3_Demons]
-- Edited by Gelio
-- Help by Colandus
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {X=1000, Y=1000, Z=7} -- Where to 1 Demon spawn
local pos2 = {X=1001, Y=1000, Z=7} -- Where to 2 Demon spawn
local pos3 = {X=1002, Y=1000, Z=7} -- Where to 3 Demon spawn
local mon = "demon" -- Do not edit (Spawning_Demon)
local mon2 = "demon" -- Do not edit (Spawning_Demon)
local mon3 = "demon" -- Do not edit (Spawning_Demon)


if item.itemid == 1945 then
if (getPlayerStorageValue(cid, 9999) == -1) then
doSummonCreature(mon, pos)
doSummonCreature(mon2, pos2)
doSummonCreature(mon3, pos3)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You opened the Hell.")
setPlayerStorageValue(cid,9999,1)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot open it more!.")
end
end
end


Like i said, i dont know if it work, but i hope!


/REPORT BUGS!
 
Last edited:
Bye? On end of script. There is few bugs. Script willn't run. Good script version (red - where you made an error):
Code:
-- Script by Ates, [Spawn_3_Demons]
-- Edited by Gelio
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = {X=1000, Y=1000, Z=7} -- Where to 1 Demon spawn
local pos2 = {X=1001, Y=1000, Z=7} -- Where to 2 Demon spawn
local pos3 = {X=1002, Y=1000, Z=7} -- Where to 3 Demon spawn
local mon = [COLOR="Red"]"demon"[/COLOR] -- Do not edit (Spawning_Demon)
local mon2 = [COLOR="Red"]"demon"[/COLOR] -- Do not edit (Spawning_Demon)
local mon3 = [COLOR="Red"]"demon"[/COLOR] -- Do not edit (Spawning_Demon)


if item.itemid == 1945 then
[COLOR="Red"]if ([/COLOR]getPlayerStorageValue(cid, 9999) == [COLOR="Red"]-1) then[/COLOR]
[COLOR="Red"]doSummonCreature(mon, pos)
doSummonCreature(mon2, pos2)
doSummonCreature(mon3, pos3)[/COLOR]
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You opened the Hell.")
[COLOR="Red"]setPlayerStorageValue(cid,9999,1)[/COLOR]
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot open it more!.")
[COLOR="Red"]end
end
end[/COLOR]
A lot of red :D
Many bugs, you didn't tested it: 3/10


Yours,
Gelio
 
Hmm some things I want to correct:

Code:
-- Script by Ates, [Spawn_3_Demons]
-- Edited and shortened up by Zoriath
function onUse(cid, item, fromPosition, itemEx, toPosition)

local monsters = {
   monsterpos = {[B]x[/B]=1000, [B]y[/B]=1000, [B]z[/B]=7}, --Place where the first demon should spawn.
  monstername = {"Demon"}, --The name of the monster
   monsterpos = {[B]x[/B]=1001, [B]y[/B]=1000, [B]z[/B]=7}, --Place where the second demon should spawn.
  monstername = {"Demon"}, --The name of the monster
   monsterpos = {[B]x[/B]=1002, [B]y[/B]=1000, [B]z[/B]=7}, --Place where the third demon should spawn.
  monstername = {"Demon"} --The name of the monster
}

   if item.itemid == 1945 [B]and getPlayerStorageValue(cid, 9999) == -1 then[/B] -- Checks the itemID of the lever and if the players storagevalue is correct.
      [B]for i = 1, table.maxn(monsters) do[/B] -- Table, so it doesn't summon only 1 demon.
      [B]doSummonCreature(monsters[i].monstername, monsters[i].monsterpos)[/B] -- Summons the demons.
      doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You opened the Hell.") -- Gives text message.
      setPlayerStorageValue(cid, 9999, 1) -- Sets the storagevalue of the player to 1.
      [B]doTransformItem(item.uid, + 1)[/B] -- Transforms the lever to ID 1946.
   elseif item.itemid == 1946 then -- Checks the itemID of the lever.
      [B]doTransformItem(item.uid, - 1)[/B] -- Transforms the lever back to ID 1945.
   else
      doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot open it more!.") -- Gives text message.
   [B]end[/B] -- Ends the if.
[B]end[/B] -- Ends the function.

Now you can easily add some monsters without making the script too much longer
 
Last edited:
@up
I think it will summon only one monster, because you only update variables monsterpos and monstername :p

Yours,
Gelio
 
No it won't, as you give it +1, -1. You need "item.itemid + 1" and "item.itemid - 1" but your problem still remain, it will only summon one monster.

Read more about tables...
 
No it won't, as you give it +1, -1. You need "item.itemid + 1" and "item.itemid - 1" but your problem still remain, it will only summon one monster.

Read more about tables...

Anyone said -1 but thanks anyway
 
I was referring to Zoriath's post where he uses doTransformItem wrong.
 
k . so i should have -1 ?

No, like Colandus stated, you should use - 1. Colandus, how would you edit it so it will work with tables? So you can add much more monsters without making it 20 times longer? I'm just editing the scripts to learn LUA better. Would it be more like
Code:
for i = 1, #monsters do
? ;)
 
Last edited:
PHP:
-- Script by Ates, [Spawn_3_Demons]
-- Edited and shortened up by Zoriath
local monsters = {
	{"Demon", {x=1000, y=1000, z=7}},
	{"Demon", {x=1001, y=1000, z=7}},
	{"Demon", {x=1002, y=1000, z=7}}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 and getPlayerStorageValue(cid, 9999) ~= TRUE then -- Checks the itemID of the lever and if the players storagevalue is correct.
		for _, v in ipairs(monsters) do -- Table, so it doesn't summon only 1 demon.
			doSummonCreature(unpack(v)) -- Summons the demons.
		end
		
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You opened the Hell.") -- Gives text message.
		setPlayerStorageValue(cid, 9999, TRUE) -- Sets the storagevalue of the player to 1.
		
		doTransformItem(item.uid, item.itemid + 1) -- Transforms the lever to ID 1946.
	elseif item.itemid == 1946 then -- Checks the itemID of the lever.
		doTransformItem(item.uid, item.itemid - 1) -- Transforms the lever back to ID 1945.
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot open it more!.") -- Gives text message.
	end -- Ends the if.
end -- Ends the function.
 
Just search :I There are many tutorials about it.

What's wrong with making a script, release it to learn LUA better? Reading only doesn't learn you a lot. That's why I make scripts to learn LUA better. Do you only read things at school? I don't think so.

Edit;

Sorry, misunderstood you.
 
Last edited:
I learned how to script now, much thansk to you guys, just need a tutorial how to add time etc and a bit more things...

addEvent "tutorial": How to use addEvent()?
Storage values: Storage Values - OpenTibia Fans (note that the example was for XML servers, now it's saved in database)

How to know e.g. if an hour has passed since a certain action:
os.time() - this function will return a time that increase each second (it's seconds since 1970, but that's irrelevant). By knowing it increases each second, it also means that it has increased by 60 in a minute...

That way, you can put the os.time() in a storage value, and next time he use the item/talkaction, it will compare the current os.time() with the stored os.time().

Example:
Code:
local compareTime = 5 * 24 * 60 * 60 -- This is 5 days, in seconds. I will compare the differences of the stored os.time() with the current os.time() to see how long time ago it was stored.

local currentValue = getPlayerStorageValue(cid, 23232)
if currentValue == -1 then -- This means that it has not been set before. If I'd compare -1 with os.time it'd give me the seconds of 39 years (2009 - 1070 = 39) and it would cause my statements to fail. So what I need to do is to declare it as os.time(). This will only happen the first time.
    currentValue = os.time()
end

if (os.time() - currentValue) >= compareTime then -- This will check if the last time you did this action (e.g used item or executed talkaction) was more than 5 days ago (compareTime) by subtracting the current time with the old time.
    -- Now, we do something that should only be able to be done each 5 days, e.g. give an item.
    doPlayerAddItem(cid, itemid, count)

    -- Now, we need to update the stored time, so next time he use it, it should count that he has done this quest right now.
    setPlayerStorageValue(cid, 23232, os.time()) -- Storage value must obviously be the same as the one we check. We set it to os.time() to store the current time.
else
    -- The statement failed, which means that he done the quest within 5 days, he still need to wait.
    doPlayerSendCancel(cid, "You are not ready for this yet.")
end

Notepad++ is a must-have: http://notepad-plus.sourceforge.net/uk/site.htm
 
What's wrong with making a script, release it to learn LUA better? Reading only doesn't learn you a lot. That's why I make scripts to learn LUA better. Do you only read things at school? I don't think so.

Edit;

Sorry, misunderstood you.
It was response for Ates' question about tutorials.
PS. If everybody start creating topics with stuff only for learning this forum is change into crap.
 
Back
Top