Guest User

Untitled

a guest
Dec 12th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. local shootingAllowed = true
  2. local allowJump = true
  3.  
  4. local powerUp1 = false
  5. local powerUp2 = false
  6. local powerUp3 = false
  7. local powerUp4 = false
  8. local powerUp5 = false
  9.  
  10. function resStart ( res )
  11. local keys1,keys2 = getBoundKeys("vehicle_fire"),getBoundKeys("vehicle_secondary_fire")
  12.  
  13. if keys1 then
  14. for keyName, state in pairs(keys1) do
  15. bindKey(keyName, "down", shoot)
  16. end
  17. end
  18. end
  19. addEventHandler ( "onClientResourceStart", resourceRoot, resStart )
  20.  
  21. function bindJumpTrapKey ( pwrUpType )
  22. if( source == localPlayer ) then
  23. if(pwrUpType == "trap") then
  24. outputChatBox ( "#0FC0FC[Power Up] #33FF33You recieved a #EE9900'Trap' #33FF33 power up! Press 'Right mouse button' to release it!", 255, 255, 255, true )
  25. bindKey ( "mouse2", "down", releaseTrap )
  26. elseif (pwrUpType == "jump") then
  27. bindKey ( "mouse2", "down", jump )
  28. outputChatBox ( "#0FC0FC[Power Up] #33FF33You recieved a #EE9900'Jump' #33FF33 power up! Press 'Right mouse button' to jump!", 255, 255, 255, true )
  29. end
  30. end
  31. end
  32. addEvent ( "bindJumpTrap", true )
  33. addEventHandler ( "bindJumpTrap", getRootElement(), bindJumpTrapKey )
  34.  
  35.  
  36. function unbindJumpKey ( )
  37. if( source == localPlayer ) then
  38. unbindKey ( "mouse2", "down", jump )
  39. end
  40. end
  41.  
  42.  
  43. function unbindKeys ( typee )
  44. if( source == localPlayer ) then
  45. if( typee == "jump" ) then
  46. unbindKey ( "mouse2", "down", jump )
  47. elseif ( typee == "trap" ) then
  48. unbindKey ( "mouse2", "down", releaseTrap )
  49. end
  50. end
  51. end
  52. addEvent ( "removeBinds", true )
  53. addEventHandler ( "removeBinds", getRootElement(), unbindKeys )
  54.  
  55.  
  56. function releaseTrap ( )
  57. unbindKey ( "mouse2", "down", releaseTrap )
  58. powerUp4 = false
  59. local x, y, z = getElementPosition ( getPedOccupiedVehicle ( localPlayer ) )
  60. triggerServerEvent ( "releaseTrap", localPlayer, x, y, z )
  61. end
  62.  
  63. function jump ( )
  64. if ( allowJump ) then
  65. allowJump = false
  66. x,y,z = getElementVelocity( getPedOccupiedVehicle ( localPlayer ) )
  67. setElementVelocity ( getPedOccupiedVehicle ( localPlayer ), x, y, z + 0.2 )
  68. setTimer ( allowJumpKey, 2000, 1 )
  69. end
  70. end
  71.  
  72. function allowJumpKey ( )
  73. allowJump = true
  74. end
  75.  
  76. function shoot ()
  77. if shootingAllowed == true then
  78. shootingAllowed = false
  79. if ( powerUp1 ) then
  80. setTimer ( allowShooting, 500, 1 )
  81. else
  82. setTimer ( allowShooting, 3000, 1 )
  83. end
  84. fire()
  85. end
  86. end
  87.  
  88. function fire ( )
  89. vehicle = getPedOccupiedVehicle ( localPlayer )
  90. if vehicle then
  91. if(powerUp2) then
  92. x1, y1, z1 = getPositionOffsetFromElement( vehicle, 1, 3, 0 )
  93. x2, y2, z2 = getPositionOffsetFromElement( vehicle, -1, 3, 0 )
  94.  
  95. createProjectile( vehicle, 19, x1, y1, z1, 1 )
  96. createProjectile( vehicle, 19, x2, y2, z2, 1 )
  97. else
  98. x1, y1, z1 = getPositionOffsetFromElement( vehicle, 0, 3, 0 )
  99. createProjectile( vehicle, 19, x1, y1, z1, 1 )
  100. end
  101. end
  102. end
  103.  
  104. function allowShooting ()
  105. shootingAllowed = true
  106. end
  107.  
  108. function setPwrUpState ( pwrUp, state )
  109. if( source == localPlayer ) then
  110. if ( pwrUp == "pwrUp1" ) then
  111. powerUp1 = state
  112. elseif ( pwrUp == "pwrUp2" ) then
  113. powerUp2 = state
  114. elseif ( pwrUp == "pwrUp3" ) then
  115. powerUp3 = state
  116. elseif ( pwrUp == "pwrUp4" ) then
  117. powerUp4 = state
  118. elseif ( pwrUp == "pwrUp5" ) then
  119. powerUp5 = state
  120. unbindJumpKey()
  121. elseif ( pwrUp == "pwrUp6" ) then
  122. powerUp6 = state
  123. end
  124. end
  125. end
  126. addEvent ( "setPwrUpState", true )
  127. addEventHandler ( "setPwrUpState", getRootElement(), setPwrUpState )
  128.  
  129. -- For a given element, calculate the absolute positon in the world from the offset (ox,oy,oz)
  130.  
  131. function getPositionOffsetFromElement(element,ox,oy,oz)
  132. local offX,offY,offZ,matrix = 0,0,0,getElementMatrix(element)
  133.  
  134. if matrix then
  135. offX = ox * matrix[1][1] + oy * matrix[2][1] + oz * matrix[3][1] + matrix[4][1]
  136. offY = ox * matrix[1][2] + oy * matrix[2][2] + oz * matrix[3][2] + matrix[4][2]
  137. offZ = ox * matrix[1][3] + oy * matrix[2][3] + oz * matrix[3][3] + matrix[4][3]
  138. end
  139.  
  140. return offX, offY, offZ
  141. end
Advertisement
Add Comment
Please, Sign In to add comment