DaBOSS54320

Bully LUA: Rotation Test

Feb 18th, 2016
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.74 KB | None | 0 0
  1. -- GOAL: Rotate multiple peds around a single point (represented by a blip)
  2.  
  3. function main()
  4.     -- Initialize game:
  5.     Wait(500)
  6.    
  7.     -- Variables:
  8.     local pedCount = 8 -- the amount of peds
  9.     local rotationTime = 5000 -- time it should take for a full rotation
  10.     local distance = 5 -- the distance from the blip the ped will be set to
  11.     local x,y,z = 270,-110,6 -- rotation origin
  12.     local t = -1 -- start time, -1 if not started
  13.     local stoppedPeds = false -- if the peds have been stopped from wandering yet
  14.    
  15.     -- Spawn blip:
  16.     local blip = BlipAddXYZ(x,y,z,25,1,1)
  17.    
  18.     -- Spawn test subjects:
  19.     local peds = {}
  20.     for i = 1,pedCount do
  21.         local ped = PedCreateXYZ(math.random(2,48),270+math.random(-10,10),-110+math.random(-10,10),6)
  22.         BlipSetShortRanged(AddBlipForChar(ped,0,0,4),true)
  23.         PedWander(ped)
  24.         table.insert(peds,ped)
  25.     end
  26.    
  27.     -- Main loop:
  28.     while true do
  29.         if t ~= -1 then -- rotation started
  30.             -- Get rotation:
  31.             local timePassed = (GetTimer()-t)/rotationTime -- result will be 0.0-1.0 based on how complete the rotation is (or above 1.0 if it is passed the ending time)
  32.             local rot = 6.28319*timePassed -- a 360 degree rotation (in radians) multiplied by timePassed, if the rotation just started then timePassed would be 0 this will be 0, if it is at the end then timePassed will be 1 so this will be the full 6.28319, if timePassed is 0.5 then this would be half of 6.28319 (180 degrees), and so on
  33.            
  34.             -- Process peds:
  35.             for i,ped in ipairs(peds) do
  36.                 -- Stop the ped (from wandering):
  37.                 if not stoppedPeds then
  38.                     PedStop(ped)
  39.                 end
  40.                
  41.                 -- Get offset (how different this ped will be from the rest, and what will be added to rot):
  42.                 local offset = 6.28319*(i/table.getn(peds)) -- i / amount of peds, if there are 4 peds for example then there will be 1/4 (0.25) for the first ped, 2/4 (0.5) for the second, 3/4 (0.75) for the third, and 4/4 (1) for the fourth. this multiplied by a full 360 degree rotation is how far this ped should be rotated from the base rotation angle (the rot we calculated above)
  43.                
  44.                 -- Get position:
  45.                 local pedRot = rot + offset -- rot + offset, the rotation this ped should be given
  46.                 local px,py,pz = PedGetPosXYZ(ped) -- x and y will be changed but z will remain the same
  47.                 px = x - math.sin(pedRot)*distance -- the x coordinate for the ped
  48.                 py = y + math.cos(pedRot)*distance -- the y coordinate for the ped
  49.                
  50.                 -- Set position and heading:
  51.                 PedSetPosXYZ(ped,px,py,pz)
  52.                 PedFaceXYZ(ped,x,y,z)
  53.             end
  54.            
  55.             -- Now that the loop has been processed at least once, set this to false (we don't need to stop the peds twice):
  56.             stoppedPeds = true
  57.            
  58.             -- Wait:
  59.             Wait(0)
  60.         elseif PedMePlaying(gPlayer,"Default_KEY") and PedIsInAreaXYZ(gPlayer,x,y,z,0.7) then -- player in blip area
  61.             TextPrintString("Press \b to begin",0,2)
  62.             Wait(0)
  63.             if PedMePlaying(gPlayer,"Default_KEY") and IsButtonBeingPressed(9,0) then
  64.                 t = GetTimer()
  65.             end
  66.         else -- rotation did not start and player is not in blip area
  67.             Wait(0)
  68.         end
  69.     end
  70. end
  71.  
  72. -- STimeCycle functions:
  73. F_AttendedClass = function()
  74.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  75.         return
  76.     end
  77.     SetSkippedClass(false)
  78.     PlayerSetPunishmentPoints(0)
  79. end
  80.  
  81. F_MissedClass = function()
  82.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  83.         return
  84.     end
  85.     SetSkippedClass(true)
  86.     StatAddToInt(166)
  87. end
  88.  
  89. F_AttendedCurfew = function()
  90.     if not PedInConversation(gPlayer) and not MissionActive() then
  91.         TextPrintString("You got home in time for curfew", 4)
  92.     end
  93. end
  94.  
  95. F_MissedCurfew = function()
  96.     if not PedInConversation(gPlayer) and not MissionActive() then
  97.         TextPrint("TM_TIRED5", 4, 2)
  98.     end
  99. end
  100.  
  101. F_StartClass = function()
  102.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  103.         return
  104.     end
  105.     F_RingSchoolBell()
  106.     local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
  107. end
  108.  
  109. F_EndClass = function()
  110.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  111.         return
  112.     end
  113.     F_RingSchoolBell()
  114. end
  115.  
  116. F_StartMorning = function()
  117.     F_UpdateTimeCycle()
  118. end
  119.  
  120. F_EndMorning = function()
  121.     F_UpdateTimeCycle()
  122. end
  123.  
  124. F_StartLunch = function()
  125.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  126.         F_UpdateTimeCycle()
  127.         return
  128.     end
  129.     F_UpdateTimeCycle()
  130. end
  131.  
  132. F_EndLunch = function()
  133.     F_UpdateTimeCycle()
  134. end
  135.  
  136. F_StartAfternoon = function()
  137.     F_UpdateTimeCycle()
  138. end
  139.  
  140. F_EndAfternoon = function()
  141.     F_UpdateTimeCycle()
  142. end
  143.  
  144. F_StartEvening = function()
  145.     F_UpdateTimeCycle()
  146. end
  147.  
  148. F_EndEvening = function()
  149.     F_UpdateTimeCycle()
  150. end
  151.  
  152. F_StartCurfew_SlightlyTired = function()
  153.     F_UpdateTimeCycle()
  154. end
  155.  
  156. F_StartCurfew_Tired = function()
  157.     F_UpdateTimeCycle()
  158. end
  159.  
  160. F_StartCurfew_MoreTired = function()
  161.     F_UpdateTimeCycle()
  162. end
  163.  
  164. F_StartCurfew_TooTired = function()
  165.     F_UpdateTimeCycle()
  166. end
  167.  
  168. F_EndCurfew_TooTired = function()
  169.     F_UpdateTimeCycle()
  170. end
  171.  
  172. F_EndTired = function()
  173.     F_UpdateTimeCycle()
  174. end
  175.  
  176. F_Nothing = function()
  177. end
  178.  
  179. F_ClassWarning = function()
  180.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  181.         return
  182.     end
  183.     local l_23_0 = math.random(1, 2)
  184. end
  185.  
  186. F_UpdateTimeCycle = function()
  187.     if not IsMissionCompleated("1_B") then
  188.         local l_24_0 = GetCurrentDay(false)
  189.         if l_24_0 < 0 or l_24_0 > 2 then
  190.             SetCurrentDay(0)
  191.         end
  192.     end
  193.     F_UpdateCurfew()
  194. end
  195.  
  196. F_UpdateCurfew = function()
  197.     local l_25_0 = shared.gCurfewRules
  198.     if not l_25_0 then
  199.         l_25_0 = F_CurfewDefaultRules
  200.     end
  201.     l_25_0()
  202. end
  203.  
  204. F_CurfewDefaultRules = function()
  205.     local l_26_0 = ClockGet()
  206.     if l_26_0 >= 23 or l_26_0 < 7 then
  207.         shared.gCurfew = true
  208.     else
  209.         shared.gCurfew = false
  210.     end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment