Zombie Event BETA! [Tfs 1.0] Vers: 0.5

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Printer, Apr 24, 2014.

  1. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Hello,

    Comment any suggestions and etc...

    Features:
    *Optimized
    *Min Players/Max Players
    *Trophy reward with description!
    *Max Zombies
    *Zombie dont summon on walls
    *Automatic start through globalevent
    *Cleaning zombies after event end
    *Join also through talkaction
    *Etc...

    Creaturescripts:
    in creaturescripts/creaturescripts.xml add these lines:
    Code (Text):
    1. <event type="preparedeath" name="ZE_Death" script="zombie_death.lua"/>
    2. <event type="death" name="ZE_Mon_Death" script="zombie_death.lua"/>
    and inside creaturescripts/scripts create lua and name it: zombie_death.lua
    Code (Text):
    1. dofile('data/zombie_system.lua')
    2.  
    3. function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    4.     local monster = Monster(cid)
    5.     monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
    6.     monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)
    7.     doSummonZombie()
    8.     Game.setStorageValue(zeZombieCountGlobalStorage, Game.getStorageValue(zeZombieCountGlobalStorage) - 1)
    9. end
    10.  
    11. function onPrepareDeath(cid, killer)
    12.     local player = Player(cid)
    13.     local winner = 0
    14.     if player:getStorageValue(zeJoinStorage) == 1 then
    15.         Game.setStorageValue(zeJoinedCountGlobalStorage, Game.getStorageValue(zeJoinedCountGlobalStorage) - 1)
    16.         player:teleportTo(player:getTown():getTemplePosition())
    17.         player:setStorageValue(zeJoinStorage, 0)
    18.         player:addHealth(player:getMaxHealth())
    19.         if Game.getStorageValue(zeJoinedCountGlobalStorage) <= 1 then --Event ended, someone won!
    20.             local players = Game.getPlayers()
    21.             for _, tmpPlayer in ipairs(players) do
    22.                 local stor = tmpPlayer:getStorageValue(zeJoinStorage)
    23.                 if stor == 1 then
    24.                     winner = tmpPlayer:getId()
    25.                     break
    26.                 end
    27.             end
    28.             winner = Player(winner)
    29.             if winner then
    30.                 winner:teleportTo(winner:getTown():getTemplePosition())
    31.                 local trophy = winner:addItem(zeTrophy, 1)
    32.                 if trophy then
    33.                     trophy:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, '['.. winner:getName() ..'] has won the Zombie Event.')
    34.                 end
    35.                  Game.broadcastMessage(string.format('%s is the winner of Zombie Event Versus %s Zombies.', winner:getName(), Game.getStorageValue(zeZombieCountGlobalStorage)), MESSAGE_STATUS_WARNING)
    36.             end
    37.             doClearZombieArena()
    38.             resetVariables()
    39.         end
    40.         return false
    41.     end
    42.     return true
    43. end
    Now go into login.lua and paste this under PlayerDeath registration:
    Code (Text):
    1. player:registerEvent("ZE_Death")
    2.     if player:getStorageValue(1000) == 1 then --write ze_join_storage number here
    3.         player:setStorageValue(1000, 0) --write ze_join_storage number here
    4.     end
    Globalevents:
    in globalevents/globalevents.xml add this line:
    Code (Text):
    1. <globalevent name="zombie" interval="7200000" script="zombie_think.lua"/>
    and in globalevents/scripts create new lua and name it: zombie_think.lua
    Code (Text):
    1. dofile('data/zombie_system.lua')
    2.  
    3. function onThink(interval, lastExecution, thinkInterval)
    4.     if Game.getStorageValue(zeStartedGlobalStorage) < 1 then
    5.         local teleport = Game.createItem(1387, 1, zeCreateTeleportPosition)
    6.         if teleport then
    7.             teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, 7000)
    8.         end
    9.         Game.setStorageValue(zeStartedGlobalStorage, 1)
    10.         print('Zombie Event has started & waiting for players to join! Min: '.. zeMinPlayers ..'/'.. zeMaxPlayers ..'.')
    11.         Game.broadcastMessage('The Zombie Event has started! You have '.. zeWaitMinutes ..' minutes to join!', MESSAGE_STATUS_WARNING)
    12.         addEvent(startZombie, zeWaitMinutes * 60 * 1000)
    13.     end
    14.     return true
    15. end
    Movements:
    in movements/movements.xml add this line:
    Code (Text):
    1. <movevent event="StepIn" uniqueid="7000" script="zombie_teleport.lua"/>
    and now create new lua in movements/scripts and name it: zombie_teleport.lua
    Code (Text):
    1. dofile('data/zombie_system.lua')
    2.  
    3. function onStepIn(cid, item, position, fromPosition)
    4.         local player = Player(cid)
    5.     if not player then
    6.             return false
    7.         end
    8.  
    9.         if Game.getStorageValue(zeStartedGlobalStorage) == 2 then
    10.             player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event has already started.')
    11.             player:teleportTo(fromPosition, true)
    12.             return false
    13.         end
    14.  
    15.         if Game.getStorageValue(zeStartedGlobalStorage) == 0 then
    16.             player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event has not started yet.')
    17.             player:teleportTo(fromPosition, true)
    18.             return false
    19.         end
    20.  
    21.        if Game.getStorageValue(zeJoinedCountGlobalStorage) > zeMaxPlayers then
    22.             player:teleportTo(fromPosition, true)
    23.             player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event is already full! ['.. Game.getStorageValue(zeJoinedCountGlobalStorage) ..'/'.. zeMaxPlayers ..']')
    24.             return false
    25.         end
    26.  
    27.         player:teleportTo(zeWaitingRoomPos)
    28.         Game.setStorageValue(zeJoinedCountGlobalStorage, Game.getStorageValue(zeJoinedCountGlobalStorage) + 1)
    29.         Game.broadcastMessage(string.format('%s has joined the Zombie Event! [%s/'.. zeMaxPlayers ..'].', player:getName(), Game.getStorageValue(zeJoinedCountGlobalStorage)), MESSAGE_STATUS_WARNING)
    30.         player:setStorageValue(zeJoinStorage, 1)
    31.         return true
    32. end
    Create new xml file and name it: Zombie_Event.xml
    Code (Text):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <monster name="Zombie" nameDescription="a zombie" race="undead" experience="0" speed="100" manacost="0">
    3.     <health now="500" max="500"/>
    4.     <look type="311" corpse="0"/>
    5.     <targetchange interval="4000" chance="10"/>
    6.     <strategy attack="100" defense="0"/>
    7.     <flags>
    8.         <flag summonable="0"/>
    9.         <flag attackable="1"/>
    10.         <flag hostile="1"/>
    11.         <flag illusionable="0"/>
    12.         <flag convinceable="0"/>
    13.         <flag pushable="0"/>
    14.         <flag canpushitems="1"/>
    15.         <flag canpushcreatures="1"/>
    16.         <flag targetdistance="1"/>
    17.         <flag staticattack="90"/>
    18.         <flag runonhealth="0"/>
    19.     </flags>
    20.     <attacks>
    21.         <attack name="melee" interval="2000" skill="9999999" attack="9999999"/>
    22.     </attacks>
    23.     <defenses armor="15" defense="15"/>
    24.     <elements>
    25.         <element firePercent="50"/>
    26.     </elements>
    27.     <immunities>
    28.         <immunity death="1"/>
    29.         <immunity energy="1"/>
    30.         <immunity ice="1"/>
    31.         <immunity earth="1"/>
    32.         <immunity drown="1"/>
    33.         <immunity drunk="1"/>
    34.         <immunity lifedrain="1"/>
    35.         <immunity paralyze="1"/>
    36.     </immunities>
    37.     <voices interval="5000" chance="10">
    38.         <voice sentence="Mst.... klll...."/>
    39.         <voice sentence="Whrrrr... ssss.... mmm.... grrrrl"/>
    40.         <voice sentence="Dnnnt... cmmm... clsrrr...."/>
    41.         <voice sentence="Httt.... hmnnsss..."/>
    42.     </voices>
    43.     <script>
    44.             <event name="ZE_Mon_Death"/>
    45.         </script>
    46. </monster>
    Go to part2, to add the other functions
     
    Last edited: Sep 5, 2014
  2. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Now in same folder as global.lua or compat.lua, create new lua and name it: zombie_system.lua
    Code (Text):
    1. -- Zombie Variables
    2. zeZombieName = 'Zombie Event' --Zombie Name
    3. zombieSpawnInterval = 5 --how many seconds until a new zombie spawns
    4. zeMaxZombies = 20 --max zombies in the arena?
    5. zeJoinedCountGlobalStorage = 100 --Player joined event count
    6.  
    7. -- Players Variables
    8. zeJoinStorage = 1000 --player join storage
    9. zeMinPlayers = 1 --min players needed when time runout
    10. zeMaxPlayers = 5 --max players to join
    11. zeTrophy = 7369 --trophy itemid
    12. zeJoinedCountGlobalStorage = 101 --Zombie spawned Count
    13.  
    14. -- Other Variables
    15. zeWaitMinutes = 1 --when event has opened, how long until it starts?
    16. zeWaitingRoomPos = Position(1998, 1999, 5) --middle of waiting room
    17. zeZombieArena = Position(2000, 2000, 6) --when even start where should player be teleported in the zombie arena?
    18. zeArenaFromPosition = Position(1995, 1996, 5) --pos of top left corner
    19. zeArenaToPosition = Position(2001, 2003, 5) --pos of bottom right corner
    20. zeMiddleZombieArena = Position(1998, 1999, 5) --Middle pos of the arena
    21. zeWaitingRoomRadiusX = 20 --depends how big the waiting room is 20sqm to x
    22. zeWaitingRoomRadiusY = 20 --depends how big the waiting room is 20sqm to y
    23. zeZombieArenaRadiusX = 50 --Depends how big the zombie arena is 50sqm to x
    24. zeZombieArenaRadiusY = 50 --Depends how big the zombie arena is 50sqm to y
    25. zeStartedGlobalStorage = 102 -- Value: 0 == false, 1 == true, 2 == started --State of the event
    26. zeCreateTeleportPosition = Position(1000, 1000, 7) --Where should the teleport be created?
    27.  
    28. function startZombie()
    29.     local specs = Game.getSpectators(zeWaitingRoomPos, false, true, 0, zeWaitingRoomRadiusX, 0, zeWaitingRoomRadiusY)
    30.         if Game.getStorageValue(zeJoinedCountGlobalStorage) < zeMinPlayers then
    31.             for i = 1, #specs do
    32.                     specs[i]:teleportTo(specs[i]:getTown():getTemplePosition(), false)
    33.                     specs[i]:setStorageValue(zeJoinStorage, 0)
    34.             end
    35.             resetVariables()
    36.             Game.broadcastMessage('Zombie Event failed to start, because of to little players joined the event!', MESSAGE_STATUS_WARNING)
    37.             return true
    38.         end
    39.  
    40.         for i = 1, #specs do
    41.             specs[i]:teleportTo(zeZombieArena)
    42.         end
    43.         Game.broadcastMessage("Zombie Event has started, good luck to all participant.", MESSAGE_STATUS_WARNING)
    44.         Game.setStorageValue(zeStartedGlobalStorage, 2)
    45.         doStartZombieEvasion()
    46. end
    47.  
    48. function doSummonZombie()
    49.         if Game.getStorageValue(zeZombieCountGlobalStorage) > zeMaxZombies then
    50.             return false
    51.         end
    52.  
    53.         local zombie = Game.createMonster(zeZombieName, {x = math.random(zeArenaFromPosition.x, zeArenaToPosition.x), y = math.random(zeArenaFromPosition.y, zeArenaToPosition.y), z = math.random(zeArenaFromPosition.z, zeArenaToPosition.z)})
    54.         if zombie then
    55.             Game.createMonster(zeZombieName, {x = math.random(zeArenaFromPosition.x, zeArenaToPosition.x), y = math.random(zeArenaFromPosition.y, zeArenaToPosition.y), z = math.random(zeArenaFromPosition.z, zeArenaToPosition.z)})
    56.         end
    57.         Game.setStorageValue(zeZombieCountGlobalStorage, Game.getStorageValue(zeZombieCountGlobalStorage) + 1)
    58. end
    59.  
    60. function doStartZombieEvasion()
    61.         if Game.getStorageValue(zeStartedGlobalStorage) == 2 then
    62.                doSummonZombie()
    63.             addEvent(doStartZombieEvasion, 5 * 1000)
    64.         end
    65. end
    66.  
    67. function resetVariables()
    68.         Game.setStorageValue(zeJoinedCountGlobalStorage, 0)
    69.         Game.setStorageValue(zeZombieCountGlobalStorage, 0)
    70.         Game.setStorageValue(zeStartedGlobalStorage, 0)
    71. end
    72.  
    73. function doClearZombieArena()
    74.         local specs = Game.getSpectators(zeMiddleZombieArena, false, false, 0, zeZombieArenaRadiusX, 0, zeZombieArenaRadiusY)
    75.         for i = 1, #specs do
    76.             if specs[i]:getName() == zeZombieName then
    77.                     specs[i]:remove()
    78.             end
    79.         end
    80. end
    You can also make them join through talkaction:

    Add this into talkactions/talkactions.xml
    Code (Text):
    1. <talkaction words="!zombie" script="zombie_join.lua"/>
    and now go to talkactions/scripts and create new lua and name it "zombie_join.lua"

    Code (Text):
    1. dofile('data/zombie_system.lua')
    2.  
    3. function onSay(cid, words, param)
    4.     local player = Player(cid)
    5.  
    6.     if Game.getStorageValue(zeStartedGlobalStorage) == 2 then
    7.         player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event has already started.')
    8.         return false
    9.     end
    10.  
    11.    if Game.getStorageValue(zeStartedGlobalStorage) < 1 then
    12.         player:sendTextMessage(MESSAGE_INFO_DESCR, "The Zombie Event has not started yet.")
    13.         return false
    14.     end
    15.  
    16.     if Game.getStorageValue(zeJoinedCountGlobalStorage) > zeMaxPlayers then
    17.         player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event is already full! ['.. Game.getStorageValue(zeJoinedCountGlobalStorage) ..'/'.. zeMaxPlayers ..']')
    18.         return false
    19.     end
    20.  
    21.     if player:isPzLocked() then
    22.         player:sendCancelMessage('You can\'t join the zombie while you are in a fight!')
    23.         return false
    24.     end
    25.    
    26.     player:teleportTo(zeWaitingRoomPos)
    27.     if not player:getGroup():getAccess() then
    28.         Game.setStorageValue(zeJoinedCountGlobalStorage, Game.getStorageValue(zeJoinedCountGlobalStorage) + 1)
    29.         Game.broadcastMessage(string.format('%s has joined the Zombie Event! [%s/'.. zeMaxPlayers ..'].', player:getName(), Game.getStorageValue(zeJoinedCountGlobalStorage)), MESSAGE_STATUS_WARNING)
    30.         player:setStorageValue(zeJoinStorage, 1)
    31.     end
    32.     return false
    33. end
     
    Last edited: Sep 12, 2014
  3. Testerus

    Testerus Active Member

    Joined:
    Mar 18, 2014
    Messages:
    674
    Likes Received:
    125
    Best Answers:
    0
    You're the best.
    Honor Printer guys, GG WP
     
  4. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Ill try to post a example of map with the posistions, so you guys get the idea how to configure it.
     
  5. Mestor

    Mestor Active Member

    Joined:
    Feb 1, 2009
    Messages:
    501
    Likes Received:
    33
    Best Answers:
    0
    Awesome <3
     
  6. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    can you make it when I type !zombie I will teleported to the waiting room but if the event is closed no one can enter with !zombie and if there are enough players to start the event !zombie says that it is full.
    sorry for bad english
     
  7. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
  8. Summ

    Summ (\/)(;,,;)(\/) Y not? Staff Member Global Moderator

    Joined:
    Oct 15, 2008
    Messages:
    4,133
    Likes Received:
    1,033
    Best Answers:
    2
    Why do you broadcast once for each player?
    Code (Text):
    1.  
    2. for _, tmpPlayer in ipairs(Game.getPlayers()) do
    3.   broadcastMessage("The Zombie Event has started! You have "..ze_wait_minutes.." minutes to join!", MESSAGE_STATUS_WARNING)
    4. end
    5.  
    Also, it does not seems to clean the spawned Zombies when finished.
     
    Printer likes this.
  9. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Ups my fault there, thanks for notice that.

    As i said, its still on beta stage, i may forgot some functions to add ^^
     
  10. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Added clean function and also join zombie through talkaction.
     
  11. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    the zombie is attacking me instead of tp me out
    and the winner will get his reward but stay in the area
     
  12. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Ive fixed that winner now is tped out, so update the zombie_death.lua.

    Also could you explain what you mean about "the zombie is attacking me instead of tp me out"
     
  13. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    normally you will be thrown out as soon as you get hit 1 time but now the zombie attacks me and I just thrown out there when I'm dead
     
  14. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    Well, it can be fixed also by change the dmg on the zombie, recopy the Zombie file.
     
  15. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    Lua Script Error: [CreatureScript Interface]
    data/creaturescripts/scripts/zombie_death.lua:eek:nPrepareDeath
    data/creaturescripts/scripts/zombie_death.lua:33: attempt to call global 'doClearZombieArena' (a nil value)
    stack traceback:
    [C]: in function 'doClearZombieArena'
    data/creaturescripts/scripts/zombie_death.lua:33: in function <data/creaturescripts/scripts/zombie_death.lua:10>
     
  16. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    The clear zombie function is missing, did you recopy the zombie_system.lua?
     
  17. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    only the zombie mob. I will copy the system.lua again
     
  18. ricotje1

    ricotje1 Member

    Joined:
    Nov 8, 2012
    Messages:
    234
    Likes Received:
    2
    Best Answers:
    0
    recopied the files but still this error:

    Lua Script Error: [CreatureScript Interface]
    data/creaturescripts/scripts/zombie_death.lua:eek:nPrepareDeath
    attempt to index a nil value
    stack traceback:
    [C]: ?
    [C]: in function 'getSpectators'
    data/zombie_system.lua:68: in function 'doClearZombieArena'
    data/creaturescripts/scripts/zombie_death.lua:33: in function <data/creaturescripts/scripts/zombie_death.lua:10>
     
  19. Printer

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

    Joined:
    Dec 27, 2009
    Messages:
    5,602
    Likes Received:
    1,892
    Best Answers:
    5
    I cant reproduce that error.
     
  20. Seksy

    Seksy Member

    Joined:
    May 20, 2012
    Messages:
    379
    Likes Received:
    21
    Best Answers:
    0
    so how does this event function? Is it so that zombies attack you and you loose or must all players fight untill one remains or must all survive X number of waves?

    Best way would be all players fight to survive X number or waves, each player gets 3 lives or 3 attempts, at end of waves all players get a prize.
     

Share This Page

Loading...