• 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!

chest game

someusername

New Member
Joined
Feb 14, 2013
Messages
24
Reaction score
1
Hello id like too request a chest game this is how it works.

A npc sends you into a room with 3 chests only 1 person can enter this room others needs to wait till its empty. To keep blockers away it says you have 10 seconds to pick a chest. Now about the game

Random chest holds a reward and the other 2 are empty but it random what chest holds the reward. Hope somebody can help me with it


Server information : 0.3.6

Edit: forgot to say if you picked 1 chest if its empty or giving reward it tps you back to the npc room
 
Last edited:
Code:
local items = {
     {2195, 1},
     {2050, 1},
     {2650, 1}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
     local chance = math.random(1, 3)
     if chance == 1 then
         chance = math.random(1, 3)
         doPlayerAddItem(cid, items[chance][1], items[chance][2])
         doCreatureSay(cid, "Congratulations you won a reward!",TALKTYPE_MONSTER)
     else
         doCreatureSay(cid, "Unfortunately, no reward from this chest!",TALKTYPE_MONSTER)
     end
     doTeleportThing(cid, {x=1457, y=1144, z=7})
     return true
end

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

local function doPlayerTpBack(cid, pos)
     if isPlayer(cid) then
         doTeleportThing(cid, pos)
     end
     return true
end

function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     if msgcontains(msg, "yes") then
         local spec = getSpectators({x=1557, y=1644, z=7}, 10, 10) -- middle position of the room
         if spec ~= nil then
             for _, s in pairs(spec) do
                 if isPlayer(s) then
                     selfSay("There is already someone in the room.", cid)
                 else
                     if doPlayerRemoveMoney(cid, 10) then
                         doTeleportThing(cid, {x=1557, y=1644, z=7}) -- where it should be teleported
                         selfSay("Good luck.", cid)
                         addEvent(doPlayerTpBack, 1000, cid, {x=1457, y=1144, z=7})
                     else
                         selfSay("You don't have enough money.", cid)
                     end
                 end
                 return true
             end
         end
     
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
but i need to make chance like 10 % to win not 1 : 3 and i've got another problem i can carry my quests chests in my backpacks ,why is it?
 
Add uniqueids to the chests in the map editor. 1 : 3 is 33% chance to get a reward from the chest, so it's like only 1 has a reward and other 2 are empty.
If you want to make the chance 10%, change 3 to 10 in local chance = math.random(1, 3). Don't change the one under that, since that is for the items.
 
Add uniqueids to the chests in the map editor. 1 : 3 is 33% chance to get a reward from the chest, so it's like only 1 has a reward and other 2 are empty.
If you want to make the chance 10%, change 3 to 10 in local chance = math.random(1, 3). Don't change the one under that, since that is for the items.
Thanks
 
Back
Top