Postado Maio 25, 2015 10 anos Boa tarde galera.. Hoje venho pedir a ajuda em uma script que o @zipter98 disponibilizou no forum a meu pedido. Porém, teve um problema. E não sei por que, mencionei no tópico lá e não obtive resposta, não sei se ele ta com problemas pra logar e etc... Enfim, o sistema que ele fez para mim é uma loteria, que inicialmente começa com 10kk e pelo comando !apostar e escolhe um numero. A loteria é sorteada de 1~50 ! Caso a pessoa acerte o numero o premio não é enviado, o sistema menciona o nome do vencedor e o premio acumulado e não envia pra lugar nenhum, queria que enviasse para o Banco do personagem, pois pode ocorrer de não ter espaço na backpack do player. Script é este:Globalevents: local config = { cash = 10000000, --Valor inicial da loteria. limit = {1, 2}, --Número mínimo e máximo da loteria. numbers = 1, --Quantos números o player deve escolher. startTime = 1, --Tempo para as apostas serem fechadas/anunciar vencedor, em minutos. messages = { --Mensagens. "A loteria está aberta, façam suas apostas! Tempo até fechar: %d minuto(s).\nDinheiro acumulado até agora: %s.", "A loteria está fechada!\nPrêmio (individual): %s gold. Vencedor%s: %s.", "Sem vencedores na loteria!\nDinheiro acumulado [total]: %s gold.", }, storages = {9571, 9572, 9573}, } function onThink() setGlobalStorageValue(config.storages[1], 1) if getGlobalStorageValue(config.storages[2]) < 0 then setGlobalStorageValue(config.storages[2], config.cash) end broadcastMessage(config.messages[1]:format(config.startTime, pointNumber(getGlobalStorageValue(config.storages[2]))), MESSAGE_INFO_DESCR) for i = 1, config.startTime do addEvent(function() if i ~= config.startTime then broadcastMessage(config.messages[1]:format(config.startTime - i), MESSAGE_INFO_DESCR) else local sortedNumbers = {} for i = 1, config.numbers do local value = math.random(config.limit[1], config.limit[2]) if isInArray(sortedNumbers, value) then while isInArray(sortedNumbers, value) do value = math.random(config.limit[1], config.limit[2]) end end table.insert(sortedNumbers, value) end setGlobalStorageValue(config.storages[1], -1) local winners, str = getLotteryWinners(sortedNumbers, config.numbers), "" local prize = math.floor(getGlobalStorageValue(config.storages[2]) / #winners) if #winners > 0 then for i = 1, #winners do if str == "" then str = getCreatureName(winners) else str = str..(i == #winners and " e " or ", ")..getCreatureName(winners) end end end if str == "" then broadcastMessage(config.messages[3]:format(pointNumber(getGlobalStorageValue(config.storages[2]))), MESSAGE_INFO_DESCR) else broadcastMessage(config.messages[2]:format(pointNumber(prize), #winners > 1 and "es" or "", str), MESSAGE_INFO_DESCR) setGlobalStorageValue(config.storages[2], -1) for i = 1, #winners do if isPlayer(winners) then doPlayerDepositMoney(winners, prize) doPlayerSendTextMessage(winners, MESSAGE_STATUS_CONSOLE_ORANGE, "Por vencer a loteria, você recebeu: "..prize.." gold.") end end end resetStorage(config.storages[3], config.numbers) end end, i * 60 * 1000) end return true end Talkactions: local config = { limit = {1, 2}, --Número mínimo e máximo da loteria. numbers = 1, --Quantos números o player deve escolher. price = 1000000, --Preço para participar da loteria. storages = {9571, 9572, 9573}, } function onSay(cid, words, param) if getGlobalStorageValue(config.storages[1]) < 1 then doPlayerSendCancel(cid, "A loteria está fechada.") elseif getPlayerStorageValue(cid, config.storages[3]) ~= -1 then doPlayerSendCancel(cid, "Você já fez sua aposta.") elseif param == "" then doPlayerSendCancel(cid, "!apostar number1 number2 number3") elseif getPlayerMoney(cid) < config.price then doPlayerSendCancel(cid, "Você precisa de, no mínimo, "..config.price.." gold para apostar.") else local numbers = param:explode(" ") if #numbers ~= config.numbers then doPlayerSendCancel(cid, "Escolha "..config.numbers.." números, entre "..config.limit[1].." - "..config.limit[2]..".") else local str = "" for i = 1, #numbers do numbers = tonumber(numbers) if not numbers or numbers < config.limit[1] or numbers > config.limit[2] then return doPlayerSendCancel(cid, "Escolha números válidos ["..config.limit[1].." - "..config.limit[2].."].") end if str == "" then str = numbers else str = str..(i == #numbers and " e " or ", ")..numbers end end doPlayerRemoveMoney(cid, config.price) doPlayerSendTextMessage(cid, 27, "Você escolheu os números: "..str..".") for i = 0, config.numbers - 1 do setPlayerStorageValue(cid, config.storages[3] + i, numbers[i + 1]) end addGlobalStorageValue(config.storages[2], config.price) end end return true end E a pedido dele, para que eu adicionasse isto em 050-function function addGlobalStorageValue(key, addValue) local result = db.getResult("SELECT value FROM global_storage WHERE key = "..key) setGlobalStorageValue(key, getGlobalStorageValue(key) + addValue) if result:getID() ~= -1 then db.executeQuery("UPDATE global_storage SET value = value + "..addValue.." WHERE key = "..key) result:free() else db.executeQuery("INSERT INTO global_storage VALUES ("..key..", 0, "..addValue..")") end end function resetStorage(key, count) local result = db.getResult("SELECT id FROM players WHERE online < 1") if result:getID() ~= -1 then repeat for i = 0, count - 1 do db.executeQuery("UPDATE player_storage SET value = -1 WHERE key = "..key + i.." AND player_id = "..result:getDataInt("id").." AND value != -1") end until not result:next() result:free() end for _, pid in pairs(getPlayersOnline()) do for i = 0, count - 1 do if getPlayerStorageValue(pid, key + i) ~= -1 then setPlayerStorageValue(pid, key + i, -1) end end end end function getLotteryWinners(n, count) local baseStorage, winners, cidNumbers = 9573, {}, {} for _, cid in pairs(getPlayersOnline()) do if getPlayerStorageValue(cid, baseStorage) ~= -1 then cidNumbers[cid] = {} for i = 0, count - 1 do table.insert(cidNumbers[cid], getPlayerStorageValue(cid, baseStorage + i)) end if compareTables(cidNumbers[cid], n) then table.insert(winners, cid) end end end return winners end function pointNumber(number) if not number or not tonumber(number) then return false end local d = tostring(number):reverse() local z = {} for i = 1, d:len(), 3 do table.insert(z, d:sub(i, i + 2)) end return table.concat(z, "."):reverse() end Se possivel alguem me ajude a fazer o premio ser enviado para o Banco do personagem! Script do banco:NPC > Bank: <?xml version="1.0" encoding="UTF-8"?> <npc name="Banco" script="data/npc/scripts/bank.lua" walkinterval="2000" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look type="132" head="115" body="0" legs="114" feet="0" addons="3" corpse="2212"/> <parameters> <parameter key="message_greet" value="Ola |PLAYERNAME|! aqui, voce {deposit}, {withdraw} ou {transfer} seu dinheiro de sua conta bancaria. Eu posso mudar suas moedas tambem."/> <parameter key="message_alreadyfocused" value="You are drunked ? I talk with you."/> <parameter key="message_farewell" value="Adeus! Seu dinheiro esta seguro! Cuidado com o juros..MUAHAAHAH, brincadeira."/> </parameters> </npc> Script Bank: 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()) Preciso mt da ajuda de vocês pois esse sistema é unico, pelo menos por enquanto né.. e é mt legal... REP+ Obg Editado Maio 25, 2015 10 anos por brendoonh (veja o histórico de edições)
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.