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

Lua StopEvent issue

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
112
Solutions
3
Reaction score
8
I'm attempting to create a hunting room script. Everything is working fine, except for when a player decides to leave the arena early. If a player leaves the arena before time expires, the script will continue running. When time expires, no matter where the player is, they will get teleported to the arena kick position.

I'm uploading a picture of the hunting rooms. (All rooms have the same setup)

I need help adding a "Check for player in room. If empty, don't run script" or something similar to that. Any help is appreciated. Thanks in advance!

Lua:
local tileId = 11062 -- Item id of tile
local timer = 1*60*1000 -- Number of minutes in arena
local signId = 1429 -- Item id of sign
local tokenId = 2157 -- Item id required to enter
local cost = 1 -- Number of items required
vipRoom = {}

local function vipRoomDecay(monsterName, cid, position)
for i, theRoom in pairs(vipRoom[monsterName]) do
  local creature = Monster(theRoom) -- Assign creature to the room from the monster array
  if creature then -- If a monster is in the room,
   creature:remove() -- Remove the monster
  end
 end
 
 vipRoom[monsterName] = nil --Initialize creature to nil
 
 local player = Player(cid) -- Assign player ID to player variable
 
 if not player then
  return
 end -- Make sure creature is a player before kicking
 
 player:teleportTo(position) -- Kick player from arena
 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Times up.') -- Show message "times up"
end
function onStepIn(player, item, position, fromPosition)
 if not player:isPlayer() then --Make sure creature entering is player
  return true
 end
local signLeft = Tile(Position(position.x-1,position.y,position.z)):getItemById(signId) -- Allow entry for east rooms
--local signRight = Tile(Position(position.x+1,position.y,position.z)):getItemById(signId) -- Allow entry for west rooms
local signDownLeft = Tile(Position(position.x-1, position.y+2, position.z)):getItemById(signId) --Find creature for east rooms
--local signDownRight = Tile(Position(position.x+1,position.y+2,position.z)):getItemById(signId) -- Find creature for west rooms
local sign = signLeft or signDownLeft --or signRight or signDownRight  --Assign signs to sign
--Depot tile handling
 if not sign then
   item:transform(11063) -- Transform tile "onStepIn"
  if Tile(position):hasFlag(TILESTATE_PROTECTIONZONE) then -- if tile is in PZ
 local lookPosition = player:getPosition() -- get Player position
  lookPosition:getNextPosition(player:getDirection()) -- get Tile in front of player (Depot)
 local depotItem = Tile(lookPosition):getItemByType(ITEM_TYPE_DEPOT) -- get Depot item list
   if depotItem ~= nil then --if depot has items
 local depotItems = player:getDepotChest(getDepotId(depotItem:getUniqueId()), true:getItemHoldingCount() -- Get the amount of items in depot
   player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your depot contains " .. depotItems .. "item" .. (depotItems > 1 and "s." or ".")) -- Send player message with depot item count
   return true
   end
  end
 return true
 end
 
--Back to hunting room handling
local monsterName = sign:getAttribute(ITEM_ATTRIBUTE_TEXT) -- Get creature name from sign
local spawnPosition = Position(position.x+4, position.y-5, position.z) -- Where to spawn creature
 if signDownLeft then --or signDownRight -- Find the location of the sign when player enters room
 
  vipRoom[monsterName] = vipRoom[monsterName] or {} --Not really sure?
 
  vipRoom[monsterName][#vipRoom[monsterName]+1] = Game.createMonster(monsterName, spawnPosition):getId() -- When player is on tile, spawn creature in assigned location
 
  return true
 end
 if player:getItemCount(tokenId) < cost then -- If player doesn't have VIP coins
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You require a VIP token to enter the arena.')
  player:teleportTo(fromPosition) -- Send player back to starting position
  return true
 end
 
 vipRoom[monsterName] = vipRoom[monsterName] or {} --Not really sure?
 
 if #vipRoom[monsterName] > 0 then -- Allow arena cooldown
  player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'This arena has recently been used. Please allow it to cool down before you try to enter.')
  return true
 end
 
 player:removeItem(tokenId, cost) -- Take required item and count from player
 player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have '..timer/(60*1000)..' minutes in this arena. Step on the red switch pad to spawn more creatures.')
 player:teleportTo(Position(position.x, position.y-2, position.z)) --Send player into arena
 
 addEvent(vipRoomDecay, timer, monsterName, player:getId(), fromPosition) -- Start timer and arena countdown
 
 return true
end
 

Attachments

  • HuntingRoomSetup.png
    HuntingRoomSetup.png
    457.3 KB · Views: 4 · VirusTotal
I don't 1.0+ scripting..

But on 0.3.7 I'd do this
Lua:
if not isPlayer(cid) then
    return true
end
If the player is indeed a player, then that means they are online..
So just find their location.
Lua:
local p_pos = getThingPosition(cid)
Then just compare to see if their current position is inside the arena.

Just do the same for 1.0+ scripting style/stuff.
 
Back
Top