• 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 Make this script take time

Bruce Leal

New Member
Joined
Nov 9, 2017
Messages
77
Reaction score
3
Hail,

Hello, this script causes the player to use the "Scroll" item, write the name of the monster, and make it appear. How can I adapt it to the monster disappear in 24 hours

Code:
function onUse(cid, item, fromPos)
  
   local cont = getItemAttribute(item.uid, "text") -- nao precisa mexer
   local summons = {"demon", "dragon", "dog", "cat", "rotworm", "morgaroth", "cyclops", "dragon lord", "son of verminor", "wolf"} -- monstros disponiveis
  
   function Summon(entity)
       if fromPos.x == 65535 and fromPos.y == 64 then
           doCreateMonster(entity, getThingPos(cid))
           doRemoveItem(item.uid)
           doSendMagicEffect(getThingPos(cid), CONST_ME_FIREWORK_YELLOW)
           return true
       else
           doCreateMonster(entity, fromPos)  
           doRemoveItem(item.uid)
           doSendMagicEffect(fromPos, CONST_ME_FIREWORK_YELLOW)
           return true
       end
       return true
   end
  
   if cont ~= nil then
       local monster = table.concat(cont:exp("%s"), " ")
       if isInArray(summons, monster) then
           Summon(monster)
           return true
       else
           doPlayerSendCancel(cid, "You can't summon this monster!")
           doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       end
   end
end

function string.exp(e, sep)
   local result = {} e:gsub("[^".. sep .."]+", function(s) table.insert(result, s:match("^%s*(.-)%s*$")) end)
   return result
end
 
Solution
Here you go, tested, works


Lua:
function Summon(entity, cid, postosumm)
local timeToDisappear =  6000

   if postosumm.x == 65535 and postosumm.y == 64 then
       postosumm = getThingPos(cid)
   end
   
   doSendMagicEffect(postosumm, CONST_ME_FIREWORK_YELLOW)
   
   local summonedMob = doCreateMonster(entity, postosumm)
   addEvent(function()
       if isCreature(summonedMob) then
        doSendMagicEffect(getThingPos(summonedMob), 13)
        doRemoveCreature(summonedMob, true)
       end
   end, timeToDisappear)
   return true
end
   

function onUse(cid, item, fromPos)

   local cont = getItemAttribute(item.uid, "text") -- nao precisa mexer
   local summons = {"demon", "dragon", "dog", "skeleton", "cat", "rotworm", "morgaroth"...
Ty this

Lua:
   function Summon(entity, cid, postosumm)
    local timeToDisappear = 1000*60*60*24
   
       if fromPos.x == 65535 and fromPos.y == 64 then
           postosumm = getThingPos(cid)
           doSendMagicEffect(getThingPos(cid), CONST_ME_FIREWORK_YELLOW)
       else
           doSendMagicEffect(fromPos, CONST_ME_FIREWORK_YELLOW)
       end
       
       local summonedMob = doCreateMonster(entity, postosumm)
       addEvent(function()
           if isCreature(summonedMob) then
            doRemoveCreature(summonedMob, true)
           end
       end, timeToDisappear)
       doRemoveItem(item.uid)
       return true
   end
   

function onUse(cid, item, fromPos)

   local cont = getItemAttribute(item.uid, "text") -- nao precisa mexer
   local summons = {"demon", "dragon", "dog", "cat", "rotworm", "morgaroth", "cyclops", "dragon lord", "son of verminor", "wolf"} -- monstros disponiveis

   if cont ~= nil then
       local monster = table.concat(cont:exp("%s"), " ")
       if isInArray(summons, monster) then
           Summon(monster, cid, fromPos)
           return true
       else
           doPlayerSendCancel(cid, "You can't summon this monster!")
           doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       end
   end
end

function string.exp(e, sep)
   local result = {} e:gsub("[^".. sep .."]+", function(s) table.insert(result, s:match("^%s*(.-)%s*$")) end)
   return result
end
 
local timeToDisappear = 1000*60*60*24

24 = 24hours? let's test with 10 seconds? how can i put the formula to seconds?
Sorry mate, i made some mistake, fixed it, edited the post, copy it again.

Just change the numbers to whatever you like. It's in miliseconds

local timeToDisappear = 1000*60*60*24

24 = 24hours? let's test with 10 seconds? how can i put the formula to seconds?

Had to edit it again, found another mistake. Let me know if there are any errors.
 
Last edited by a moderator:
Here you go, tested, works


Lua:
function Summon(entity, cid, postosumm)
local timeToDisappear =  6000

   if postosumm.x == 65535 and postosumm.y == 64 then
       postosumm = getThingPos(cid)
   end
   
   doSendMagicEffect(postosumm, CONST_ME_FIREWORK_YELLOW)
   
   local summonedMob = doCreateMonster(entity, postosumm)
   addEvent(function()
       if isCreature(summonedMob) then
        doSendMagicEffect(getThingPos(summonedMob), 13)
        doRemoveCreature(summonedMob, true)
       end
   end, timeToDisappear)
   return true
end
   

function onUse(cid, item, fromPos)

   local cont = getItemAttribute(item.uid, "text") -- nao precisa mexer
   local summons = {"demon", "dragon", "dog", "skeleton", "cat", "rotworm", "morgaroth", "cyclops", "dragon lord", "son of verminor", "wolf"} -- monstros disponiveis

   if cont ~= nil then
       local monster = table.concat(cont:exp("%s"), " ")
       if isInArray(summons, monster) then
           Summon(monster, cid, fromPos)
            doRemoveItem(item.uid)
           return true
       else
           doPlayerSendCancel(cid, "You can't summon this monster!")
           doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       end
   end
end

function string.exp(e, sep)
   local result = {} e:gsub("[^".. sep .."]+", function(s) table.insert(result, s:match("^%s*(.-)%s*$")) end)
   return result
end
 
Last edited:
Solution
Great, you are good!
Eeer...

Anyway to use this scroll and summon only in player's house ?
I was going to look around for a function to check if in house.. then realised monsters can't go in a pz zone, so your secondary request is impossible, afaik.
 
I guess something as this is hard ... only in Source maybe ...
anyway, thanks, thanks a lot for help me in question of time to monster disappear.

Bye friends, rep+
 
Back
Top