cities = {}
cities[0] = {'vega','senja','tibia'}
cities[1] = {x=305,y=502,z=7,cost=10,prem=0}
cities[2] = {x=403,y=477,z=7,cost=10,prem=0}
cities[3] = {x=575,y=497,z=7,cost=0,prem=0}
dest=0
focus = 0
talk_start = 0
citylist = ''
i=1
while (cities[0][i] ~= nil) do
citylist = citylist .. cities[0][i]..' '
i=i+1
end
function ucfirst(str)
result=''
for word in string.gfind(str, "%S+") do
local first = string.sub(word,1,1) --get the first char of each word, uppercase
result = result .. string.upper(first) .. string.lower(string.sub(word,2)) .. ' '
end
return result
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 onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureDisappear(cid, pos)
if focus == cid then
selfSay('Good bye then.')
focus = 0
talk_start = 0
dest = 0
end
end
function onCreatureAppear(creature)
end
function onCreatureTurn(creature)
end
function onCreatureChangeOutfit(creature)
end
function onCreatureSay(cid, type, msg)
if getDistanceToCreature(cid) >= 3 then
return
end
msg = string.lower(msg)
if msgcontains(msg, 'hi') or msgcontains(msg, 'hello') then
if focus == 0 then
selfSay('Welcome on board, ' .. creatureGetName(cid) .. '! What\'s your destination?')
focus = cid
elseif focus ~= cid and focus ~= 0 then
selfSay(creatureGetName(cid) .. ', wait for your turn.')
elseif focus == cid and focus ~= 0 then
selfSay(creatureGetName(cid) .. ', I am already talking to you.')
end
end
if focus == cid and focus ~= 0 then
if dest~= 0 then
if string.find(msg, 'yes') then
if (isPremium(cid) and cities[dest].prem == 1) or cities[dest].prem == 0 then
if pay(cid,cities[dest].cost) then
selfSay('Let\'s go!')
selfSay('/send ' .. creatureGetName(cid) .. ', '..cities[dest].x..' '..cities[dest].y..' '..cities[dest].z)
focus = 0
talk_start = 0
else
selfSay('Sorry, you don\'t have enough money.')
talk_start = os.clock()
end
else
selfSay('Sorry, you are not premium.')
talk_start = os.clock()
end
else
selfSay('Where do you want to go then?')
end
dest=0
end
talk_start = os.clock()
if msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
selfSay('Good bye, ' .. creatureGetName(focus) .. '.')
focus = 0
talk_start = 0
dest=0
elseif msgcontains(msg, 'job') then
selfSay('I\'m a captain of this ship.')
elseif string.find(msg, 'destination') then
selfSay('I can take you to: '..ucfirst(citylist)..'. Arrg!')
elseif msgcontains(msg, 'about') then
selfSay('Script made by Nicaw.')
else
i=1
while (cities[0][i] ~= nil and dest==0) do
if msgcontains(msg,cities[0][i]) then dest = i end
i=i+1
end
end
if dest ~= 0 then
selfSay('Do you seek a passage to '..ucfirst(cities[0][dest])..'for '..cities[dest].cost..' gold?')
end
end
end
function onThink()
if focus > 0 then
selfLook(focus)
if getDistanceToCreature(focus) > 5 then
focus = 0
selfSay('Good bye then.')
end
end
if (os.clock() - talk_start) > 40 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
end