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

Create item and magic effect on chance

Lucas Durais

New Member
Joined
Jan 13, 2017
Messages
40
Reaction score
1
Hello guys

I really want to know if I can, by chance, create in a specific tile, two different types of items and a magic effect.

In my script, it only creates the two items, and I don't know how to put the const effect among them.
This is how it looks:

Game.createItem(math.random(item1, item2), 1, position)


Thank you very much.
 
Last edited:
const effect?
you mean a magic effect?

Code:
local function sendEffect(position, effect)
    position:sendMagicEffect(effect)
    addEvent(sendEffect, 1000, position, effect)
end
you can use this to keep sending an effect every second
as for creating a random item:
Code:
local t = {itemid1, itemid2, ...}

Game.createItem(math.random(#t), 1, position)
 
I think i didn't explain it right.

I want the magic effect to also be random among the two items.
For example, when I step on a tile, starts creating this two items/ magic effect randomly.
It can appear the item 1, or the item 2, or the magic effect. All by chance and not by time.

I already have the function that makes it an event by time.

The full script is like this:


local function doCreateDummy(cid, position)
local player = Player(cid)
if not player then
return true
end

local tile = Tile(position)
if tile then
local thing = tile:getTopVisibleThing()
if thing and isInArray({18226, 18227}, thing.itemid) then
thing:remove()
end
end

if player:getStorageValue(46181) >= 5 then
player:setStorageValue(46182, 9)
return
end

Game.createItem(math.random(18226, 18227), 1, position)
event = addEvent(doCreateDummy, 2 * 1000, cid, position)
end

function onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end

if player:getStorageValue(46182) ~= 8 then
return true
end
if item.uid == 46200 then
local playerPosition = player:getPosition()
position:sendMagicEffect(CONST_ME_POFF)
doCreateDummy(player.uid, Position(playerPosition.x, playerPosition.y - 5, 10))




The only problem, is that my script only creates by chance the two items, with id 18226 and 18227. The magic effect that i wants to be part of that constant do not exist.
I want to know how to do that
 
Last edited:
Forget about it. I did it :D


I made it like if random chance >=7 then send magic effect
and if <7 then create item 1 or 2.

Thank you anyway.
 
Back
Top