LeOnArd0
Member
- Joined
- Jan 24, 2010
- Messages
- 76
- Reaction score
- 14
Hello guys, good night!
I've been trying to adapt some scripts to revscripts and I've had good results. But sometimes I get stuck haha.
I tried to adapt this script, however, I have 3 problems.
1. He doesn't send the message when he picks up a legendary item.
2. It is not removing the item from the first and last floors (sometimes it does, sometimes it doesn't).
3. It is returning an error in the console:
This is code:
could someone help me?
Tkss,
Leo
I've been trying to adapt some scripts to revscripts and I've had good results. But sometimes I get stuck haha.
[Tf 1x+] Event Roulette
otland.net
I tried to adapt this script, however, I have 3 problems.
1. He doesn't send the message when he picks up a legendary item.
2. It is not removing the item from the first and last floors (sometimes it does, sometimes it doesn't).
3. It is returning an error in the console:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
/data/scripts/lottery.lua:83: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/scripts/lottery.lua:83: in function </data/scripts/lottery.lua:67>
This is code:
Lua:
local decayItems = {
[1945] = 1946, [1946] = 1945
}
local slots = {
Position(32344, 32218, 4), Position(32345, 32218, 4), Position(32346, 32218, 4), Position(32347, 32218, 4), Position(32348, 32218, 4),
Position(32349, 32218, 4), Position(32350, 32218, 4)
}
local itemtable = {
[1] = {id = 2390, chance = 100},
[2] = {id = 2523, chance = 5},
[3] = {id = 2646, chance = 10},
[4] = {id = 2505, chance = 15},
[5] = {id = 2469, chance = 20},
[6] = {id = 2506, chance = 25},
[7] = {id = 2471, chance = 30},
[8] = {id = 2472, chance = 35},
[9] = {id = 5184, chance = 40},
[10] = {id = 5175, chance = 45},
[11] = {id = 5185, chance = 50},
[12] = {id = 2466, chance = 55},
[13] = {id = 2195, chance = 60},
[14] = {id = 5270, chance = 80},
[15] = {id = 5181, chance = 85},
[16] = {id = 2488, chance = 90},
[17] = {id = 2477, chance = 95},
[18] = {id = 5226, chance = 99}
}
local roulette = Action()
local function ender(cid, position)
local player = Player(cid)
local posicaofim = Position(32347, 32218, 4) -- HERE WILL APPEAR THE EFFECT, which defines the item that the player won
local item = Tile(posicaofim):getTopDownItem()
if item then
local itemId = item:getId()
posicaofim:sendMagicEffect(19)
player:addItem(itemId, 1)
end
local alavanca = Tile(position):getTopDownItem()
if alavanca then
alavanca:setActionId(18562) -- back actionid to play again.
end
if itemId == 2390 or itemId == 5185 or itemId == 2471 or itemId == 2466 or itemId == 2646 then -- check if it is the ID of the LEGENDARY item
Game.broadcastMessage('This player ' ..player:getName().. ' reward a ' ..item:getName().. ' !', MESSAGE_STATUS_WARNING) -- if it's a rare item send it on the broadcast
for _, pid in ipairs(getPlayersOnline()) do
if pid ~= cid then
pid:say("This player "..player:getName().." reward a "..item:getName().."", TALKTYPE_MONSTER_SAY) -- if not legendary, send a regular message
end
end
end
end
local function delay(position, aux)
local item = Tile(position):getTopDownItem()
if item then
local slot = aux + 1
item:moveTo(slots[slot])
end
end
local function exec(cid)
-- calculate a chance and assign an item
local rand = math.random(1, 100)
local aux, memo = 0, 0
if rand >= 1 then
for i = 1, #itemtable do
local randitemid = itemtable[i].id
local randitemchance = itemtable[i].chance
if rand >= randitemchance then
aux = aux + 1
memo = randitemchance
end
end
end
-- Step one: Create an item in the first SLOT, and delete if there is an item in the last slot.
Game.createItem(itemtable[aux].id, 1, slots[1])
slots[1]:sendMagicEffect(CONST_ME_POFF)
local item = Tile(slots[#slots]):getTopDownItem()
if item then
item:remove()
end
-- Step two: Move items to the next slot in all slots 1 to 12 for 2 > 13
local maxslot = #slots-1
local lastloop = 0
for i = maxslot, 1, -1 do
addEvent(delay, 1*1*900, slots[i], i)
end
end
function roulette.onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)
if not player then
return false
end
if not player:removeItem(5197, 1) then -- roulette item
return false
end
item:transform(decayItems[item.itemid])
item:decay()
--change actionid for use only one person
item:setActionId(18563)
local segundos = 15
local loopsize = segundos*2
for i = 1, loopsize do
addEvent(exec, 1*i*500, cid.uid)
end
addEvent(ender, (1*loopsize*500)+1000, cid.uid, fromPosition)
return true
end
roulette:aid(18562)
roulette:register()
could someone help me?
Tkss,
Leo
Last edited: