Jump to content
Close
Sign in to follow this  
Serpente

Scripting [Pedido] NPC que vende premium account e promotion

Recommended Posts

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

 

 


Share this post


Link to post
Share on other sites
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:

  • Email: dwarfer@sapo.pt
  • Discord: Dwarfer#2715

 

Share this post


Link to post
Share on other sites

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())

 


Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

Open Tibia Server

Quer aprender a criar seu próprio servidor de Tibia? Então está no lugar certo, aqui você encontrará milhares de tutorias, scripts, códigos, mapas e utilitários para que você possa fazer o seu próprio servidor de Tibia partindo do zero.

Redes Sociais

Anuncie no Tibia King

Precisa de mais visibilidade em seus projetos? Quer publicidade para o seu servidor? Anuncie no Tibia King e faça sua divulgação, possuímos centenas de acessos simultâneos e milhares diários, com certeza será a sua solução! A publicação do seu anuncio é instantânea!

×
×
  • Create New...