Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. -- Copyright (c) 2017, Alberto Alonso
  2. --
  3. -- All rights reserved.
  4. --
  5. -- Redistribution and use in source and binary forms, with or without modification,
  6. -- are permitted provided that the following conditions are met:
  7. --
  8. --     * Redistributions of source code must retain the above copyright notice, this
  9. --       list of conditions and the following disclaimer.
  10. --     * Redistributions in binary form must reproduce the above copyright notice, this
  11. --       list of conditions and the following disclaimer in the documentation and/or other
  12. --       materials provided with the distribution.
  13. --     * Neither the name of the superman script nor the names of its contributors may be used
  14. --       to endorse or promote products derived from this software without specific prior
  15. --       written permission.
  16. --
  17. -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21. -- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. -- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. local Superman = {}
  29.  
  30. -- Static global values
  31. local rootElement = getRootElement()
  32. local thisResource = getThisResource()
  33.  
  34. local allowedTeams = {
  35.     ["Admins"] = true,
  36.     ["Staff"] = true
  37. }
  38.  
  39. -- Resource events
  40. addEvent("superman:start", true)
  41. addEvent("superman:stop", true)
  42. addEvent("superman:checkRight", true)
  43.  
  44. --
  45. -- Start/stop functions
  46. --
  47.  
  48. function Superman.Start()
  49.   local self = Superman
  50.  
  51.   addEventHandler("superman:start", rootElement, self.clientStart)
  52.   addEventHandler("superman:stop", rootElement, self.clientStop)
  53.   addEventHandler("onPlayerVehicleEnter",rootElement,self.enterVehicle)
  54.   addEventHandler("onPlayerJoin",rootElement,self.updateRight)
  55.   addEventHandler("onPlayerLogin",rootElement,self.updateRight)
  56.   addEventHandler("onPlayerLogout",rootElement,self.updateRight)
  57.   addEventHandler("superman:checkRight",rootElement,self.updateRight)
  58.  
  59. end
  60. addEventHandler("onResourceStart", getResourceRootElement(thisResource), Superman.Start, false)
  61.  
  62. function Superman.clientStart()
  63.   setElementData(client, "superman:flying", true)
  64. end
  65.  
  66. function Superman.clientStop()
  67.   setElementData(client, "superman:flying", false)
  68. end
  69.  
  70. -- Fix for players glitching other players' vehicles by warping into them while superman is active, causing them to flinch into air and get stuck.
  71. function Superman.enterVehicle()
  72.     if getElementData(source,"superman:flying") or getElementData(source,"superman:takingOff") then
  73.         removePedFromVehicle(source)
  74.         local x,y,z = getElementPosition(source)
  75.         setElementPosition(source,x,y,z)
  76.     end
  77. end
  78.  
  79. function Superman.updateRight()
  80.  
  81.     if client ~= source then return end
  82.    
  83.     local isAllowed = false
  84.  
  85.     local team = getPlayerTeam(client)
  86.     local data = getElementData(client, "class")
  87.  
  88.     if team and data then
  89.         if allowedTeams[getTeamName(team)] then
  90.             if data == "Admin" or data == "Staff" then
  91.                 isAllowed = true
  92.             end
  93.         end
  94.     end
  95.    
  96.     triggerClientEvent(source,"superman:updateRight",source,isAllowed)
  97.  
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement