michael
New Member
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:
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