Advertisement
th3w1zard1

OnFlashlightToggle function

Feb 5th, 2012
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 KB | None | 0 0
  1. -- This function is required for scripts to run on Phasor (including and after 01.00.03.104)
  2. -- You should return the minimum required version of Phasor
  3. -- Official releases:
  4. --   01.00.03.104 - 3104
  5. --   01.00.10.057 - 10057
  6.  
  7. function GetRequiredVersion()
  8.     return 10058
  9. end
  10.  
  11. -- called when the script is loaded
  12. function OnScriptLoad(process)
  13. end
  14.  
  15. -- called when the script is unloaded
  16. -- Do not return a value
  17. function OnScriptUnload()
  18. end
  19.  
  20. -- called when a game is starting (before any players join)
  21. -- Do not return a value.
  22. function OnNewGame(map)
  23. end
  24.  
  25. -- called when a game is ending
  26. -- Do not return a value.
  27. function OnGameEnd(mode)
  28.     -- mode 1 = score menu (F1) is being displayed to clients, they are still ingame
  29.     -- mode 2 = post game menu appeared
  30.     -- mode 3 = players can quit via the post game score card
  31. end
  32.  
  33. -- Called when there is chat within the server
  34. -- It must return a value which indicates whether or not the chat is sent.
  35. function OnServerChat(player, chattype, message)
  36.     return 1
  37. end
  38.  
  39. -- Called when a server command is being executed
  40. -- It must return a value which indicates whether or not the command should be processed
  41. -- Note: It is only called when an authenticated (and allowed) player attempts to use the command.
  42. --       player is -1 when being executed via the server console.
  43. function OnServerCommand(player, command)
  44.     return 1
  45. end
  46.  
  47. -- Called when a player's team is being chosen as the join the server.
  48. -- It must return a value which indicates the team the player is to be put on.
  49. -- Note: this function being called doesn't guarantee that the player will be able to successfully join.
  50. function OnTeamDecision(cur_team)
  51.     return cur_team
  52. end
  53.  
  54. -- Called when a player joins the server.
  55. -- Do not return a value.
  56. function OnPlayerJoin(player, team)
  57. end
  58.  
  59. -- Called when a player the server.
  60. -- Do not return a value.
  61. function OnPlayerLeave(player, team)
  62. end
  63.  
  64. -- called when a player kills another, 'killer' is the index of the killing player, 'victim' is the index of the dead player
  65. -- Do not return a value.
  66. function OnPlayerKill(killer, victim, mode)
  67. end
  68.  
  69. -- called when a player gets a double kill, killing spree etc
  70. -- see Phasor documentation for multiplier values
  71. function OnKillMultiplier(player, multiplier)
  72. end
  73.  
  74. -- Called when a player s (after object is created, before players are notified)
  75. -- Do not return a value
  76. function OnPlayerSpawn(player, m_objectId)
  77. end
  78.  
  79. -- Called after clients have been notified of a player spawn
  80. -- Do not return a value
  81. function OnPlayerSpawnEnd(player, m_objectId)
  82.  
  83. end
  84.  
  85. -- Called when a player is attempting to .
  86. -- A value must be returned. The return value indicates whether or not the player is allowed the change team.
  87. -- Notes: If relevant is 1 the return value is considered, if it's 0 then the return value is ignored.
  88. function OnTeamChange(relevant, player, team, dest_team)
  89.     return 1
  90. end
  91.  
  92. -- This is called when a client sends the server an update packet.
  93. -- This includes things such as movement vectors, camera positions, button presses etc.
  94. -- This function is called frequently so care should be taken to keep processing
  95. -- to a minimum.
  96. -- Do not return a value
  97. function OnClientUpdate(player, m_objectId)
  98.  
  99.     local id = resolveplayer(player)
  100.     local m_object = getobject(m_objectId)
  101.     local m_playerObjId = getplayerobjectid(player)
  102.  
  103.     if getobject(readdword(m_object, 0x11C)) == nil then
  104.         local flashlight = readbit(m_object, 0x208, 3) -- 1 when flashlight key is pressed
  105.         local obj_flashlight = readbyte(m_object, 0x206) -- 8 when flashlight is off, 0 when flashlight is on (other way around, but it doesn't update until after this button is clicked)
  106.         if flashlight == 1 and obj_flashlight == 8 then
  107.             local allow = OnFlashlightToggle(player, "off")
  108.             if allow == 0 then
  109.                 writebit(m_object, 0x208, 3, 0) -- Blocks flashlight, does not sync with client
  110.             end
  111.         elseif flashlight == 1 and obj_flashlight == 0 then
  112.             local allow = OnFlashlightToggle(player, "on")
  113.             if allow == 0 then
  114.                 writebit(m_object, 0x208, 3, 0) -- Blocks flashlight, does not sync with client
  115.             end
  116.         end
  117.     end
  118.  
  119. end
  120.  
  121. -- Called when a player interacts with an object
  122. -- It can be called while attempting to pick the object up
  123. -- It is also called when standing above an object so can be called various times quickly
  124. function OnObjectInteraction(player, m_ObjectId, tagType, tagName)
  125.     return 1
  126. end
  127.  
  128. -- Called when a player attempts to reload their weapon.
  129. -- A value must be returned. The return value indicates whether or not the player is allowed to reload.
  130. -- Notes: If player is -1 then the weapon being reload wasn't located (it could be a vehicle's weapon)
  131. function OnWeaponReload(player, weapon)
  132.     return 1
  133. end
  134.  
  135. -- Called when a player attempts to enter a vehicle.
  136. --The return value indicates whether or not the player is allowed to enter.
  137. function OnVehicleEntry(relevant, player, vehicleId, vehicle_tag, seat)
  138.     return 1
  139. end
  140.  
  141. -- Called when a player is being ejected from their vehicle
  142. -- Return 1 or 0 to allow/block it.
  143. function OnVehicleEject(player, forceEject)
  144.     return 1
  145. end
  146.  
  147.  
  148. -- Called when damage is being done to an object.
  149. -- This doesn't always need to be a player.
  150. -- Do not return a value
  151. function OnDamageLookup(receiving_obj, causing_obj, tagdata, tagname)
  152. end
  153.  
  154. -- Called when a player is being assigned a weapon (usually when they spawn)
  155. -- A value must be returned. The return value is the id of the weapon they're to spawn with. Return zero if the weapon shouldn't change.
  156. -- Notes:   This is called for all weapon spawns the player has
  157. --          This is also called with player 255 when vehicles are being assigned weapons.
  158. --          This is only considered if in gametype, the weapon set is 'generic' if not this has no effect.
  159. function OnWeaponAssignment(player, object, count, tag)
  160. end
  161.  
  162. -- Called when an object is created
  163. -- Do not return a value.
  164. function OnObjectCreation(m_objectId, player_owner, tag)
  165. end
  166.  
  167. function OnWeaponSwitch(player, m_playerObjId, cur_weapId, next_weapId)
  168.  
  169. end
  170.  
  171. function OnPlayerCrouch(player, m_objectId)
  172.     return 1
  173. end
  174.  
  175. function OnPlayerJump(player, m_objectId)
  176.     return 1
  177. end
  178.  
  179. function OnPlayerSmack(player, m_objectId)
  180.     return 1
  181. end
  182.  
  183. -- Called when someone turns their flashlight on or off
  184. -- Does not sync with the client, state is "on" or "off"
  185. -- This action can be blocked
  186. function OnFlashlightToggle(player, state)
  187.     return 1
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement