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:
Now go into globalevents/globalevents.xml and paste this line:
Now go into globalevents/scripts and create new lua and name it 'lmsStartEvent' and paste this code:
Now go into movements/movements.xml and paste this line:
And now go into movements/scripts and create new lua and name it 'lmsStepIn' and paste the code:
Now last thing go to creaturescripts/creaturescripts.xml and paste this line:
Now go into creaturescripts/scripts and create new lua and name it 'lmsOnDeath' and paste this code:
Enjoy!
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: