Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GOAL: Rotate multiple peds around a single point (represented by a blip)
- function main()
- -- Initialize game:
- Wait(500)
- -- Variables:
- local pedCount = 8 -- the amount of peds
- local rotationTime = 5000 -- time it should take for a full rotation
- local distance = 5 -- the distance from the blip the ped will be set to
- local x,y,z = 270,-110,6 -- rotation origin
- local t = -1 -- start time, -1 if not started
- local stoppedPeds = false -- if the peds have been stopped from wandering yet
- -- Spawn blip:
- local blip = BlipAddXYZ(x,y,z,25,1,1)
- -- Spawn test subjects:
- local peds = {}
- for i = 1,pedCount do
- local ped = PedCreateXYZ(math.random(2,48),270+math.random(-10,10),-110+math.random(-10,10),6)
- BlipSetShortRanged(AddBlipForChar(ped,0,0,4),true)
- PedWander(ped)
- table.insert(peds,ped)
- end
- -- Main loop:
- while true do
- if t ~= -1 then -- rotation started
- -- Get rotation:
- 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)
- 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
- -- Process peds:
- for i,ped in ipairs(peds) do
- -- Stop the ped (from wandering):
- if not stoppedPeds then
- PedStop(ped)
- end
- -- Get offset (how different this ped will be from the rest, and what will be added to rot):
- 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)
- -- Get position:
- local pedRot = rot + offset -- rot + offset, the rotation this ped should be given
- local px,py,pz = PedGetPosXYZ(ped) -- x and y will be changed but z will remain the same
- px = x - math.sin(pedRot)*distance -- the x coordinate for the ped
- py = y + math.cos(pedRot)*distance -- the y coordinate for the ped
- -- Set position and heading:
- PedSetPosXYZ(ped,px,py,pz)
- PedFaceXYZ(ped,x,y,z)
- end
- -- Now that the loop has been processed at least once, set this to false (we don't need to stop the peds twice):
- stoppedPeds = true
- -- Wait:
- Wait(0)
- elseif PedMePlaying(gPlayer,"Default_KEY") and PedIsInAreaXYZ(gPlayer,x,y,z,0.7) then -- player in blip area
- TextPrintString("Press \b to begin",0,2)
- Wait(0)
- if PedMePlaying(gPlayer,"Default_KEY") and IsButtonBeingPressed(9,0) then
- t = GetTimer()
- end
- else -- rotation did not start and player is not in blip area
- Wait(0)
- end
- end
- end
- -- STimeCycle functions:
- F_AttendedClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- SetSkippedClass(false)
- PlayerSetPunishmentPoints(0)
- end
- F_MissedClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- SetSkippedClass(true)
- StatAddToInt(166)
- end
- F_AttendedCurfew = function()
- if not PedInConversation(gPlayer) and not MissionActive() then
- TextPrintString("You got home in time for curfew", 4)
- end
- end
- F_MissedCurfew = function()
- if not PedInConversation(gPlayer) and not MissionActive() then
- TextPrint("TM_TIRED5", 4, 2)
- end
- end
- F_StartClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- F_RingSchoolBell()
- local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
- end
- F_EndClass = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- F_RingSchoolBell()
- end
- F_StartMorning = function()
- F_UpdateTimeCycle()
- end
- F_EndMorning = function()
- F_UpdateTimeCycle()
- end
- F_StartLunch = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- F_UpdateTimeCycle()
- return
- end
- F_UpdateTimeCycle()
- end
- F_EndLunch = function()
- F_UpdateTimeCycle()
- end
- F_StartAfternoon = function()
- F_UpdateTimeCycle()
- end
- F_EndAfternoon = function()
- F_UpdateTimeCycle()
- end
- F_StartEvening = function()
- F_UpdateTimeCycle()
- end
- F_EndEvening = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_SlightlyTired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_Tired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_MoreTired = function()
- F_UpdateTimeCycle()
- end
- F_StartCurfew_TooTired = function()
- F_UpdateTimeCycle()
- end
- F_EndCurfew_TooTired = function()
- F_UpdateTimeCycle()
- end
- F_EndTired = function()
- F_UpdateTimeCycle()
- end
- F_Nothing = function()
- end
- F_ClassWarning = function()
- if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
- return
- end
- local l_23_0 = math.random(1, 2)
- end
- F_UpdateTimeCycle = function()
- if not IsMissionCompleated("1_B") then
- local l_24_0 = GetCurrentDay(false)
- if l_24_0 < 0 or l_24_0 > 2 then
- SetCurrentDay(0)
- end
- end
- F_UpdateCurfew()
- end
- F_UpdateCurfew = function()
- local l_25_0 = shared.gCurfewRules
- if not l_25_0 then
- l_25_0 = F_CurfewDefaultRules
- end
- l_25_0()
- end
- F_CurfewDefaultRules = function()
- local l_26_0 = ClockGet()
- if l_26_0 >= 23 or l_26_0 < 7 then
- shared.gCurfew = true
- else
- shared.gCurfew = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment