Ir para conteúdo

Featured Replies

Postado

Boa tarde!!!

Galera estou precisando de uma ajuda em uma script.  Fiz uma raspadinha, onde o player clica e vem um valor aleatorio de dinheiro. configurei assim né, porem não ta saindo aleatorio so sai um dos valores.
Por exemplo:
ITEM - CHANCE - QUANTIDADE
2160 > 80 > 5
2160 > 70 > 10
2160 > 10 > 100

Ai só ta saindo um deles, testei varias vezes e so sai 1 dos 3 configurados...

E se tiver como, colocar para o dinheiro q sair aleatorio ir para o banco, pra caso o cara n tiver slot na bp sobrando n caia no chao.


Script
 

Spoiler

local items = {
    --[itemid] = {chance, count},         
    [2160] = {80, 50},
    [2160] = {60, 100},
    [2160] = {50, 500},
    [2160] = {40, 1000},
    [2160] = {30, 2500},
    [2160] = {10, 5000},
}
function onUse(cid, item)
    local number = math.random(1, 100)
    local _item = 0
    for itemid, chance in pairs(items) do
        if _item == 0 then
            _item = itemid
        else
            local new_chance = (chance[1] - number) > 0 and chance[1] - number or number - chance[1]
            local old_chance = (items[_item][1] - number) > 0 and items[_item][1] - number or number - items[_item][1]
            if new_chance < old_chance then
                _item = itemid
            end
        end
    end
    if _item ~= 0 then
        local count = items[_item][2]
        if not isItemStackable(_item) then
            if count > 1 then
                for i = 1, count do
                    doPlayerAddItem(cid, _item, 1)
                end
            else
                doPlayerAddItem(cid, _item, 1)
            end
        else
            doPlayerAddItem(cid, _item, count)
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: "..count.."x "..getItemNameById(_item)..(count > 1 and "s" or "")..".")
        doRemoveItem(item.uid, 1)
    end
    return true
end

 

Editado por brendoonh (veja o histórico de edições)

Resolvido por Dwarfer

Ir para solução
  • Respostas 6
  • Visualizações 477
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

Postado

Li "raspadinha" vim no tópico correndo pensando que era outra coisa, mas era só o script mesmo :'(

Fiz umas mudanças, se me permite.

 

Spoiler

local items = {
    --[chance] = {id, count}, 
    [80] = {2160, 50},
    [60] = {2160, 100},
    [50] = {2160, 500},
    [40] = {2160, 1000},
    [30] = {2160, 2500},
    [10] = {2160, 5000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local t, c, chk = {}, 0, false
for _, v in pairs(items) do 
table.insert(t, _)
end
table.sort(t)
for i, v in pairs(t) do
if math.random(1,100) < v then
c = v
break
end
end
local i, slots = items[c], 0
local s = getAllContainerFree(getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid)
if not isItemStackable(i[1]) then
slots = i[2]
else
slots = math.ceil(i[2]/100)
end
if getPlayerFreeCap(cid) <= i[2]*getItemWeightById(i[1],1) or s < slots then
chk = true
end
if chk == true and isInArray({2148, 2152, 2160}, tonumber(i[1])) then
local dp = i[1] == tonumber(2160) and (i[2]*10000) or i[1] == 2152 and (i[2]*100) or i[2]
m = "As the reward was too heavy, it was sent to your bank account."
doPlayerDepositMoney(cid, dp)
doRemoveItem(item.uid,1)
else
m = "You reward is too heavy or need more spaces in your backpack. Take out some items and try again."
end
if chk == false then
if not isItemStackable(i[1]) then
for index = 1, i[2] do
doPlayerAddItem(cid, i[1], 1)
end
else
doPlayerAddItem(cid, i[1], i[2])
end
doRemoveItem(item.uid, 1)
end
text = i[2] .. " " .. getItemNameById(i[1]) .. "" .. (i[2] > 1 and "s " or " ") 
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: ".. text ..". " .. (chk == true and m or ""))
return true
end

function getContainerSlotsFree(container) -- by vodka
return getContainerCap(container)-getContainerSize(container)
end

function getAllContainerFree(container) -- by vodka
local containers,soma = {},0
for i = 0, getContainerSize(container)-1 do
local item = getContainerItem(container, i)
if isContainer(item.uid) then
table.insert(containers, item.uid)
end
end
for _, check in pairs(containers) do
soma = soma + getContainerSlotsFree(check)
end
return (soma + getContainerSlotsFree(container))
end

 

 

Contato:

 

Postado
  • Autor
1 hora atrás, Dwarfer disse:

Li "raspadinha" vim no tópico correndo pensando que era outra coisa, mas era só o script mesmo :'(

Fiz umas mudanças, se me permite.

 

  Mostrar conteúdo oculto


local items = {
    --[chance] = {id, count}, 
    [80] = {2160, 50},
    [60] = {2160, 100},
    [50] = {2160, 500},
    [40] = {2160, 1000},
    [30] = {2160, 2500},
    [10] = {2160, 5000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local t, c, chk = {}, 0, false
for _, v in pairs(items) do 
table.insert(t, _)
end
table.sort(t)
for i, v in pairs(t) do
if math.random(1,100) < v then
c = v
break
end
end
local i, slots = items[c], 0
local s = getAllContainerFree(getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid)
if not isItemStackable(i[1]) then
slots = i[2]
else
slots = math.ceil(i[2]/100)
end
if getPlayerFreeCap(cid) <= i[2]*getItemWeightById(i[1],1) or s < slots then
chk = true
end
if chk == true and isInArray({2148, 2152, 2160}, tonumber(i[1])) then
local dp = i[1] == tonumber(2160) and (i[2]*10000) or i[1] == 2152 and (i[2]*100) or i[2]
m = "As the reward was too heavy, it was sent to your bank account."
doPlayerDepositMoney(cid, dp)
doRemoveItem(item.uid,1)
else
m = "You reward is too heavy or need more spaces in your backpack. Take out some items and try again."
end
if chk == false then
if not isItemStackable(i[1]) then
for index = 1, i[2] do
doPlayerAddItem(cid, i[1], 1)
end
else
doPlayerAddItem(cid, i[1], i[2])
end
doRemoveItem(item.uid, 1)
end
text = i[2] .. " " .. getItemNameById(i[1]) .. "" .. (i[2] > 1 and "s " or " ") 
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: ".. text ..". " .. (chk == true and m or ""))
return true
end

function getContainerSlotsFree(container) -- by vodka
return getContainerCap(container)-getContainerSize(container)
end

function getAllContainerFree(container) -- by vodka
local containers,soma = {},0
for i = 0, getContainerSize(container)-1 do
local item = getContainerItem(container, i)
if isContainer(item.uid) then
table.insert(containers, item.uid)
end
end
for _, check in pairs(containers) do
soma = soma + getContainerSlotsFree(check)
end
return (soma + getContainerSlotsFree(container))
end

 

 

auhuahuahauhauhu , pensou em outra coisa raspadinha né... 

@topic 
Eu coloquei aqui no meu server, tem um erro... quando o premio vem de 1kk vai pra bp, até ai otimo. Quando é maior q 1kk q é pra ir pro banco aparece a msg e tudo, mas qnd vou ver o saldo no banco continua o mesmo...

22:01 Banco Rox24h: Your account balance is 30.433.139 gold.

22:01 You received: 2500 crystal coins . As the reward was too heavy, it was sent to your bank account.
22:01 You received: 2500 crystal coins . As the reward was too heavy, it was sent to your bank account.
22:01 You received: 50 crystal coins . 
22:01 You received: 100 crystal coins . 
22:01 You received: 500 crystal coins . 


22:02 Banco Rox24h: Your account balance is 30.433.139 gold.

Vou postar script do meu banco..

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local moneyTo = {}
local playerTo = {}

function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)        end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)        end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                npcHandler:onThink()                end
function pointNumber(number)
    if not tonumber(number) then
        return false
    end
    local str = ""
    number = tostring(number):reverse()
    local count = 0
    for i = 1, number:len() do
        count = count + 1
        if count <= 3 then
            if str == "" then
                str = number:sub(i, i)
            else
                str = str..number:sub(i, i)
            end
        else
            count = 1
            str = str.."."..number:sub(i, i)
        end
    end
    return str:reverse()
end   
local function isValidMoney(money)
    if isNumber(money) == TRUE and money > 0 and money < 999999999 then
        return TRUE
    end
    return FALSE
end

function creatureSayCallback(cid, type, msg)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    if msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
        selfSay("You can check the {balance} of your bank account, {deposit} money or {withdraw} it. You can also {transfer} money to other characters, provided that they have a vocation.", cid)
        talkState[cid] = 0
-----------------------------------------------------------------
---------------------------- Balance ----------------------------
-----------------------------------------------------------------
     elseif msgcontains(msg, 'balance') or msgcontains(msg, 'Balance') then
        selfSay('Your account balance is '..pointNumber(getPlayerBalance(cid))..' gold.', cid)
        talkState[cid] = 0
-----------------------------------------------------------------
---------------------------- Help -------------------------------
-----------------------------------------------------------------
    elseif msgcontains(msg, 'basic functions') then
        selfSay('You can check the {balance{ of your bank account, Pdeposit{ money or Pwithdraw{ it. You can also {transfer} money to othercharacters, provided that they have a vocation.', cid)
        talkState[cid] = 0
    elseif msgcontains(msg, 'advanced functions') then
        selfSay('Renting a house has never been this easy. Simply make a bid for an auction. We will check immediately if you haveenough money.', cid)
        talkState[cid] = 0
-----------------------------------------------------------------
---------------------------- Deposit ----------------------------
-----------------------------------------------------------------
    elseif msgcontains(msg, 'deposit all') then
        moneyTo[cid] = getPlayerMoney(cid)
        if moneyTo[cid] < 1 then
            selfSay('You don\'t have any money to deposit in you inventory..', cid)
            talkState[cid] = 0
        else
            selfSay('Would you really like to deposit '..pointNumber(moneyTo[cid])..' gold?', cid)
            talkState[cid] = 2
        end
    elseif msgcontains(msg, 'deposit') then
        selfSay("Please tell me how much gold it is you would like to deposit.", cid)
        talkState[cid] = 1
    elseif talkState[cid] == 1 then
        moneyTo[cid] = tonumber(msg)
        if isValidMoney(moneyTo[cid]) == TRUE then
            selfSay('Would you really like to deposit '..pointNumber(moneyTo[cid])..' gold?', cid)
            talkState[cid] = 2
        else
            selfSay('Is isnt valid amount of gold to deposit.', cid)
            talkState[cid] = 0
        end
    elseif talkState[cid] == 2 then
        if msgcontains(msg, 'yes') then
            if doPlayerDepositMoney(cid, moneyTo[cid], 1) ~= TRUE then
                selfSay('You do not have enough gold.', cid)
            else
selfSay('Alright, we have added the amount of '..pointNumber(moneyTo[cid])..' gold to your balance. You can withdraw your money anytime you want to. Your account balance is ' .. pointNumber(getPlayerBalance(cid)) .. '.', cid)
            end
        elseif msgcontains(msg, 'no') then
            selfSay('As you wish. Is there something else I can do for you?', cid)
        end
        talkState[cid] = 0
-----------------------------------------------------------------
---------------------------- Withdraw ---------------------------
-----------------------------------------------------------------
    elseif msgcontains(msg, 'withdraw') then
        selfSay("Please tell me how much gold you would like to withdraw.", cid)
        talkState[cid] = 6
    elseif talkState[cid] == 6 then
        moneyTo[cid] = tonumber(msg)
        if isValidMoney(moneyTo[cid]) == TRUE then
            selfSay('Are you sure you wish to withdraw '..pointNumber(moneyTo[cid])..' gold from your bank account?', cid)
            talkState[cid] = 7
        else
            selfSay('Is isnt valid amount of gold to withdraw.', cid)
            talkState[cid] = 0
        end
    elseif talkState[cid] == 7 then
        if msgcontains(msg, 'yes') then
            if doPlayerWithdrawMoney(cid, moneyTo[cid]) ~= TRUE then
                selfSay('There is not enough gold on your account. Your account balance is '..getPlayerBalance(cid)..'. Please tell me the amount of gold coins you would like to withdraw.', cid)
            else
                selfSay('Here you are, ' .. pointNumber(moneyTo[cid]) .. ' gold. Please let me know if there is something else I can do for you.', cid)
                talkState[cid] = 0
            end
        elseif msgcontains(msg, 'no') then
            selfSay('As you wish. Is there something else I can do for you?', cid)
            talkState[cid] = 0
        end
-----------------------------------------------------------------
---------------------------- Transfer ---------------------------
-----------------------------------------------------------------
    elseif msgcontains(msg, 'transfer') then
        selfSay("Please tell me the amount of gold you would like to transfer.", cid)
        talkState[cid] = 11
    elseif talkState[cid] == 11 then
        moneyTo[cid] = tonumber(msg)
        if isValidMoney(moneyTo[cid]) == TRUE then
            selfSay('Who would you like transfer '..moneyTo[cid]..' gold to?', cid)
            talkState[cid] = 12
        else
            selfSay('Is isnt valid amount of gold to transfer.', cid)
            talkState[cid] = 0
        end
    elseif talkState[cid] == 12 then
        playerTo[cid] = msg

        if getCreatureName(cid) == playerTo[cid] then
            selfSay('Ehm, You want transfer money to yourself? Its impossible!', cid)
            talkState[cid] = 0
            return TRUE
        end

        if playerExists(playerTo[cid]) then
            selfSay('So you would like to transfer ' .. pointNumber(moneyTo[cid]) .. ' gold to "' .. playerTo[cid] .. '" ?', cid)
            talkState[cid] = 13
        else
            selfSay('Player with name "' .. playerTo[cid] .. '" doesnt exist.', cid)
            talkState[cid] = 0
        end
    elseif talkState[cid] == 13 then
        if msgcontains(msg, 'yes') then
            if getPlayerBalance(cid) < moneyTo[cid] then
                selfSay('You dont have enought money on your bank account.', cid)
                return TRUE
            end

            if doPlayerTransferMoneyTo(cid, playerTo[cid], moneyTo[cid]) ~= TRUE then
                selfSay('This player does not exist on this world or have no vocation.', cid)
            else
           selfSay('You have transferred ' .. pointNumber(moneyTo[cid]) .. ' gold to "' .. playerTo[cid] ..' ".', cid)
                playerTo[cid] = nil
            end
        elseif msgcontains(msg, 'no') then
            selfSay('As you wish. Is there something else I can do for you?', cid)
        end
        talkState[cid] = 0
    end
    return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())  



Apareceu um erro na distro..

 

[30/08/2017 21:59:45] [Error - Action Interface] 
[30/08/2017 21:59:45] data/actions/scripts/raspadinha.lua:onUse
[30/08/2017 21:59:45] Description: 
[30/08/2017 21:59:45] data/actions/scripts/raspadinha.lua:25: attempt to index local 'i' (a nil value)
[30/08/2017 21:59:45] stack traceback:
[30/08/2017 21:59:45] 	data/actions/scripts/raspadinha.lua:25: in function <data/actions/scripts/raspadinha.lua:11>

 

Editado por brendoonh (veja o histórico de edições)

Postado
  • Solução
Spoiler

local items = {
    --[chance] = {id, count}, 
    [80] = {2160, 50},
    [60] = {2160, 100},
    [50] = {2160, 500},
    [40] = {2160, 1000},
    [30] = {2160, 2500},
    [10] = {2160, 5000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local t, c, chk = {}, 0, false
for _, v in pairs(items) do 
table.insert(t, _)
end
table.sort(t)
for _, v in pairs(t) do
if math.random(1,100) < v then
c = v
break
end
end
local i,slots = items[c], 0
if items[c] then
local s = getAllContainerFree(getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid)
if not isItemStackable(i[1]) then
slots = i[2]
else
slots = math.ceil(i[2]/100)
end
if getPlayerFreeCap(cid) <= i[2]*getItemWeightById(i[1],1) or s < slots then
chk = true
end
if chk == true and isInArray({2148, 2152, 2160}, tonumber(i[1])) then
local dp = i[1] == tonumber(2160) and (i[2]*10000) or i[1] == 2152 and (i[2]*100) or i[2]
m = "As the reward was too heavy, it was sent to your bank account."
doPlayerSetBalance(cid, getPlayerBalance(cid) + dp)
doRemoveItem(item.uid,1)
else
m = "You reward is too heavy or need more spaces in your backpack. Take out some items and try again."
end
if chk == false then
if not isItemStackable(i[1]) then
for index = 1, i[2] do
doPlayerAddItem(cid, i[1], 1)
end
else
doPlayerAddItem(cid, i[1], i[2])
end
doRemoveItem(item.uid, 1)
end
text = i[2] .. " " .. getItemNameById(i[1]) .. "" .. (i[2] > 1 and "s " or " ") 
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: ".. text .."." .. (chk == true and m or ""))
end
return true
end

function getContainerSlotsFree(container) -- by vodka
return getContainerCap(container)-getContainerSize(container)
end

function getAllContainerFree(container) -- by vodka
local containers,soma = {},0
for i = 0, getContainerSize(container)-1 do
local item = getContainerItem(container, i)
if isContainer(item.uid) then
table.insert(containers, item.uid)
end
end
for _, check in pairs(containers) do
soma = soma + getContainerSlotsFree(check)
end
return (soma + getContainerSlotsFree(container))
end

 

 

Contato:

 

Postado
  • Autor
14 horas atrás, Dwarfer disse:
  Mostrar conteúdo oculto


local items = {
    --[chance] = {id, count}, 
    [80] = {2160, 50},
    [60] = {2160, 100},
    [50] = {2160, 500},
    [40] = {2160, 1000},
    [30] = {2160, 2500},
    [10] = {2160, 5000}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
local t, c, chk = {}, 0, false
for _, v in pairs(items) do 
table.insert(t, _)
end
table.sort(t)
for _, v in pairs(t) do
if math.random(1,100) < v then
c = v
break
end
end
local i,slots = items[c], 0
if items[c] then
local s = getAllContainerFree(getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid)
if not isItemStackable(i[1]) then
slots = i[2]
else
slots = math.ceil(i[2]/100)
end
if getPlayerFreeCap(cid) <= i[2]*getItemWeightById(i[1],1) or s < slots then
chk = true
end
if chk == true and isInArray({2148, 2152, 2160}, tonumber(i[1])) then
local dp = i[1] == tonumber(2160) and (i[2]*10000) or i[1] == 2152 and (i[2]*100) or i[2]
m = "As the reward was too heavy, it was sent to your bank account."
doPlayerSetBalance(cid, getPlayerBalance(cid) + dp)
doRemoveItem(item.uid,1)
else
m = "You reward is too heavy or need more spaces in your backpack. Take out some items and try again."
end
if chk == false then
if not isItemStackable(i[1]) then
for index = 1, i[2] do
doPlayerAddItem(cid, i[1], 1)
end
else
doPlayerAddItem(cid, i[1], i[2])
end
doRemoveItem(item.uid, 1)
end
text = i[2] .. " " .. getItemNameById(i[1]) .. "" .. (i[2] > 1 and "s " or " ") 
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: ".. text .."." .. (chk == true and m or ""))
end
return true
end

function getContainerSlotsFree(container) -- by vodka
return getContainerCap(container)-getContainerSize(container)
end

function getAllContainerFree(container) -- by vodka
local containers,soma = {},0
for i = 0, getContainerSize(container)-1 do
local item = getContainerItem(container, i)
if isContainer(item.uid) then
table.insert(containers, item.uid)
end
end
for _, check in pairs(containers) do
soma = soma + getContainerSlotsFree(check)
end
return (soma + getContainerSlotsFree(container))
end

 

 

Certinho!! Valeu mesmo!!! 

Uma pequeno detalhe, caso seja simples, teria como deixar esse valor mais explicado? Por exemplo, 500k, 1kk , 25kk ou até mesmo como é no meu banco, 500.000, 1.000.000, 25.000.000 
è que acaba confundindo o valor, da forma q está rsrs

Se for mt trabalhoso, nem precisa não tá otimo!!

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo