• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Problem with action + creaturescripts

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hey guys!

I've got these scripts. In actions:
LUA:
---------------------------------- Start Config -------------------------------
local config = {
   arena_position = {x = 462, y = 17, z = 7}, -- Player Arena Position
   failed_position = {x = 473, y = 10, z = 7}, -- Player took too long position
   lever_reset_time = 10, -- in minutes (how long until another player can kick them out)
   global_storage = 696969, -- any free storage
   storage = 42312,
   top_left_corner = {x = 459, y = 15, z = 7}, -- top left corner of arena
   bottom_right_corner = {x = 470, y = 18, z = 7}, -- bottom right corner of arena
   joke_monster = "Fighter" -- They will kill this monster to start the waves
}
----------------------------------- End Config --------------------------------
local function reset(p)
   doTransformItem(getTileItemById(p, 1946).uid, 1945)
end
local function teleport(cid)
   setPlayerStorageValue(cid, config.storage, 1)
   doTeleportThing(cid, config.arena_position)
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "---------------------------------------")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Kill the training mate to start Tournament.")
   doCreateMonster(config.joke_monster, config.arena_position)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
   -- check if lever is currently used
   if item.itemid == 1946 then
     return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset. It resets automatically every ".. config.lever_reset_time .." minutes.")
   end
   -- check for players/monsters in arena, and kick them out/remove them
   for t = config.top_left_corner.x, config.bottom_right_corner.x do
     for f = config.top_left_corner.y, config.bottom_right_corner.y do
       pos = {x = t, y = f, z = 7}
       pid = getTopCreature(pos).uid
       if isPlayer(pid) then
         doTeleportThing(pid, config.failed_position)
         doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Another player started the arena. You have been removed. Better luck next time!")
       end
       if isMonster(pid) then
         doRemoveCreature(pid)
       end
     end
   end
   -- tell player what to do
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Lever resets automatically every ".. config.lever_reset_time .." minutes.")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Once the lever resets another player can start the arena.")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "If your still inside when another player starts, you will be removed from the arena and unable to continue.")
   -- reset global storage
   setGlobalStorageValue(global_storage, 0)
   -- teleport player to arena, send start message, create start/joke monster
   addEvent(teleport, 5000, cid)
   -- transform lever, and add reset
   doTransformItem(item.uid, item.itemid + 1)
   addEvent(reset, ((config.lever_reset_time * 60 * 1000) + 5000), toPosition)
   return true
end

And in creaturescripts:

First (kill):
LUA:
local config = {
   reward_position = {x = 472, y = 12, z = 7}, -- Teleport location when Arena is Cleared.
   global_storage = 696969, -- any free storage
   top_left_corner = {x = 459, y = 15, z = 7}, -- top left corner of arena
   storage = 42312,
   bottom_right_corner = {x = 470, y = 18, z = 7}, -- bottom right corner of arena
}
local monsters = { -- All monsters in arena (including joke monster)
   [1] = "Fighter",
   [2] = "Yamcha",
   [3] = "Ranfan",
   [4] = "Jackie Chun"
}
local monster_config_wave_one = { -- wave 1
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Yamcha"}
}
local monster_config_wave_two = { -- wave 2
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Ranfan"}
}
local monster_config_wave_three = { -- wave 3
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Jackie Chun"}

}
   function onKill(cid, target, damage, flags)
   -- check if target is player
   if isPlayer(target) then
     return true
   end
   -- check if target is on list of monsters in arena
   local name = getCreatureName(target):lower()
   count = 0
   for i = 1, #monsters do
     if name == monsters[i]:lower() then
       count = count + 1
     end
   end
   if count == 0 then -- if target is not on list
     return true
   end
   -- check if target is in area and add to global storage if it is
   for t = config.top_left_corner.x, config.bottom_right_corner.x do
     for f = config.top_left_corner.y, config.bottom_right_corner.y do
       pos = {x = t, y = f, z = 7}
       pid = getTopCreature(pos).uid
       if pid == target then
         setGlobalStorageValue(global_storage, getGlobalStorageValue(global_storage) + 1)
         setPlayerStorageValue(cid, config.storage, 1)
       end
     end
   end
   -- Start checks for waves of arena
   -- Wave 1
   if getGlobalStorageValue(global_storage) == 1 then
     for i = 1, #monster_config_wave_one do
       doCreateMonster(monster_config_wave_one[i].name, monster_config_wave_one[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 1.")
   end
   -- Wave 2
   if getGlobalStorageValue(global_storage) == 2 then
     for i = 1, #monster_config_wave_two do
       doCreateMonster(monster_config_wave_two[i].name, monster_config_wave_two[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 2.")
   end
   -- Wave 3
   if getGlobalStorageValue(global_storage) == 3 then
     for i = 1, #monster_config_wave_three do
       doCreateMonster(monster_config_wave_three[i].name, monster_config_wave_three[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 3. Final Wave.")
   end
   -- When final wave ends
   -- Teleport player
   if getGlobalStorageValue(global_storage) == 4 then
     doTeleportThing(cid, config.reward_position)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations! Go collect your reward.")
     setGlobalStorageValue(global_storage, 0)
   end
   return true
end

And Second (preparedeath):
LUA:
function onPrepareDeath(cid, deathList)
local storage = 42312
local pos = {x = 472, y = 12, z = 7}
    if getPlayerStorageValue(cid, storage) == 1 then
        setPlayerStorageValue(cid, storage, 0)
        doTeleportThing(cid, pos)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
        doCreatureAddMana(cid, getCreatureMaxMana(cid))
        doRemoveCondition(cid, false)
        return false
    end
    return true
end

What is a problem? I wanted to make, that after dead in area the player will be teleported to position I set. And it's working fine. BUT when after that i go to normal monster and I die, i teleport to temple but without dead. Just teleported. After this teleported, when i go on normal monster and i die I'm standing with 0hp and cannot move (when I heal up i can). After relog in the last situation, I die as a normal.
Where is a problem? :/ Please help
 
Back
Top