• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[help] promotion npc

michael

New Member
Joined
Jun 2, 2007
Messages
122
Reaction score
0
Location
Netherlands
Hi I need some help with my promotion npc. It works fine but I want that if you say "Hell" or "Heaven" he checks for a storagevalue but I can't figure out how that works.

here is my npc so far:
Code:
local focus = 0
local talk_start = 0
local target = 0
local days = 0

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end


function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

  	if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then
 		selfSay('Welcome to the knight hall ' .. getPlayerName(cid) .. '! I sell premiums and first promotion and second promotion.')
 		focus = cid
 		talk_start = os.clock()

	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
  		selfSay('Sorry, ' .. getPlayerName(cid) .. '! I talk to you in a minute.')

  	elseif focus == cid then
		talk_start = os.clock()

		if msgcontains(msg, '1') or msgcontains(msg, 'promote') or msgcontains(msg, 'first') then
 			if getPlayerVocation(cid) > 4 then
 				selfSay('Sorry, you are already promoted.')
 				talk_state = 0
 			elseif getPlayerLevel(cid) < 20 then
				selfSay('Sorry, you need level 20 to buy promotion.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==1 or getPlayerVocation(cid) ==5 then
				selfSay('Sorry, you are a sorcerer only knights may buy promotion from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==3 or getPlayerVocation(cid) ==7 then
				selfSay('Sorry, you are a paladin only knights may buy promotion from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==2 or getPlayerVocation(cid) ==6 then
				selfSay('Sorry, you are a druid only knights may buy promotion from me.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to buy promotion.')
				talk_state = 0
			else
				selfSay('Do you want to buy promotion for 20k?')
				talk_state = 1
			end

		elseif msgcontains(msg, 'premium') or msgcontains(msg, 'premmy') then
			selfSay('Do you want to buy 7 days of premium for 7k?')
			talk_state = 2
			elseif getPlayerVocation(cid) ==1 or getPlayerVocation(cid) ==5 then
				selfSay('Sorry, you are a sorcerer only knights may buy premium from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==3 or getPlayerVocation(cid) ==7 then
				selfSay('Sorry, you are a paladin only knights may buy premium from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==2 or getPlayerVocation(cid) ==6 then
				selfSay('Sorry, you are a druid only knights may buy premium from me.')
				talk_state = 0
				
		elseif msgcontains(msg, '2') or msgcontains(msg, 'second') then
 			if getPlayerVocation(cid) > 8 then
 				selfSay('Sorry, you are already promoted.')
 				talk_state = 0
 			elseif getPlayerLevel(cid) < 220 then
				selfSay('Sorry, you need level 220 to buy promotion.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==1 or getPlayerVocation(cid) ==5 then
				selfSay('Sorry, you are a sorcerer only knights may buy promotion from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==3 or getPlayerVocation(cid) ==7 then
				selfSay('Sorry, you are a paladin only knights may buy promotion from me.')
				talk_state = 0
			elseif getPlayerVocation(cid) ==2 or getPlayerVocation(cid) ==6 then
				selfSay('Sorry, you are a druid only knights may buy promotion from me.')
				talk_state = 0
			elseif not isPremium(cid) then
				selfSay('Sorry, you must be premium to buy promotion.')
				talk_state = 0
			else
				selfSay('Are you ready for your second promotion?')
				talk_state = 3
			end
	

		elseif talk_state == 1 then
			if msgcontains(msg, 'yes') then
				if doPlayerRemoveMoney(cid,20000) then
					doPlayerSetVocation(cid, getPlayerVocation(cid)+4)
					selfSay('You are now promoted!')
				else
					selfSay('Sorry, you do not have enough money.')
				end
 			end
			talk_state = 0

		elseif talk_state == 2 then
			if msgcontains(msg, 'yes') then
				if doPlayerRemoveMoney(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
			talk_state = 0
		
		elseif talk_state == 3 then
			selfSay('Alright, before you decide if you will join the "hell" or "heaven" side. Visit http://destinytibia.servegame.com/vocations are you ready for the next step.')
			talk_state = 4
				
		elseif talk_state == 4 then
			selfSay('Ok, would you join the Hell of Heaven side?')
			talk_state = 0
				elseif msgcontains(msg, 'hell') then
					selfSay('Are you shure that you will join the Hell side? That will cost 100k')
					talk_state = 5
				elseif msgcontains(msg, 'heaven') then
					selfSay('Are you shure that you will join the Heaven side? That will cost 100k')
					talk_state = 6

	elseif talk_state == 5 then
			if msgcontains(msg, 'yes') then
				if doPlayerRemoveMoney(cid,100000) then
					doPlayerSetVocation(cid, getPlayerVocation(cid)+1)
					selfSay('You are now promoted!')
				else
					selfSay('Sorry, you do not have enough money.')
				end
 			end
			talk_state = 0
			
	elseif talk_state == 6 then
			if msgcontains(msg, 'yes') then
				if doPlayerRemoveMoney(cid,100000) then
					doPlayerSetVocation(cid, getPlayerVocation(cid)+2)
					selfSay('You are now promoted!')
				else
					selfSay('Sorry, you do not have enough money.')
				end
 			end
			talk_state = 0

  		elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then
  			selfSay('Good bye, ' .. getPlayerName(cid) .. '!')
  			focus = 0
  			talk_start = 0
  		end
  	end
end


function onCreatureChangeOutfit(creature)

end


function onThink()
	doNpcSetCreatureFocus(focus)
  	if (os.clock() - talk_start) > 30 then
  		if focus > 0 then
  			selfSay('Next Please...')
  		end
  			focus = 0
  	end
 	if focus ~= 0 then
 		if getDistanceToCreature(focus) > 5 then
 			selfSay('Good bye then.')
 			focus = 0
 		end
 	end
end
 
I'm saying this off the top of my head:

There's a function called GetPlayerStorageValue(cid,value) right? It's something like that anyway.

Here you go.
if msgcontains(msg, 'hell') then
if getPlayerStorageValue(cid,<ur storage value>) == 0 then

<do action>

end
end

Hope this gets you on the right track. If you still have problems I can post my old promo file that's in one of my RAR archives somewhere :p
 
Well since the user you use got the latest Npc system u can use this (u just need to edited it an bit)

King.xml
Code:
<npc name="The King" script="data/npc/scripts/promotion.lua" autowalk="0" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="137" head="140" body="64" legs="121" feet="76" corpse="2212"/>
	<parameters>
		<parameter key="message_farewell" value="Farewell |PLAYERNAME|!" />
	</parameters>
</npc>

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



-- 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
-- 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, promotions = {[1] = 5, [2] = 6, [3] = 7, [4] = 8}, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Allright then. Come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())
 
Well since the user you use got the latest Npc system u can use this (u just need to edited it an bit)

King.xml
Code:
<npc name="The King" script="data/npc/scripts/promotion.lua" autowalk="0" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="137" head="140" body="64" legs="121" feet="76" corpse="2212"/>
	<parameters>
		<parameter key="message_farewell" value="Farewell |PLAYERNAME|!" />
	</parameters>
</npc>

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



-- 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
-- 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, promotions = {[1] = 5, [2] = 6, [3] = 7, [4] = 8}, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Allright then. Come back when you are ready.', reset = true})

npcHandler:addModule(FocusModule:new())

If you need help about npcs then Mokerhamer is the right person to ask. :)
 
how to make new vocations to add in promote? like:
Knight: promote
King: do you want to promote to elite knight, black knight or dead knight?

i want to make this for all vocs, can somebody helpme? ^^
 
Back
Top Bottom