local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
local function getPlayerMoney(cid)
return ((getPlayerItemCount(cid, 2160) * 10000) +
(getPlayerItemCount(cid, 2152) * 100) +
getPlayerItemCount(cid, 2148))
end
function onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid)) then --Be sure he's online
closeShopWindow(cid)
end
end
end
---CUSTOM FUNCTIONS----
function getPlayerSMS(cid)
SELECT `orbs` FROM `accounts` WHERE `id` = getPlayerAccountId(cid)
end
function getPlayerOrbs(cid)
SELECT `sms` FROM `accounts` WHERE `id` = getPlayerAccountId(cid)
end
function setPlayerOrbs(cid, amount)
INSERT INTO `accounts` SET `orbs` = getPlayerOrbs(cid) + amount WHERE `id` = getPlayerAccountId(cid)
end
function setPlayerSMS(cid, amount)
INSERT INTO `accounts` SET `sms` = getPlayerSMS(cid) + amount WHERE `id` = getPlayerAccountId(cid)
end
--------SCRIPT START----------
function onCreatureSay(cid, type, msg)
if((msg == "hi") and not (isFocused(cid))) then
selfSay("Welcome to the SMS store. Would you like to see our prices?", cid, true)
addFocus(cid)
elseif((isFocused(cid)) and (msg == "yes" or msg == "prices")) then
selfSay("We sell {30} sms for 100 orbs, or {60} sms for 180 orbs.", cid)
elseif((is focused(cid)) and (msg == "30" or msg == "30 sms" or msg == "buy 30 sms")) then
if getPlayerOrbs(cid) < 30 then
selfSay("You do not have enough orbs.")
return false
else
setPlayerOrbs(cid, -100)
setPlayerSMS(cid, 30)
end
elseif((isfocused(cid)) and (msg == "60" or msg == "60 sms" or msg == "buy 60 sms"))
if getPlayerOrbs(cid) < 30 then
selfSay("You do not have enough orbs.")
return false
else
setPlayerOrbs(cid, -180)
setPlayerSMS(cid, 60)
end
elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
selfSay("Goodbye!", cid, true)
removeFocus(cid)
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerEndTrade(cid)
selfSay("It was a pleasure doing business with you.", cid)
end
function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("Hmph!")
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end