function onCreatureAppear(cid)
end
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 NpcLookDirection(cid, direction) --1(west), 2(north), 3(east), 4(south) --
doCreatureSetLookDirection(cid, direction)
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
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
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
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
local GREET_MESSAGE = {"hi", "Hi", "hello", "Hello", "hey", "Hey"}
local BYE_MESSAGE = {"bye", "Bye", "goodbye", "Goodbye", "cya", "Cya"}
local NO_MESSAGE = {"no", "No", "nah", "Nah", "nope", "Nope"}
local YES_MESSAGE = {"yes", "Yes", "yeah", "Yeah", "ya", "Ya"}
-----Set this to the position of the counter players put their items on.----
local item1 = {x = 1000, y = 1000, z = 7, stackpos = 1} --first item on counter
local item2 = {x = 1000, y = 1000, z = 7, stackpos = 2} -- second
local item3 = {x = 1000, y = 1000, z = 7, stackpos = 3} --third
-----set this to where the player must be standing to play.--------------
local pos_player_spot = {x = 1000, y = 1000, z = 7}
local npc_pos = {x = 1000, y = 1000, z = 7} --pos of npc
----------if false: The NPC will ignore players who are in the wrong spot. if true: he will tell them they are standing in the wrong spot.
local talk_to_player_if_in_wrong_spot = false
--------Item's that can be played----------
local item_array = {1111, 1111, 1111, 1111, 1111, 1111}
----Storages can be anything...--------
local storage1 = 34111
local storage2 = 34112
local storage3 = 34113
function onCreatureSay(cid, type, msg)
if((isInArray(GREET_MESSAGE, msg)) and not (isFocused(cid)) and getDistanceTo(cid) <= 3) then
if getPlayerPosition(cid) == pos_player_spot then
selfSay("I am the Dice NPC. If you win my game you will receive 2x the items. {play}", cid)
selfSay("You must put 3 items on the counter between us.", cid)
addFocus(cid)
else
if talk_to_player_if_in_wrong_spot == false
return false
else
selfSay("You must be standing in the spot next to me to play.", cid)
return false
end
end
--------------Guess the number---------------------
elseif((isFocused(cid)) and (msg == "play") and getDistanceTo(cid) <= 3) then
selfSay("Say h or l for high or low", cid)
elseif((isFocused(cid)) and (msg == "h") or (msg == "high") and getDistanceTo(cid) <= 3) then
local roll = math.random(1, 6)
if isInArray(item_array, getThingFromPos(item1)) then
if isInArray(item_array, getThingFromPos(item2)) then
if isInArray(item_array, getThingFromPos(item3)) then
local player_item1 = getThingFromPos(item1)
local player_item2 = getThingFromPos(item2)
local player_item3 = getThingFromPos(item3)
setPlayerStorageValue(cid, storage1, player_item1)
setPlayerStorageValue(cid, storage2, player_item2)
setPlayerStorageValue(cid, storage3, player_item3)
doRemoveItem(item1)
doRemoveItem(item2)
doRemoveItem(item3)
if roll >= 5 then
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
doSendMagicEffect(npc_pos, math.random(1, 30))
doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
selfSay("You have WON! Here is your reward.", cid)
setPlayerStorageValue(cid, storage1, 0)
setPlayerStorageValue(cid, storage2, 0)
setPlayerStorageValue(cid, storage3, 0)
selfSay("Would you like to {play} again?", cid)
else
selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
setPlayerStorageValue(cid, storage1, 0)
setPlayerStorageValue(cid, storage2, 0)
setPlayerStorageValue(cid, storage3, 0)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
elseif((isFocused(cid)) and (msg == "l") or (msg == "low") and getDistanceTo(cid) <= 3) then
local roll = math.random(1, 6)
if isInArray(item_array, getThingFromPos(item1)) then
if isInArray(item_array, getThingFromPos(item2)) then
if isInArray(item_array, getThingFromPos(item3)) then
local player_item1 = getThingFromPos(item1)
local player_item2 = getThingFromPos(item2)
local player_item3 = getThingFromPos(item3)
setPlayerStorageValue(cid, storage1, player_item1)
setPlayerStorageValue(cid, storage2, player_item2)
setPlayerStorageValue(cid, storage3, player_item3)
doRemoveItem(item1)
doRemoveItem(item2)
doRemoveItem(item3)
if roll <= 4 then
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage1), 2)
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
doPlayerAddItem(cid, getPlayerStorageValue(cid, storage2), 2)
doSendMagicEffect(npc_pos, math.random(1, 30))
doSendAnimatedText(npc_pos, ""..roll, math.random(1, 30))
selfSay("You have WON! Here is your reward.", cid)
setPlayerStorageValue(cid, storage1, 0)
setPlayerStorageValue(cid, storage2, 0)
setPlayerStorageValue(cid, storage3, 0)
selfSay("Would you like to {play} again?", cid)
else
selfSay("You have lost with a roll of "..roll..". Better luck next time.", cid)
setPlayerStorageValue(cid, storage1, 0)
setPlayerStorageValue(cid, storage2, 0)
setPlayerStorageValue(cid, storage3, 0)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
else
selfSay("One of your items cannot be played. You can only play donation items.", cid)
end
--bye message
elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
selfSay("Good-bye.", cid)
closeShopWindow(cid)
removeFocus(cid)
end
end