Ir para conteúdo
Entre para seguir isso  
Miltonhit

Sacar e depositar "vip coins" ingame.

Recommended Posts

Miltonhit    4
Miltonhit

Olá caro úsuario, se você usa gesior, e armaneza "vip coins" na database, aonde o player pode comprar itens no shop do site, tenho uma novidade para você!

 

Que tal liberar as coins ingame, para o players negociarem, e até mesmo quem não tem condições de "depositar", possa comprar essas tais cois de outros players, para comprar sua premmy e etc, isso estimularia o mercado ingame, aonde os principais itens e coisas poderiam ser vendidos pelas "vip coins" entre os players...

 

[spoiler=Padrão]

Autor: Mirto, MiltonHit
Nome: Bank Vip
Versão: 1.0
Créditos: TFS e GESIOR

 

Vamos ao trabalho, primeiro duas funções super simples, para o sistema todo funcionar....em lib/050-function.lua adicione isto na ultima linha:

function addVipAccount(cid, count)  --function by Mirto, MiltonHit - otserv.com.br
           db.executeQuery("UPDATE `accounts` SET `premium_points` = premium_points + '"..count.."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end

function getVipBalance(cid)  --function by Mirto, MiltonHit - otserv.com.br
        local skpo = db.getResult("SELECT * FROM `accounts` where `name`='"..getPlayerAccount(cid).."'")
        return skpo:getDataInt("premium_points")
end

function getNumber(txt) --return number if its number and is > 0, else return 0 (function maded by Gesior)
        x = string.gsub(txt,"%a","")
        x = tonumber(x)
        if x ~= nill and x > 0 then
           return x
        else
           return 0
        end
end

 

Feito isso as funções já vão estar instaladas, agora vá até a pasta npcs/scripts crie um arquivo bank_vip.lua e adicione isto:

------SCRIPT ORIGINALMENTE CRIADO PELO TFS, E ADPTADO POR Mirto, MiltonHit -------------
   local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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 creatureSayCallback(cid, type, msg)
   if(not npcHandler:isFocused(cid)) then
       return false
   end

   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

--------------------MESSAGES------------------------------------------------------------------------------
   local id_moeda = 6527  ---MUITO IMPORTANTE, id da coin vip..

   if msgcontains(msg, 'deposit') then
       selfSay('Please tell me how much vip coins it is you would like to deposit.', cid)
       talkState[talkUser] = 1

   elseif msgcontains(msg, 'withdraw') then
       selfSay('Please tell me how much vip coins you would like to withdraw.', cid)
       talkState[talkUser] = 3

   elseif msgcontains(msg, 'balance') then
       n = getVipBalance(cid)
       if n > 1 then
          selfSay('Your balance are '..n..' vip coins.', cid)
       else
          selfSay('Your balance are '..n..' vip coin.', cid)
       end
       talkState[talkUser] = 0

----------------------DEPOSIT-------------------------------------------------------
   elseif talkState[talkUser] == 1 then
       if msgcontains(msg, 'all') then
           n = getPlayerItemCount(cid, id_moeda)
           if n < 1 then
              selfSay('You dont have vip coins to deposit.', cid)
              talkState[talkUser] = 0
              return true
           elseif n == 1 then
              selfSay('Do you want deposit '..n..' vip coin?', cid)
           elseif n > 1 then       
              selfSay('Do you want deposit '..n..' vip coins?', cid)
           end
           talkState[talkUser] = 2            
       else
           n = getNumber(msg)
              if n < 1 then
                 selfSay('You cant deposit values less than zero.', cid)
                 talkState[talkUser] = 1
                 return true
              elseif n > 9999 then
                 selfSay('This value is too hight for deposit.', cid)
                 talkState[talkUser] = 1
                 return true
              elseif n == 1 then
                 selfSay('Do you want deposit '..n..' vip coin?', cid)
              elseif n > 1 then             
                 selfSay('Do you want deposit '..n..' vip coins?', cid)
              end
           talkState[talkUser] = 2
       end

   elseif talkState[talkUser] == 2 then
       if msgcontains(msg, 'yes') then
           if getPlayerItemCount(cid, id_moeda) >= n then
               addVipAccount(cid, n)
               doPlayerRemoveItem(cid, id_moeda, n)            
               selfSay('Thanks. Now your balance account is ' ..getVipBalance(cid)..' vip coins.', cid)
               talkState[talkUser] = 0
           else
               selfSay('You dont have this value for deposit.', cid)
               talkState[talkUser] = 0
           end
       else
               selfSay('Thats ok.', cid)
               talkState[talkUser] = 0
       end

----------------------WITHDRAW------------------------------------------------------------------------------------------------------------------------------------    

   elseif talkState[talkUser] == 3 then
       if msgcontains(msg, 'all') then
          n = getVipBalance(cid)
           if n < 1 then
              selfSay('Sorry, your balance is zero.', cid)
              talkState[talkUser] = 0
              return true
           elseif n == 1 then
              selfSay('Do you want withdraw '..n..' vip coin?', cid)
           elseif n > 1 then    
              selfSay('Do you want withdraw '..n..' vip coins?', cid)
           end
           talkState[talkUser] = 4            
       else
           n = getNumber(msg)
           if n < 1 then
              selfSay('You cant withdraw values less than zero.', cid)
              talkState[talkUser] = 3
              return true
           elseif n > 99999 then
              selfSay('This value is too hight for withdraw.', cid)
              talkState[talkUser] = 3
              return true
           elseif n == 1 then
              selfSay('Do you want withdraw '..n..' vip coin?', cid)
           elseif n > 1 then   
              selfSay('Do you want withdraw '..n..' vip coins?', cid)
           end
           talkState[talkUser] = 4
       end

   elseif talkState[talkUser] == 4 then
       if msgcontains(msg, 'yes') then
           if getVipBalance(cid) >= n then
               addVipAccount(cid, -n)
               doPlayerGiveItem(cid, id_moeda, n)
               if n == 1 then        
                  selfSay('Here you are, '..n..' vip coin. Now your balance account is ' ..getVipBalance(cid)..' vip coins.', cid)
               elseif n > 1 then
                  selfSay('Here you are, '..n..' vip coins. Now your balance account is ' ..getVipBalance(cid)..' vip coins.', cid)
               end
               talkState[talkUser] = 0
           else
               selfSay('Your account dont have that value for withdraw.', cid)
               talkState[talkUser] = 0
           end
       else
               selfSay('Ok then', cid)
               talkState[talkUser] = 0
       end
   end
end

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

 

Prontinho! Agora é só você criar um NPC xml ao seu gosto e usufluir do novo Vip Bank, esse script é totalmente exclusivo do otserv.com.br, eu não autorizo a postagem do mesmo em outro forúm.

 

Não se preoucupem com o code, ele já foi testado muitas vezes, é impossível bugar o sistema.... Ele tem todas as travas necessárias para o player não "enganar" o npc, não se esqueça de mudar o id da moeda vip no começo do script do npc, aceito criticas construtivas para diminuir o code.

 

Abraços galera!

Compartilhar este post


Link para o post
devotti    0
devotti

eu uso o premium_points funciona?

Compartilhar este post


Link para o post
Miltonhit    4
Miltonhit
eu uso o premium_points funciona?

sim senhor, o sistema todo é baseado encima dessa tabela.

Compartilhar este post


Link para o post
devotti    0
devotti

estou pondo no meu serv , obrigado rep +

Compartilhar este post


Link para o post
Vittu    5
Vittu

Nossa muito bom, sempre procurei algo assim, parabéns.

Reputado.

Compartilhar este post


Link para o post
kaelos    0
kaelos

Fiz tudo como está No tópico

mas Tenho erros acontece com DEPOSIT e WITHDRAW

 

[23/06/2012 14:31:43] [Error - Npc interface] [23/06/2012 14:31:43] data/npc/scripts/bank_vip.lua:onCreatureSay
[23/06/2012 14:31:43] Description: 
[23/06/2012 14:31:43] data/lib/050-function.lua:93: attempt to call field 'query' (a nil value)
[23/06/2012 14:31:43] stack traceback:
[23/06/2012 14:31:43]     data/lib/050-function.lua:93: in function 'addVipAccount'
[23/06/2012 14:31:43]     data/npc/scripts/bank_vip.lua:74: in function 'callback'
[23/06/2012 14:31:43]     data/npc/lib/npcsystem/npchandler.lua:383: in function 'onCreatureSay'
[23/06/2012 14:31:43]     data/npc/scripts/bank_vip.lua:9: in function <data/npc/scripts/bank_vip.lua:9>

 

Arrumei.

alterei

[left][color=#333333]function addVipAccount(cid, count)  --function by Mirto, MiltonHit - otserv.com.br
[/color][color=#333333]            db.executeQuery("UPDATE `accounts` SET `premium_points` = premium_points + '"..count.."' WHERE `name` ='"..getPlayerAccount(cid).."'")[/color][/left]

Por

function addVipAccount(cid, count)  --function by Mirto, MiltonHit - otserv.com.br
           db.[color=#008000]getResult[/color]("UPDATE `accounts` SET `premium_points` = premium_points + '"..count.."' WHERE `name` ='"..getPlayerAccount(cid).."'")

Editado por kaelos
Ps. arrumei agora funcionol perfeito

Compartilhar este post


Link para o post
Visitante
Este tópico está impedido de receber novos posts.
Entre para seguir isso  
  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×