• 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 Monster mystery box action script [SOLVED]

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
249
Solutions
3
Reaction score
30
Location
Hell
Hello OtLanders!
I need your help with this action script:
Code:
local config = {
    monsterName = 'Demon',
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local pos = getPlayerPosition(cid)
    if(fromPosition.x ~= CONTAINER_POSITION) and item.itemid == 10503 then
    spawnEffect = math.random(6, 7)
    doRemoveItem(item.uid, 1)
    doSummonCreature(monsterName, fromPosition)
    doSendMagicEffect(getCreaturePosition(ret), spawnEffect)
    elseif(fromPosition.x ~= CONTAINER_POSITION) == false and item.itemid == 10503 then
        doPlayerSendCancel(cid,"You may open this only on the ground.")
    end

    return true
end
I want this script to work in a box that summons random creatures from my OTS.
EXAMPLE: You use the box and then summons a Demon and if you use another box it summons a Medusa and even more creatures. I'm using TFS 1.2.
Thanks for all your help OtLand!

Oh craps! I just solved my problem xD
If someone is searching for this script. Try with this:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local pos = getPlayerPosition(cid)
    if(fromPosition.x ~= CONTAINER_POSITION) and item.itemid == 10503 then
    doRemoveItem(item.uid, 1)
    random = math.random(1,2)
    if random == 1 then
        doSummonCreature("Demon", fromPosition)
    elseif random == 2 then
        doSummonCreature("Dragon Lord", fromPosition)
    end
    elseif(fromPosition.x ~= CONTAINER_POSITION) == false and item.itemid == 10503 then
        doPlayerSendCancel(cid,"You may open this only on the ground.")
    end

    return true
end
If you want to add more monsters just increase the maximum of:
Code:
    random = math.random(1,2) ---> 1 to 2
example:     random = math.random(1,3) ----> 1 to 3
    random = math.random(1,10) 1 to 10
Then add monsters here:
Code:
    if random == 1 then
        doSummonCreature("Demon", fromPosition)
    elseif random == 2 then
        doSummonCreature("Dragon Lord", fromPosition)
    end
Like this...
Code:
  if random == 1 then
        doSummonCreature("Demon", fromPosition)
    elseif random == 2 then
        doSummonCreature("Dragon Lord", fromPosition)
    elseif random == 3 then
        doSummonCreature("Medusa", fromPosition)
    end
 
Last edited by a moderator:
Good to see you solved your problem and posted a solution for it good shit
 
you can add more monsters easier by using a table
Code:
local monsters = {'Demon', 'Dragon lord'}

doSummonCreature(monsters[math.random(#monsters)], fromPosition)

math.random(#monsters) will give a random index in our array
monsters[math.random(#monsters)] will access our array with the random index and give us back a monster name, which we can use to summon
 
Good to see you solved your problem and posted a solution for it good shit
Yeah, I know someone will look for this kind of script and I thank the posters when they leave a clear solution to their problem. That will improve the community of OtLand! :)
you can add more monsters easier by using a table
Code:
local monsters = {'Demon', 'Dragon lord'}

doSummonCreature(monsters[math.random(#monsters)], fromPosition)

math.random(#monsters) will give a random index in our array
monsters[math.random(#monsters)] will access our array with the random index and give us back a monster name, which we can use to summon
This worked so good, your mathrand with names is an easier way to add creatures to the script. Thanks @Xeraphus!
 
Back
Top