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

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Printer, Nov 19, 2014.

  1. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,604
    Likes Received:
    1,911
    Best Answers:
    5
    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 (Lua):
    1. lmsConfigTable = {
    2.     minPlayers = 5, --Min players req to start the event
    3.     maxPlayers = 20, --Max players can join the event
    4.     waitingMinutes = 5, --How long until the event start, after it get's annouced first time
    5.     joinedStorage = 1000, --Use non used storage
    6.     lmsArenaPostions = {
    7.         Position(143, 387, 7), --Top left corner of the arena
    8.         Position(147, 391, 7) --Bottom right corner of the arena
    9.     },
    10.     joinedCountStorage = 101, --Use non used global storage
    11.     waitingRoomPosition = {
    12.         centerPos = Position(159, 388, 7),
    13.         radiusX = 20,
    14.         radiusY = 20
    15.     },
    16.     trophyId = 7369 --Itemid of the reward
    17. }
    18.  
    19. lmsStatesTable = {
    20.     EVENT_STATE_STORAGE = 100, --Use none used global storage
    21.     ['EVENT_STATE_INIT'] = 1,
    22.     ['EVENT_STATE_STARTED'] = 2,
    23.     ['EVENT_STATE_CLOSED'] = 3
    24. }
    25.  
    26. lmsTeleportTable = {
    27.     teleportId = 1387, --itemId of the teleport
    28.     teleportUid = 5000, --Use none used Uid
    29.     createTeleportPosition = Position(153, 388, 7) --The position where the teleport will be created
    30. }
    31.  
    32. function startLMSEvent()
    33.     local joinedCount = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    34.     if not joinedCount or (joinedCount < lmsConfigTable.minPlayers) then
    35.         local specs = Game.getSpectators(lmsConfigTable.waitingRoomPosition.centerPos, false, true, 0, lmsConfigTable.waitingRoomPosition.radiusX, 0, lmsConfigTable.waitingRoomPosition.radiusY)
    36.         for i = 1, #specs do
    37.             if specs[i]:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
    38.                 specs[i]:teleportTo(specs[i]:getTown():getTemplePosition())
    39.                 specs[i]:setStorageValue(lmsConfigTable.joinedStorage, 0)
    40.             end
    41.         end
    42.  
    43.         Game.broadcastMessage('Last Man Standing Event did not start! There was not enough of participants.', MESSAGE_STATUS_WARNING)
    44.         resetLMSEvent()
    45.         return true
    46.     end
    47.  
    48.     local player, players = nil, Game.getPlayers()
    49.     local randX, randY, randZ
    50.     for i = 1, #players do
    51.         randX = math.random(lmsConfigTable.lmsArenaPostions[1].x, lmsConfigTable.lmsArenaPostions[2].x)
    52.         randY = math.random(lmsConfigTable.lmsArenaPostions[1].y, lmsConfigTable.lmsArenaPostions[2].y)
    53.         randZ = math.random(lmsConfigTable.lmsArenaPostions[1].z, lmsConfigTable.lmsArenaPostions[2].z)
    54.  
    55.         player = players[i]
    56.         if player:getStorageValue(lmsConfigTable.joinedStorage) == 1 then
    57.             player:teleportTo(Position(randX, randY, randZ))
    58.             player:registerEvent('LMSOnDeath')
    59.             print(randX, randY, randZ)
    60.         end
    61.     end
    62.  
    63.     Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_STARTED)
    64.     Game.broadcastMessage('Last Man Standing Event has started with '.. Game.getStorageValue(lmsConfigTable.joinedCountStorage) ..' players.', MESSAGE_STATUS_WARNING)
    65. end
    66.  
    67. function resetLMSEvent()
    68.     Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    69.     Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
    70. end
    Now go into globalevents/globalevents.xml and paste this line:
    Code (XML):
    1. <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 (Lua):
    1. dofile('data/lmsLib.lua')
    2.  
    3. local function sendReminderLMSEvent()
    4.     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)
    5. end
    6.  
    7. function onThink(interval, lastExecution)
    8.     if #Game.getPlayers() < lmsConfigTable.minPlayers then --Min players is not online, we stop event from executing
    9.         return true
    10.     end
    11.  
    12.     if not Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) then
    13.         Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_CLOSED)
    14.     end
    15.  
    16.     if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_CLOSED then
    17.         return true
    18.     end
    19.  
    20.     local teleportTile = Tile(lmsTeleportTable.createTeleportPosition):getItemById(lmsTeleportTable.teleportId)
    21.     if not teleportTile then
    22.         local teleport = Game.createItem(lmsTeleportTable.teleportId, 1, lmsTeleportTable.createTeleportPosition)
    23.         if teleport then
    24.             teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, lmsTeleportTable.teleportUid)
    25.         end
    26.     end
    27.  
    28.     Game.setStorageValue(lmsStatesTable.EVENT_STATE_STORAGE, lmsStatesTable.EVENT_STATE_INIT)
    29.     Game.setStorageValue(lmsConfigTable.joinedCountStorage, 0)
    30.     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)
    31.     addEvent(startLMSEvent, lmsConfigTable.waitingMinutes * 60 * 1000)
    32.     addEvent(sendReminderLMSEvent, (lmsConfigTable.waitingMinutes / 2) * 60 * 1000)
    33.     return true
    34. end
    Now go into movements/movements.xml and paste this line:
    Code (XML):
    1. <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 (Lua):
    1. dofile('data/lmsLib.lua')
    2.  
    3. function onStepIn(creature, item, position, fromPosition)
    4.     local player = creature:getPlayer()
    5.     if not player then
    6.         return true
    7.     end
    8.  
    9.     if Game.getStorageValue(lmsStatesTable.EVENT_STATE_STORAGE) ~= lmsStatesTable.EVENT_STATE_INIT then
    10.         player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event has started or not started yet.')
    11.         player:teleportTo(fromPosition, true)
    12.         fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    13.         return true
    14.     end
    15.  
    16.     local joinedCountStorage = Game.getStorageValue(lmsConfigTable.joinedCountStorage)
    17.     if joinedCountStorage and joinedCountStorage > lmsConfigTable.maxPlayers then
    18.         player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Lastman Standing Event is already full.')
    19.         player:teleportTo(fromPosition, true)
    20.         fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    21.         return true
    22.     end
    23.  
    24.     fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
    25.     player:teleportTo(lmsConfigTable.waitingRoomPosition.centerPos)
    26.     lmsConfigTable.waitingRoomPosition.centerPos:sendMagicEffect(CONST_ME_TELEPORT)
    27.     Game.setStorageValue(lmsConfigTable.joinedCountStorage, joinedCountStorage + 1)
    28.     player:setStorageValue(lmsConfigTable.joinedStorage, 1)
    29.     return true
    30. end
    Now last thing go to creaturescripts/creaturescripts.xml and paste this line:
    Code (XML):
    1. <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 (Lua):
    1. dofile('data/lmsLib.lua')
    2.  
    3. function onPrepareDeath(player, killer)
    4.     player:teleportTo(player:getTown():getTemplePosition())
    5.     player:addHealth(player:getMaxHealth())
    6.     player:addMana(player:getMaxMana())
    7.     player:setStorageValue(lmsConfigTable.joinedStorage, 0)
    8.     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '[LMS] You were killed by '.. killer:getName() ..'.')
    9.     player:unregisterEvent('LMSOnDeath')
    10.  
    11.     Game.setStorageValue(lmsConfigTable.joinedCountStorage, Game.getStorageValue(lmsConfigTable.joinedCountStorage) - 1)
    12.     if Game.getStorageValue(lmsConfigTable.joinedCountStorage) == 1 then
    13.         local winner = killer
    14.         local trophy = winner:addItem(lmsConfigTable.trophyId, 1)
    15.         if trophy then
    16.             trophy:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, winner:getName() ..' has won The Last Man Standing Event.')
    17.         end
    18.  
    19.         winner:teleportTo(winner:getTown():getTemplePosition())
    20.         winner:unregisterEvent('LMSOnDeath')
    21.         winner:addHealth(winner:getMaxHealth())
    22.         winner:addMana(winner:getMaxMana())
    23.         winner:setStorageValue(lmsConfigTable.joinedStorage, 0)
    24.         Game.broadcastMessage(winner:getName() ..' Is the winner of The Last Man Standing Event.', MESSAGE_STATUS_WARNING)
    25.         resetLMSEvent()
    26.     end
    27.     return false
    28. end
    Enjoy!
     
    Last edited: Dec 26, 2014
    Azze19, Oravake, Evil Puncker and 6 others like this.
  2. domyno2837

    domyno2837 Member

    Joined:
    Oct 28, 2013
    Messages:
    167
    Likes Received:
    5
    Best Answers:
    0
    How to Start that event? :eek:
     
  3. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,604
    Likes Received:
    1,911
    Best Answers:
    5
    Well i have not made any command to start the event. But you can configure the interval:
    Code (XML):
    1. <globalevent name="lms" interval="7200000" script="lmsStartEvent.lua"/>
     
    Last edited by a moderator: Feb 12, 2017
  4. domyno2837

    domyno2837 Member

    Joined:
    Oct 28, 2013
    Messages:
    167
    Likes Received:
    5
    Best Answers:
    0
    ok Thanks :D
     
  5. emil1174

    emil1174 Member

    Joined:
    Feb 12, 2012
    Messages:
    74
    Likes Received:
    43
    Best Answers:
    0
    You can fix event for tfs 0.2.11 ? :D:D:D
     
  6. imback1

    imback1 Unknown member

    Joined:
    Jul 11, 2013
    Messages:
    766
    Likes Received:
    42
    Best Answers:
    1
    [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
     
  7. iDramatiik

    iDramatiik http://realia.no-ip.info/ RLMap 10.41 Free Points

    Joined:
    Apr 15, 2014
    Messages:
    157
    Likes Received:
    14
    Best Answers:
    0
    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?
     
  8. Oravake

    Oravake New Member

    Joined:
    Nov 22, 2014
    Messages:
    4
    Likes Received:
    2
    Best Answers:
    0
    Hello dear Otlanders,

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

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

    PS: I am using TFS 1.0
     
  9. Printer

    Printer if Printer then print("LUA") end Premium User

    Joined:
    Dec 27, 2009
    Messages:
    5,604
    Likes Received:
    1,911
    Best Answers:
    5
    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 (Text):
    1. function onStepIn(creature, item, position, fromPosition)
    2.     local player = creature:getPlayer()
    3.     if not player then
    4.         return true
    5.     end
    To this:
    Code (Text):
    1. function onStepIn(cid, item, position, fromPosition)
    2.     local player = Player(cid)
    3.  
    Then same goes for creaturescripts/scripts/lmsOnDeath.lua
    Code (Text):
    1. function onPrepareDeath(player, killer)
    To this:
    Code (Text):
    1. function onPrepareDeath(cid, killer)
    2.     local player = Player(cid)
     
    Codinablack and Oravake like this.
  10. Oravake

    Oravake New Member

    Joined:
    Nov 22, 2014
    Messages:
    4
    Likes Received:
    2
    Best Answers:
    0
    Thank you @Printer. Got it working now and cheers mate ;)
     
    Codinablack likes this.
  11. vingo

    vingo Active Member

    Joined:
    Oct 27, 2012
    Messages:
    466
    Likes Received:
    43
    Best Answers:
    0
    I get no errors but the teleport won't teleport me

    any idea?
     
  12. Slaying World

    Slaying World Member

    Joined:
    Apr 9, 2009
    Messages:
    212
    Likes Received:
    8
    Best Answers:
    0
    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?
     
  13. musk1

    musk1 New Member

    Joined:
    Dec 31, 2014
    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    <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
     
  14. Vanderlay

    Vanderlay Back on track Premium User

    Joined:
    Sep 20, 2007
    Messages:
    893
    Likes Received:
    105
    Best Answers:
    0
    Interval is set in milliseconds so 5000 is 5 seconds.
     
  15. musk1

    musk1 New Member

    Joined:
    Dec 31, 2014
    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    I solved it.i changed lmsLib.lua. Thanks, now it works perfectly
     
    Last edited: Jan 5, 2015
  16. EstebanGod

    EstebanGod Member

    Joined:
    Jun 18, 2014
    Messages:
    83
    Likes Received:
    3
    Best Answers:
    0
    - 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?
     
  17. EstebanGod

    EstebanGod Member

    Joined:
    Jun 18, 2014
    Messages:
    83
    Likes Received:
    3
    Best Answers:
    0
    nvm
     
    Last edited: Jan 27, 2015
  18. danne3131

    danne3131 Active Member

    Joined:
    Jun 26, 2008
    Messages:
    375
    Likes Received:
    38
    Best Answers:
    0
    Ive done everything but it doesnt start... its like it doesnt react to the global event... TFS 1.1 Help please :/
     
  19. danne3131

    danne3131 Active Member

    Joined:
    Jun 26, 2008
    Messages:
    375
    Likes Received:
    38
    Best Answers:
    0
    anyone?
     
  20. Prestin32k

    Prestin32k New Member

    Joined:
    Jul 16, 2012
    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    same problem, bump
     

Share This Page

Loading...