Ir para conteúdo

Featured Replies

Postado

Diga em poucas palavras a base utilizada (Nome do servidor ou nome do website).

OTX 2.9 (Baseado em TFS 0.3.7)

Qual erro está surgindo/O que você procura?

Estou querendo adicionar ao NPC que vende PROMOTION, a possibilidade de comprar 7 dias de premium account tambêm, porém não estou consigo.

Meu servidor possui o comando de comprar premmium account de 7 dias (!buypremium) acredito que seja possivel adapta-lo e adiciona-lo ao npc de promotion .

 

Você tem o código disponível? Se tiver publique-o aqui:

 

Meu atual npc de promotion que quero modificar

npc/scripts/promotion.lua:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 onPlayerEndTrade(cid)				npcHandler:onPlayerEndTrade(cid)			end
function onPlayerCloseChannel(cid)			npcHandler:onPlayerCloseChannel(cid)		end

local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
	node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, promotion = 1, text = 'Congratulations! You are now promoted.'})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())
 

 

Talkaction !buypremium

data/talkactions/scripts/buypremium.lua:

function onSay(cid, words, param)
if getPlayerPremiumDays(cid) <= 350 then
if doPlayerRemoveMoney(cid, 7000) == TRUE then
doPlayerAddPremiumDays(cid, 7)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have successful bought 7 days of premium account..")
else
doPlayerSendCancel(cid, "You dont have enough money to buy 7 days of premium account.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
else
doPlayerSendCancel(cid, "You cannot buy more than 1 year of premium account.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
end

 

 

Postado
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local npcTopic = {}
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 onPlayerEndTrade(cid)				npcHandler:onPlayerEndTrade(cid)			end
function onPlayerCloseChannel(cid)			npcHandler:onPlayerCloseChannel(cid)		end

local premium = {days = 30, cost = 10000} -- days = dias de premium comprados, cost = valor em gold coins

function creatureSayCallback(cid, type, msg)
    local talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    if msgcontains(msg, "premium") then
        if not isPremium(cid) then
            npcHandler:say("Do you want to buy ".. premium.days .." premium days for ".. premium.cost .. " gold coins?", cid)
            npcTopic[talkUser] = 1
        else
            npcHandler:say("You are already a premium player.", cid)
            npcTopic[talkUser] = 0
        end
    elseif msgcontains(msg, "yes") and npcTopic[talkUser] == 1 then
        if doPlayerRemoveMoney(cid, premium.cost) then
            npcHandler:say("Here you go, as I promised.", cid)
            doPlayerAddPremiumDays(cid, premium.days)
            doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_GREEN)
        else
            npcHandler:say("You do not have ".. premium.cost .." gold coins.", cid)
        end
        npcTopic[talkUser] = 0
    elseif msgcontains(msg, "no") and npcTopic[talkUser] == 1 then
        npcHandler:say("No problem. Maybe on next time.", cid)
        npcTopic[talkUser] = 0
    end
    return true
end


local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, promotion = 1, text = 'Congratulations! You are now promoted.'})
node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})

   
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Welcome, |PLAYERNAME|. Become a premium or a promoted player here!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Who is next?")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Who is next?")
npcHandler:addModule(FocusModule:new())

 

Contato:

 

Postado
  • Autor

Exatamente oque eu queria, obrigado, foi necessário somente alguns ajustes para funcionar no meu servidor.

 

O código caso alguem precise:

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

-- OTServ event handling functions start
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 onPlayerEndTrade(cid)				npcHandler:onPlayerEndTrade(cid)			end
function onPlayerCloseChannel(cid)			npcHandler:onPlayerCloseChannel(cid)		end
-- OTServ event handling functions end
   
local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
	node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, promotion = 1, text = 'Congratulations! You are now promoted.'})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then, come back when you are ready.', reset = true})
 	
	
	function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'premium') or msgcontains(msg, 'premmy')) then

            npcHandler:say('Do you want to buy 7 days of premium account for 7k?', cid)
			talkState[talkUser] = 1
	elseif(talkState[talkUser] == 1) then
 if(msgcontains(msg, 'yes')) then
			if pay(cid,7000) then
				doPlayerAddPremiumDays(cid, 7)
				selfSay('You have 7 days of premium more!')
			else
				selfSay('Sorry, you do not have enough money.')
			end
 		end
		talkState[talkUser] = 0
	end
end

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

 

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.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo