• 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:
Power of math! Do one script, what gives you 33% chances to get the reward, then add this script into each of 3 chests. Logicially it will be the same.

Aslo, code is simple:
Code:
function onUse(cid, item)
     local r = math.random(1,100)
     if r > 66 then
          doPlayerAddItem(cid, 2195, 1) -- reward
     else
          doPlayerSendCancel(cid, "SORRY, THIS CHEST IS EMPTY")
     end
     doTeleportCreature(cid, pos)
     return true
end

To protect other players from entering this room while someone is inside you can make a simple script in movements.

Code:
getSpectators
isInArea
i tried your script but i found error with it
Code:
[29/01/2015 14:39:12] [Error - Action Interface]
[29/01/2015 14:39:12] data/actions/scripts/chestlot.lua:onUse
[29/01/2015 14:39:13] Description:
[29/01/2015 14:39:13] data/actions/scripts/chestlot.lua:8: attempt to call global 'doTeleportCreature' (a nil value)
[29/01/2015 14:39:13] stack traceback:
[29/01/2015 14:39:13]     data/actions/scripts/chestlot.lua:8: in function <data/actions/scripts/chestlot.lua:1>
@andu
 
well i got it working and edited some so if people want to use it you are free to

PHP:
function onUse(cid, item)
     local r = math.random(1,100)
     if r > 66 then
          doPlayerAddItem(cid, 2195, 1) -- reward
          doCreatureSay(cid, "Gratz",TALKTYPE_MONSTER)
     else
          doCreatureSay(cid, "SORRY, THIS CHEST IS EMPTY",TALKTYPE_MONSTER)
     end
     doTeleportThing(cid, {x=1000, y=1000, z=7})
     return true
end

thx @andu

now npc is left :)

oh before i forget how make it random between 3 items for now there is only one in it :p
 
Last edited:
well i got it working and edited some so if people want to use it you are free to

PHP:
function onUse(cid, item)
     local r = math.random(1,100)
     if r > 66 then
          doPlayerAddItem(cid, 2195, 1) -- reward
          doCreatureSay(cid, "Gratz",TALKTYPE_MONSTER)
     else
          doCreatureSay(cid, "SORRY, THIS CHEST IS EMPTY",TALKTYPE_MONSTER)
     end
     doTeleportThing(cid, {x=1000, y=1000, z=7})
     return true
end

thx @andu

now npc is left :)

oh before i forget how make it random between 3 items for now there is only one in it :p
i'm using tfs 0.3.6 and i got this errpr i think i need to change function to 0.3.6
EDITED Working fine now and about your question we can make npc to tp for random room like 10 rooms and we can make 2 chests on every room empty and only one with this script its will be lucky too
 
Last edited:
Well it is just a game not story in it just so players can try out their luck.

Player: hi
Npc: greetings playername I'm hosting a chest game. You open a chest and...suprise!!! you find your reward... or not. right click on the chest to open it. try out your luck.
Npc: Like to play? It costs 10 gold coins.
Player: yes

Tps you inside the play room..
open chest (reward) could be 3 items tped back with the text "congratulations you win :item name."
open chest( no reward) tped back with the message "unfortunately no reward from this chest"

well i agree no need to have 1 person in the room :p forget that

Or try to make it that you can only enter the room once every 24h or something like that
 
Or try to make it that you can only enter the room once every 24h or something like that
well im thinking about every 30 min but it will be all about the npc atm since ive got the chest script part ;p
i dont think so i've another idea you can make this room for cash i mean you can enter it with money so your cash on server won't die like others and will be important to gain more items from lottery ,isn't it good idea? btw how can i make many items on that chest not only 1 ? :oops:
 
i dont think so i've another idea you can make this room for cash i mean you can enter it with money so your cash on server won't die like others and will be important to gain more items from lottery ,isn't it good idea? btw how can i make many items on that chest not only 1 ? :oops:

thats easy

PHP:
function onUse(cid, item)
     local r = math.random(1,100)
     if r > 70 then
          doPlayerAddItem(cid, 2195, 1) -- reward
          doPlayerAddItem(cid, 2050, 1) -- reward
          doPlayerAddItem(cid, 2650, 1) -- reward
          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

Don't forget a lvl req or something so people won't be able to make many chars and do it over and over (if the reward is worth making alot of chars :p)

yea that would be great! just need to find that person that is willing to make a NPC :D
 
thats easy

PHP:
function onUse(cid, item)
     local r = math.random(1,100)
     if r > 70 then
          doPlayerAddItem(cid, 2195, 1) -- reward
          doPlayerAddItem(cid, 2050, 1) -- reward
          doPlayerAddItem(cid, 2650, 1) -- reward
          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
but i think this one will give me 3 rewards isn't it? but i need to put 3 items on it and only take one reward by chance
 
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())
 
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
         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())

I Tested the Script It Teleported me to the temple its good but the message appears in the room after i left it !!
 
@Limos how do i remove the one person in the room thingy i found out there is no need for this xD
and how to add that you can not talk to him when the player has the battlesign
 
Remove everything related to getSpectators.

For the fight condition
Code:
if getCreatureCondition(cid, CONDITION_INFIGHT) then
      return selfSay("You can't talk with me when you're in a fight.", cid)
end
 
@Limos like this?

PHP:
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 getCreatureCondition(cid, CONDITION_INFIGHT) then
         return selfSay("You can't talk with me when you're in a fight.", cid)
     end
     if msgcontains(msg, "yes") then
                     if doPlayerRemoveMoney(cid, 100) then
                         doTeleportThing(cid, {x=1462, y=1145, 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())
 
Back
Top