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

GlobalEvent Last Man Standing Event [TFS 1.X [1.0/1.1]]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,284
Location
Sweden?
Hello,

Today i made a small event named Last Man Standing, which refer to an Event in which Players have to Fight to Survive and Win certain Rewards.

Made only for TFS 1.x -> series! [1.0/1.1]

Features:
*Winner Reward!
*Broadcasts!
*Teleport Out 'losers'
*Teleport gets created!
*Min and Max Players!

Create new lua and name it 'lmsLib' inside the data folder and paste this code:
Lua:
lmsConfigTable = {
    minPlayers = 5, --Min players req to start the event
    maxPlayers = 20, --Max players can join the event
    waitingMinutes = 5, --How long until the event start, after it get's annouced first time
    joinedStorage = 1000, --Use non used storage
    lmsArenaPostions = {
        Position(143, 387, 7), --Top left corner of the arena
        Position(147, 391, 7) --Bottom right corner of the arena
    },
    joinedCountStorage = 101, --Use non used global storage
    waitingRoomPosition = {
        centerPos = Position(159, 388, 7),
        radiusX = 20,
        radiusY = 20
    },
    trophyId = 7369 --Itemid of the reward
}

lmsStatesTable = {
    EVENT_STATE_STORAGE = 100, --Use none used global storage
    ['EVENT_STATE_INIT'] = 1,
    ['EVENT_STATE_STARTED'] = 2,
    ['EVENT_STATE_CLOSED'] = 3
}

lmsTeleportTable = {
    teleportId = 1387, --itemId of the teleport
    teleportUid = 5000, --Use none used Uid
    createTeleportPosition = Position(153, 388, 7) --The position where the teleport will be created
}

function startLMSEvent()
    local joinedCount = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if not joinedCount or (joinedCount < lmsConfigTable.minPlayers) then
        local specs = Game.getSpectators(lmsConfigTable.waitingRoomPosition.centerPos, false, true, 0, lmsConfigTable.waitingRoomPosition.radiusX, 0, lmsConfigTable.waitingRoomPosition.radiusY)
        for i = 1, #specs do
            if specs[i]:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
                specs[i]:teleportTo(specs[i]:getTown():getTemplePosition())
                specs[i]:setStorageValue(lmsConfigTable.joinedStorage, 0)
            end
        end

        Game.broadcastMessage('Last Man Standing Event did not start! There was not enough of participants.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
        return true
    end

    local player, players = nil, Game.getPlayers()
    local randX, randY, randZ
    for i = 1, #players do
        randX = math.random(lmsConfigTable.lmsArenaPostions[1].x, lmsConfigTable.lmsArenaPostions[2].x)
        randY = math.random(lmsConfigTable.lmsArenaPostions[1].y, lmsConfigTable.lmsArenaPostions[2].y)
        randZ = math.random(lmsConfigTable.lmsArenaPostions[1].z, lmsConfigTable.lmsArenaPostions[2].z)

        player = players[i]
        if player:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
            player:teleportTo(Position(randX, randY, randZ))
            player:registerEvent('LMSOnDeath')
            print(randX, randY, randZ)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_STARTED)
    Game.broadcastMessage('Last Man Standing Event has started with '.. Game.getStorageValue(lmsConfigTable.joinedCountStorage) ..' players.', MESSAGE_STATUS_WARNING)
end

function resetLMSEvent()
    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
end

Now go into globalevents/globalevents.xml and paste this line:
XML:
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>

Now go into globalevents/scripts and create new lua and name it 'lmsStartEvent' and paste this code:
Lua:
dofile('data/lmsLib.lua')

local function sendReminderLMSEvent()
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
end

function onThink(interval, lastExecution)
    if #Game.getPlayers() < lmsConfigTable.minPlayers then --Min players is not online, we stop event from executing
        return true
    end

    if not Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) then
        Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_CLOSED then
        return true
    end

    local teleportTile = Tile(lmsTeleportTable.createTeleportPosition):getItemById(lmsTeleportTable.teleportId)
    if not teleportTile then
        local teleport = Game.createItem(lmsTeleportTable.teleportId, 1, lmsTeleportTable.createTeleportPosition)
        if teleport then
            teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, lmsTeleportTable.teleportUid)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_INIT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
    addEvent(startLMSEvent, lmsConfigTable.waitingMinutes * 60 * 1000)
    addEvent(sendReminderLMSEvent, (lmsConfigTable.waitingMinutes / 2) * 60 * 1000)
    return true
end

Now go into movements/movements.xml and paste this line:
XML:
<movevent event="StepIn" uniqueid="5000" script="lmsStepIn.lua"/>

And now go into movements/scripts and create new lua and name it 'lmsStepIn' and paste the code:
Lua:
dofile('data/lmsLib.lua')

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_INIT then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event has started or not started yet.')
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    local joinedCountStorage = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if joinedCountStorage and joinedCountStorage > lmsConfigTable.maxPlayers then
        player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event is already full.')
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(lmsConfigTable.waitingRoomPosition.centerPos)
    lmsConfigTable.waitingRoomPosition.centerPos:sendMagicEffect(CONST_ME_TELEPORT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, joinedCountStorage + 1)
    player:setStorageValue(lmsConfigTable.joinedStorage, 1)
    return true
end

Now last thing go to creaturescripts/creaturescripts.xml and paste this line:
XML:
<event type="preparedeath" name="LMSOnDeath" script="lmsOnDeath.lua"/>

Now go into creaturescripts/scripts and create new lua and name it 'lmsOnDeath' and paste this code:
Lua:
dofile('data/lmsLib.lua')

function onPrepareDeath(player, killer)
    player:teleportTo(player:getTown():getTemplePosition())
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    player:setStorageValue(lmsConfigTable.joinedStorage, 0)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '[LMS] You were killed by '.. killer:getName() ..'.')
    player:unregisterEvent('LMSOnDeath')

    Game.setStorageValue(lmsConfigTable.joinedCountStorage, Game.getStorageValue(lmsConfigTable.joinedCountStorage) - 1)
    if Game.getStorageValue(lmsConfigTable.joinedCountStorage) == 1 then
        local winner = killer
        local trophy = winner:addItem(lmsConfigTable.trophyId, 1)
        if trophy then
            trophy:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, winner:getName() ..' has won The Last Man Standing Event.')
        end

        winner:teleportTo(winner:getTown():getTemplePosition())
        winner:unregisterEvent('LMSOnDeath')
        winner:addHealth(winner:getMaxHealth())
        winner:addMana(winner:getMaxMana())
        winner:setStorageValue(lmsConfigTable.joinedStorage, 0)
        Game.broadcastMessage(winner:getName() ..' Is the winner of The Last Man Standing Event.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
    end
    return false
end

Enjoy!
 
Last edited:
Well i have not made any command to start the event. But you can configure the interval:
XML:
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>
 
Last edited by a moderator:
Hello,

Today i made a small event named Last Man Standing, which refer to an Event in which Players have to Fight to Survive and Win certain Rewards.

Made only for TFS 1.x -> series! [1.0/1.1]

Features:
*Winner Reward!
*Broadcasts!
*Teleport Out 'losers'
*Teleport gets created!
*Min and Max Players!

Create new lua and name it 'lmsLib' inside the data folder and paste this code:
Code:
lmsConfigTable = {
    minPlayers = 5, --Min players req to start the event
    maxPlayers = 20, --Max players can join the event
    waitingMinutes = 5, --How long until the event start, after it get's annouced first time
    joinedStorage = 1000, --Use non used storage
    lmsArenaPostions = {
        Position(143, 387, 7), --Top left corner of the arena
        Position(147, 391, 7) --Bottom right corner of the arena
    },
    joinedCountStorage = 101, --Use non used global storage
    waitingRoomPosition = {
        centerPos = Position(159, 388, 7),
        radiusX = 20,
        radiusY = 20
    },
    trophyId = 7369 --Itemid of the reward
}

lmsStatesTable = {
    EVENT_STATE_STORAGE = 100, --Use none used global storage
    ['EVENT_STATE_INIT'] = 1,
    ['EVENT_STATE_STARTED'] = 2,
    ['EVENT_STATE_CLOSED'] = 3
}

lmsTeleportTable = {
    teleportId = 1387, --itemId of the teleport
    teleportUid = 5000, --Use none used Uid
    createTeleportPosition = Position(153, 388, 7) --The position where the teleport will be created
}

function startLMSEvent()
    local joinedCount = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if not joinedCount or (joinedCount < lmsConfigTable.minPlayers) then
        local specs = Game.getSpectators(lmsConfigTable.waitingRoomPosition.centerPos, false, true, 0, lmsConfigTable.waitingRoomPosition.radiusX, 0, lmsConfigTable.waitingRoomPosition.radiusY)
        for i = 1, #specs do
            if specs[i]:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
                specs[i]:teleportTo(specs[i]:getTown():getTemplePosition())
                specs[i]:setStorageValue(lmsConfigTable.joinedStorage, 0)
            end
        end

        Game.broadcastMessage('Last Man Standing Event did not start! There was not enough of participants.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
        return true
    end

    local player, players = nil, Game.getPlayers()
    local randX, randY, randZ
    for i = 1, #players do
        randX = math.random(lmsConfigTable.lmsArenaPostions[1].x, lmsConfigTable.lmsArenaPostions[2].x)
        randY = math.random(lmsConfigTable.lmsArenaPostions[1].y, lmsConfigTable.lmsArenaPostions[2].y)
        randZ = math.random(lmsConfigTable.lmsArenaPostions[1].z, lmsConfigTable.lmsArenaPostions[2].z)

        player = players[i]
        if player:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
            player:teleportTo(Position(randX, randY, randZ))
            player:registerEvent('LMSOnDeath')
            print(randX, randY, randZ)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_STARTED)
    Game.broadcastMessage('Last Man Standing Event has started with '.. Game.getStorageValue(lmsConfigTable.joinedCountStorage) ..' players.', MESSAGE_STATUS_WARNING)
end

function resetLMSEvent()
    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
end

Now go into globalevents/globalevents.xml and paste this line:
Code:
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>

Now go into globalevents/scripts and create new lua and name it 'lmsStartEvent' and paste this code:
Code:
dofile('data/lmsLib.lua')

local function sendReminderLMSEvent()
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
end

function onThink(interval, lastExecution)
    if #Game.getPlayers() < lmsConfigTable.minPlayers then --Min players is not online, we stop event from executing
        return true
    end

    if not Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) then
        Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_CLOSED then
        return true
    end

    local teleportTile = Tile(lmsTeleportTable.createTeleportPosition):getItemById(lmsTeleportTable.teleportId)
    if not teleportTile then
        local teleport = Game.createItem(lmsTeleportTable.teleportId, 1, lmsTeleportTable.createTeleportPosition)
        if teleport then
            teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, lmsTeleportTable.teleportUid)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_INIT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
    addEvent(startLMSEvent, lmsConfigTable.waitingMinutes * 60 * 1000)
    addEvent(sendReminderLMSEvent, (lmsConfigTable.waitingMinutes / 2) * 60 * 1000)
    return true
end

Now go into movements/movements.xml and paste this line:
Code:
<movevent event="StepIn" uniqueid="5000" script="lmsStepIn.lua"/>

And now go into movements/scripts and create new lua and name it 'lmsStepIn' and paste the code:
Code:
dofile('data/lmsLib.lua')

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_INIT then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event has started or not started yet.')
        creature:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    local joinedCountStorage = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if joinedCountStorage and joinedCountStorage > lmsConfigTable.maxPlayers then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event is already full.')
        creature:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    creature:teleportTo(lmsConfigTable.waitingRoomPosition.centerPos)
    lmsConfigTable.waitingRoomPosition.centerPos:sendMagicEffect(CONST_ME_TELEPORT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, joinedCountStorage + 1)
    creature:setStorageValue(lmsConfigTable.joinedStorage, 1)
    return true
end

Now last thing go to creaturescripts/creaturescripts.xml and paste this line:
Code:
<event type="preparedeath" name="LMSOnDeath" script="lmsOnDeath.lua"/>

Now go into creaturescripts/scripts and create new lua and name it 'lmsOnDeath' and paste this code:
Code:
dofile('data/lmsLib.lua')

function onPrepareDeath(creature, killer)
    creature:teleportTo(creature:getTown():getTemplePosition())
    creature:addHealth(creature:getMaxHealth())
    creature:addMana(creature:getMaxMana())
    creature:setStorageValue(lmsConfigTable.joinedStorage, 0)
    creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, '[LMS] You were killed by '.. killer:getName() ..'.')
    creature:unregisterEvent('LMSOnDeath')

    Game.setStorageValue(lmsConfigTable.joinedCountStorage, Game.getStorageValue(lmsConfigTable.joinedCountStorage) - 1)
    if Game.getStorageValue(lmsConfigTable.joinedCountStorage) == 1 then
        local winner = killer
        local trophy = winner:addItem(lmsConfigTable.trophyId, 1)
        if trophy then
            trophy:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, winner:getName() ..' has won The Last Man Standing Event.')
        end
 
        winner:teleportTo(winner:getTown():getTemplePosition())
        winner:unregisterEvent('LMSOnDeath')
        winner:addHealth(winner:getMaxHealth())
        winner:addMana(winner:getMaxMana())
        winner:setStorageValue(lmsConfigTable.joinedStorage, 0)
        Game.broadcastMessage(winner:getName() ..' Is the winner of The Last Man Standing Event.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
    end
    return false
end

Enjoy!
[16/12/2014 00:15:04] [Error - CreatureScript Interface]
[16/12/2014 00:15:04] data/creaturescripts/scripts/lmsOnDeath.lua
[16/12/2014 00:15:04] Description:
[16/12/2014 00:15:04] data/lmsLib.lua:7: attempt to call global 'Position' (a nil value)
[16/12/2014 00:15:04] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/lmsOnDeath.lua)


[16/12/2014 00:15:04] [Error - GlobalEvent Interface]
[16/12/2014 00:15:05] data/globalevents/scripts/lmsStartEvent.lua
[16/12/2014 00:15:05] Description:
[16/12/2014 00:15:05] data/lmsLib.lua:7: attempt to call global 'Position' (a nil value)
[16/12/2014 00:15:05] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/lmsStartEvent.lua)

version 0.3.6 // 8.60 // 1.0
 
Hello,

Today i made a small event named Last Man Standing, which refer to an Event in which Players have to Fight to Survive and Win certain Rewards.

Made only for TFS 1.x -> series! [1.0/1.1]

Features:
*Winner Reward!
*Broadcasts!
*Teleport Out 'losers'
*Teleport gets created!
*Min and Max Players!

Create new lua and name it 'lmsLib' inside the data folder and paste this code:
Code:
lmsConfigTable = {
    minPlayers = 5, --Min players req to start the event
    maxPlayers = 20, --Max players can join the event
    waitingMinutes = 5, --How long until the event start, after it get's annouced first time
    joinedStorage = 1000, --Use non used storage
    lmsArenaPostions = {
        Position(143, 387, 7), --Top left corner of the arena
        Position(147, 391, 7) --Bottom right corner of the arena
    },
    joinedCountStorage = 101, --Use non used global storage
    waitingRoomPosition = {
        centerPos = Position(159, 388, 7),
        radiusX = 20,
        radiusY = 20
    },
    trophyId = 7369 --Itemid of the reward
}

lmsStatesTable = {
    EVENT_STATE_STORAGE = 100, --Use none used global storage
    ['EVENT_STATE_INIT'] = 1,
    ['EVENT_STATE_STARTED'] = 2,
    ['EVENT_STATE_CLOSED'] = 3
}

lmsTeleportTable = {
    teleportId = 1387, --itemId of the teleport
    teleportUid = 5000, --Use none used Uid
    createTeleportPosition = Position(153, 388, 7) --The position where the teleport will be created
}

function startLMSEvent()
    local joinedCount = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if not joinedCount or (joinedCount < lmsConfigTable.minPlayers) then
        local specs = Game.getSpectators(lmsConfigTable.waitingRoomPosition.centerPos, false, true, 0, lmsConfigTable.waitingRoomPosition.radiusX, 0, lmsConfigTable.waitingRoomPosition.radiusY)
        for i = 1, #specs do
            if specs[i]:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
                specs[i]:teleportTo(specs[i]:getTown():getTemplePosition())
                specs[i]:setStorageValue(lmsConfigTable.joinedStorage, 0)
            end
        end

        Game.broadcastMessage('Last Man Standing Event did not start! There was not enough of participants.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
        return true
    end

    local player, players = nil, Game.getPlayers()
    local randX, randY, randZ
    for i = 1, #players do
        randX = math.random(lmsConfigTable.lmsArenaPostions[1].x, lmsConfigTable.lmsArenaPostions[2].x)
        randY = math.random(lmsConfigTable.lmsArenaPostions[1].y, lmsConfigTable.lmsArenaPostions[2].y)
        randZ = math.random(lmsConfigTable.lmsArenaPostions[1].z, lmsConfigTable.lmsArenaPostions[2].z)

        player = players[i]
        if player:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
            player:teleportTo(Position(randX, randY, randZ))
            player:registerEvent('LMSOnDeath')
            print(randX, randY, randZ)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_STARTED)
    Game.broadcastMessage('Last Man Standing Event has started with '.. Game.getStorageValue(lmsConfigTable.joinedCountStorage) ..' players.', MESSAGE_STATUS_WARNING)
end

function resetLMSEvent()
    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
end

Now go into globalevents/globalevents.xml and paste this line:
Code:
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>

Now go into globalevents/scripts and create new lua and name it 'lmsStartEvent' and paste this code:
Code:
dofile('data/lmsLib.lua')

local function sendReminderLMSEvent()
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
end

function onThink(interval, lastExecution)
    if #Game.getPlayers() < lmsConfigTable.minPlayers then --Min players is not online, we stop event from executing
        return true
    end

    if not Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) then
        Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_CLOSED then
        return true
    end

    local teleportTile = Tile(lmsTeleportTable.createTeleportPosition):getItemById(lmsTeleportTable.teleportId)
    if not teleportTile then
        local teleport = Game.createItem(lmsTeleportTable.teleportId, 1, lmsTeleportTable.createTeleportPosition)
        if teleport then
            teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, lmsTeleportTable.teleportUid)
        end
    end

    Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_INIT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
    Game.broadcastMessage(string.format('Last Man Standing Event has started and waiting for players to join! Min %s/%s.', lmsConfigTable.minPlayers, lmsConfigTable.maxPlayers), MESSAGE_STATUS_WARNING)
    addEvent(startLMSEvent, lmsConfigTable.waitingMinutes * 60 * 1000)
    addEvent(sendReminderLMSEvent, (lmsConfigTable.waitingMinutes / 2) * 60 * 1000)
    return true
end

Now go into movements/movements.xml and paste this line:
Code:
<movevent event="StepIn" uniqueid="5000" script="lmsStepIn.lua"/>

And now go into movements/scripts and create new lua and name it 'lmsStepIn' and paste the code:
Code:
dofile('data/lmsLib.lua')

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_INIT then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event has started or not started yet.')
        creature:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    local joinedCountStorage = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    if joinedCountStorage and joinedCountStorage > lmsConfigTable.maxPlayers then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event is already full.')
        creature:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        return true
    end

    fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    creature:teleportTo(lmsConfigTable.waitingRoomPosition.centerPos)
    lmsConfigTable.waitingRoomPosition.centerPos:sendMagicEffect(CONST_ME_TELEPORT)
    Game.setStorageValue(lmsConfigTable.joinedCountStorage, joinedCountStorage + 1)
    creature:setStorageValue(lmsConfigTable.joinedStorage, 1)
    return true
end

Now last thing go to creaturescripts/creaturescripts.xml and paste this line:
Code:
<event type="preparedeath" name="LMSOnDeath" script="lmsOnDeath.lua"/>

Now go into creaturescripts/scripts and create new lua and name it 'lmsOnDeath' and paste this code:
Code:
dofile('data/lmsLib.lua')

function onPrepareDeath(creature, killer)
    creature:teleportTo(creature:getTown():getTemplePosition())
    creature:addHealth(creature:getMaxHealth())
    creature:addMana(creature:getMaxMana())
    creature:setStorageValue(lmsConfigTable.joinedStorage, 0)
    creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, '[LMS] You were killed by '.. killer:getName() ..'.')
    creature:unregisterEvent('LMSOnDeath')

    Game.setStorageValue(lmsConfigTable.joinedCountStorage, Game.getStorageValue(lmsConfigTable.joinedCountStorage) - 1)
    if Game.getStorageValue(lmsConfigTable.joinedCountStorage) == 1 then
        local winner = killer
        local trophy = winner:addItem(lmsConfigTable.trophyId, 1)
        if trophy then
            trophy:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, winner:getName() ..' has won The Last Man Standing Event.')
        end
 
        winner:teleportTo(winner:getTown():getTemplePosition())
        winner:unregisterEvent('LMSOnDeath')
        winner:addHealth(winner:getMaxHealth())
        winner:addMana(winner:getMaxMana())
        winner:setStorageValue(lmsConfigTable.joinedStorage, 0)
        Game.broadcastMessage(winner:getName() ..' Is the winner of The Last Man Standing Event.', MESSAGE_STATUS_WARNING)
        resetLMSEvent()
    end
    return false
end

Enjoy!
Looks very nice will have to give that a shot, I can make my own but care to upload any waiting area/game area maps you might have?
 
Hello dear Otlanders,

I have a problem with this script. It is giving me an error on lmsStepIn.

16e067c01f539ee86f9102b6a9b7e9d1.png

I hope you can help me, because I would like to use it in my server :)

PS: I am using TFS 1.0
 
Well, it is actually created for TFS 1.1. To make it work, you just edit the functions. Such as:

I've updated these files, please recopy them: movements/scripts/lmsStepIn.lua and creaturescripts/scripts/lmsOnDeath.lua. And now just make these minor changes:

in the movements/scripts/lmsStepIn.lua
Code:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

To this:
Code:
function onStepIn(cid, item, position, fromPosition)
    local player = Player(cid)

Then same goes for creaturescripts/scripts/lmsOnDeath.lua
Code:
function onPrepareDeath(player, killer)

To this:
Code:
function onPrepareDeath(cid, killer)
    local player = Player(cid)
 
I get no errors but the teleport won't teleport me

any idea?
 
Awesome man!, Only one question i got, what if player goes in waiting room, but noone else joins in? Will he have to wait there forever until someone else goes in there?
 
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>
i've changed to
<globalevent name="lms" interval="5" script="lmsStartEvent.lua"/>
after 5 sec nothing happens!
Plaease help me ;p
 
<globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>
i've changed to
<globalevent name="lms" interval="5" script="lmsStartEvent.lua"/>
after 5 sec nothing happens!
Plaease help me ;p
Interval is set in milliseconds so 5000 is 5 seconds.
 
I solved it.i changed lmsLib.lua. Thanks, now it works perfectly
 
Last edited:
- could you make a talkaction to start the event?
-is there a limit time for the event? I mean incase there is 2 players left that cant kill each other?
 
Ive done everything but it doesnt start... its like it doesnt react to the global event... TFS 1.1 Help please :/
 
Back
Top