DaBOSS54320

Bully LUA: Insanity Edition

Jul 28th, 2016
844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 77.74 KB | None | 0 0
  1. -- INSANITY EDITION 3.0
  2.  
  3. --[[ TO ADD:
  4.     Shady/police jobs
  5.     More errands
  6. ]]
  7.  
  8. -- Debug settings:
  9. gForceNormalPeds = nil -- make all peds normal
  10. gForceWeaponChance = nil -- override chance of peds having weapons
  11. gForceMoreEvents = nil -- spawn events more frequently
  12. gForceMoreErrands = nil -- spawn errands more frequently
  13. gForceSlowSheldonator = nil -- lower the sheldonator's speed for testing
  14. gDebugTests = nil -- create test functions and spawn a debug blip in Jimmy's room
  15. gDebugSlingshot = nil -- debugger's slingshot, player's slingshot is twice as fast and 1000x as powerful
  16.  
  17. -- Settings:
  18. gSettings = {
  19.     peds = {
  20.         normalChance = (gForceNormalPeds and 100) or 2, -- percent chance a ped will not be ignored by the peds thread
  21.         stats = { -- stats that can get fucked up, how much, and how frequently
  22.             -- [stat] = {chance,minMult,maxMult}
  23.             -- [stat] = {chance,fixedValue}
  24.             [6] = {50,0,0.5},
  25.             [7] = {25,1,3},
  26.             [8] = {10,1.5,10},
  27.             [9] = {40,2,10},
  28.             [10] = {20,1,10},
  29.             [11] = {75,4,12},
  30.             [12] = {7,2,20},
  31.             [13] = {10,2,50},
  32.             [14] = {20,2,10},
  33.             [15] = {75,9999999},
  34.             [20] = {6,0.05,3.4},
  35.             [31] = {7,0,20},
  36.             [33] = {10,100},
  37.             [34] = {15,2,30},
  38.             [35] = {50,2,5},
  39.             [36] = {50,0.1,9},
  40.             [37] = {50,0.2,10},
  41.             [38] = {20,0.5,10},
  42.             [39] = {10,0.5,9},
  43.             [44] = {20,2,3},
  44.             [61] = {10,0.5,7},
  45.             [62] = {4,0},
  46.             [63] = {20,0.1,9},
  47.         },
  48.         infiniteSprintChance = 13, -- chance of having infinite sprint
  49.         healthMult = {6,0.01,17}, -- health multiplier ({chance,minMult,maxMult})
  50.         weaponChance = gForceWeaponChance or 35, -- percent chance that a ped will get a random weapon
  51.         weapons = {300,301,302,303,305,307,309,310,311,313,315,320,321,323,324,326,327,329,335,338,341,342,346,348,349,354,355,358,363,372,397,400,404,409,410,418}, -- weapons that can be randomly set on a ped
  52.         pedEventTimeFromSpawn = {0,15000}, -- time it takes for a ped event to happen per ped from spawn ({minTime,maxTime})
  53.         pedEventTimeAfterSpawn = {10000,50000}, -- time it takes for a ped event to happen per ped after one has already happened ({minTime,maxTime})
  54.     },
  55.     events = {
  56.         initialTime = 5000, -- time it takes for first event to start
  57.         timeRange = (gForceMoreEvents and {1000,5000}) or {30000,120000}, -- time it takes for an event to start after the first
  58.     },
  59.     errands = {
  60.         timeRange = (gForceMoreErrands and {1000,5000}) or {60000,300000}, -- time it takes for an errand to start (reset after missions)
  61.     },
  62. }
  63.  
  64. --[[ T_Peds:
  65.     Fucks up all NPC peds, randomizing stats as they spawn, and periodically making them do random shit.
  66.     Peds can be flagged as mission peds by using PED_SetMissionPed(ped,true), this will make the T_Peds thread ignore them.
  67. ]]
  68. function T_Peds()
  69.     -- Variables:
  70.     local settings = gSettings.peds
  71.     local peds = {}
  72.     gIgnorePeds = {[gPlayer] = true}
  73.     gPedEvents = {
  74.         F_PE_Attack,
  75.         F_PE_AttackPlayer,
  76.         F_PE_Dance,
  77.         F_PE_Headbutt,
  78.         F_PE_LayDown,
  79.         F_PE_Vomit,
  80.         F_PE_PunchCombo,
  81.         F_PE_HateEveryone,
  82.         F_PE_JoinPlayer,
  83.         F_PE_Workout,
  84.         F_PE_Spin,
  85.         F_PE_Complain,
  86.         F_PE_Scream,
  87.         F_PE_Flee,
  88.     }
  89.    
  90.     -- Main loop:
  91.     while true do
  92.         -- Get all peds:
  93.         gAllPeds = {PedFindInAreaXYZ(0,0,0,9999999)}
  94.         table.remove(gAllPeds,1)
  95.        
  96.         -- Process peds:
  97.         for i,ped in ipairs(gAllPeds) do
  98.             if not PedIsValid(ped) or PedIsModel(ped,136) then
  99.                 table.remove(gAllPeds,i)
  100.                 i = i - 1
  101.             elseif not gIgnorePeds[ped] then
  102.                 local t = peds[ped]
  103.                 if not t then
  104.                     -- At spawn (initialize ped):
  105.                     if chance(settings.normalChance) then
  106.                         -- Ignore ped (make normal):
  107.                         gIgnorePeds[ped] = true
  108.                     else
  109.                         -- Set stats:
  110.                         for i,v in pairs(settings.stats) do
  111.                             if chance(v[1]) then
  112.                                 if v[3] then
  113.                                     GameSetPedStat(ped,i,GameGetPedStat(ped,i)*(math.random(v[2]*100,v[3]*100)/100))
  114.                                 else
  115.                                     GameSetPedStat(ped,i,v[2])
  116.                                 end
  117.                             end
  118.                         end
  119.                        
  120.                         -- Set infinite sprint:
  121.                         if chance(settings.infiniteSprintChance) then
  122.                             PedSetInfiniteSprint(ped,true)
  123.                         end
  124.                        
  125.                         -- Set health:
  126.                         if chance(settings.healthMult[1]) then
  127.                             PedSetMaxHealth(ped,PedGetMaxHealth(ped)*(math.random(settings.healthMult[2]*100,settings.healthMult[3]*100)/100))
  128.                             PedSetHealth(ped,PedGetMaxHealth(ped))
  129.                         end
  130.                        
  131.                         -- Set weapon:
  132.                         if chance(settings.weaponChance) then
  133.                             PedSetWeapon(ped,settings.weapons[math.random(1,table.getn(settings.weapons))],50)
  134.                         end
  135.                        
  136.                         -- Set crazy timer:
  137.                         peds[ped] = GetTimer() + math.random(0,15000)
  138.                     end
  139.                 elseif GetTimer() >= t then
  140.                     -- Do something crazy (periodic shit):
  141.                     if gPedEvents[math.random(1,table.getn(gPedEvents))](ped) ~= false then
  142.                         -- Reset crazy timer:
  143.                         peds[ped] = GetTimer() + math.random(10000,50000)
  144.                     end
  145.                 end
  146.             end
  147.         end
  148.        
  149.         -- Wait:
  150.         Wait(0)
  151.     end
  152. end
  153. function PED_SetMissionPed(ped,onOrOff)
  154.     gIgnorePeds[ped] = onOrOff ~= false and true or nil
  155. end
  156. function F_PE_Attack(ped)
  157.     local enemy = gAllPeds[math.random(1,table.getn(gAllPeds))]
  158.     if ped ~= enemy and PedIsValid(enemy) then
  159.         PedSetPedToTypeAttitude(ped,PedGetFaction(enemy),0)
  160.         PedAttack(ped,enemy,1)
  161.     else
  162.         return false
  163.     end
  164. end
  165. function F_PE_AttackPlayer(ped)
  166.     if not chance(25) then
  167.         return false
  168.     end
  169.     PedSetPedToTypeAttitude(ped,13,0)
  170.     PedAttackPlayer(ped,1)
  171. end
  172. function F_PE_Dance(ped)
  173.     if PedMePlaying(ped,"Default_KEY") then
  174.         local dances = {
  175.             {"/Global/404Conv/Nerds/Dance1","Act/Conv/4_04.act"},
  176.             {"/Global/404Conv/Nerds/Dance2","Act/Conv/4_04.act"},
  177.             {"/Global/Ambient/Scripted/Cheerleading","Act/Anim/Ambient.act"},
  178.         }
  179.         local dance = dances[math.random(1,table.getn(dances))]
  180.         PedSetActionNode(ped,dance[1],dance[2])
  181.     else
  182.         return false
  183.     end
  184. end
  185. function F_PE_Headbutt(ped)
  186.     if PedMePlaying(ped,"Default_KEY") then
  187.         PedStopLove(ped)
  188.         PedSetActionNode(ped,"/Global/6_02/HeadButt/HeadButt_AnticStart","Act/Conv/6_02.act")
  189.         PedFaceXYZ(ped,PlayerGetPosXYZ())
  190.     else
  191.         return false
  192.     end
  193. end
  194. function F_PE_LayDown(ped)
  195.     if PedMePlaying(ped,"Default_KEY") then
  196.         PedSetActionNode(ped,"/Global/1_11X1/Animations/GaryIdleInBed","Act/Conv/1_11X1.act")
  197.     else
  198.         return false
  199.     end
  200. end
  201. function F_PE_Vomit(ped)
  202.     if PedMePlaying(ped,"Default_KEY") then
  203.         PedSetActionNode(ped,"/Global/Ambient/Scripted/SpecialPuke","Act/Anim/Ambient.act")
  204.     else
  205.         return false
  206.     end
  207. end
  208. function F_PE_PunchCombo(ped)
  209.     if PedMePlaying(ped,"Default_KEY") then
  210.         local closestPed,closestDist = nil,1.5
  211.         local x,y,z = PedGetPosXYZ(ped)
  212.         for i,ped2 in ipairs(gAllPeds) do
  213.             if ped ~= ped2 and PedIsValid(ped2) then
  214.                 local x2,y2,z2 = PedGetPosXYZ(ped2)
  215.                 local dist = math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y) + (z2-z)*(z2-z))
  216.                 if dist < closestDist then
  217.                     closestPed = ped2
  218.                     closestDist = dist
  219.                 end
  220.             end
  221.         end
  222.         if closestPed then
  223.             PedSetPedToTypeAttitude(ped,PedGetFaction(closestPed),0)
  224.             PedFaceXYZ(ped,PedGetPosXYZ(closestPed))
  225.             PedLockTarget(ped,closestPed)
  226.             PedStopLove(ped)
  227.             PedSetActionNode(ped,"/Global/BOSS_Darby/Offense/Short/Grapples/HeavyAttacks/Catch_Throw","Act/Anim/BOSS_Darby.act")
  228.         end
  229.     else
  230.         return false
  231.     end
  232. end
  233. function F_PE_HateEveryone(ped)
  234.     local faction = PedGetFaction(ped)
  235.     for f = 0,13 do
  236.         if f ~= faction and f ~= 12 then
  237.             PedSetPedToTypeAttitude(ped,f,0)
  238.         end
  239.     end
  240. end
  241. function F_PE_JoinPlayer(ped)
  242.     if not chance(10) then
  243.         return false
  244.     else
  245.         local leader = gPlayer
  246.         while PedHasAllyFollower(leader) do
  247.             leader = PedGetAllyFollower(leader)
  248.             if leader == ped then
  249.                 return false
  250.             end
  251.         end
  252.         PedRecruitAlly(leader,ped)
  253.     end
  254. end
  255. function F_PE_Workout(ped)
  256.     if PedMePlaying(ped,"Default_KEY") then
  257.         PedSetActionNode(ped,"/Global/Ambient/Scripted/Workout","Act/Anim/Ambient.act")
  258.     else
  259.         return false
  260.     end
  261. end
  262. function F_PE_Spin(ped)
  263.     if not chance(20) or not PedMePlaying(ped,"Default_KEY") then
  264.         return false
  265.     end
  266.     if not gSpinningPeds then
  267.         gSpinningPeds = {}
  268.         gSpinningPedsThread = function()
  269.             while true do
  270.                 for i,v in ipairs(gSpinningPeds) do
  271.                     if PedIsValid(v[1]) and GetTimer() < v[2] + 2000 then
  272.                         local x,y,z = PedGetPosXYZ(v[1])
  273.                         local h = PedGetHeading(v[1])+(20-(math.abs(GetTimer()-(v[2]+1000))/1000))
  274.                         PedFaceXYZ(v[1],x-math.sin(h),y+math.cos(h),z)
  275.                     else
  276.                         table.remove(gSpinningPeds,i)
  277.                         i = i - 1
  278.                     end
  279.                 end
  280.                 Wait(0)
  281.             end
  282.         end
  283.         gSpinningPedsThread = CreateThread("gSpinningPedsThread")
  284.     end
  285.     table.insert(gSpinningPeds,{ped,GetTimer()})
  286. end
  287. function F_PE_Complain(ped)
  288.     SoundPlayAmbientSpeechEvent(ped,chance(50) and "COMPLAIN" or "SEE_SOMETHING_CRAP")
  289. end
  290. function F_PE_Scream(ped)
  291.     SoundPlayAmbientSpeechEvent(ped,chance(50) and "SCARED" or "SCARED_CRY")
  292. end
  293. function F_PE_Flee(ped)
  294.     if PedMePlaying(ped,"Default_KEY") then
  295.         PedSetActionTree(ped,"/Global/N_Ranged_A","Act/Anim/N_Ranged_A.act")
  296.         SoundPlayAmbientSpeechEvent(ped,"SCARED")
  297.         PedFlee(ped)
  298.     else
  299.         return false
  300.     end
  301. end
  302.  
  303. --[[ T_Blips:
  304.     There are a few blips around Bullworth that give the player some special shit.
  305. ]]
  306. function T_Blips()
  307.     -- Setup stuff for blip functions:
  308.     local F_GiveWeapon = function(weapon)
  309.         PlayerSetWeapon(weapon,50,false)
  310.     end
  311.     local stuff = {
  312.         {"Food",{
  313.             {"Apple",F_GiveWeapon,{310}},
  314.             {"Banana",F_GiveWeapon,{358}},
  315.             {"Eggs",F_GiveWeapon,{312}},
  316.         }},
  317.         {"Guns",{
  318.             {"Spud Gun",F_GiveWeapon,{305}},
  319.             {"Rocket Launcher",F_GiveWeapon,{307}},
  320.         }},
  321.         {"Melee",{
  322.             {"Baseball Bat",F_GiveWeapon,{300}},
  323.             {"Two by Four",F_GiveWeapon,{323}},
  324.             {"Sledge Hammer",F_GiveWeapon,{324}},
  325.             {"Paddle",F_GiveWeapon,{357}},
  326.             {"Devil Fork",F_GiveWeapon,{409}},
  327.             {"Magic Wand",F_GiveWeapon,{410}},
  328.             {"Gold Pipe",F_GiveWeapon,{418}},
  329.         }},
  330.         {"Projectiles",{
  331.             {"Fire Crackers",F_GiveWeapon,{301}},
  332.             {"Stink Bombs",F_GiveWeapon,{309}},
  333.             {"Itching Powder",F_GiveWeapon,{394}},
  334.             {"Bag o' Marbles",F_GiveWeapon,{349}},
  335.             {"Volcano 4000",F_GiveWeapon,{397}},
  336.             {"Rigged Ball",F_GiveWeapon,{400}},
  337.         }},
  338.         {"Sports",{
  339.             {"Baseball",F_GiveWeapon,{302}},
  340.             {"Basket Ball",F_GiveWeapon,{381}},
  341.             {"Soccer Ball",F_GiveWeapon,{329}},
  342.             {"Foot Ball",F_GiveWeapon,{331}},
  343.             {"Frisbee",F_GiveWeapon,{335}},
  344.         }},
  345.         {"Books",{
  346.             {"Book",F_GiveWeapon,{405}},
  347.             {"Book",F_GiveWeapon,{413}},
  348.             {"Book",F_GiveWeapon,{414}},
  349.             {"Book",F_GiveWeapon,{415}},
  350.             {"Book",F_GiveWeapon,{416}},
  351.             {"Diary",F_GiveWeapon,{432}},
  352.         }},
  353.         {"Junk",{
  354.             {"Brick",F_GiveWeapon,{311}},
  355.             {"Newspapers",F_GiveWeapon,{320}},
  356.             {"Pom Poms",F_GiveWeapon,{341}},
  357.             {"Old Pet",F_GiveWeapon,{346}},
  358.             {"Vase",F_GiveWeapon,{354}},
  359.             {"Lunch Tray",F_GiveWeapon,{348}},
  360.             {"Dinner Plate",F_GiveWeapon,{338}},
  361.             {"Decorative Plate",F_GiveWeapon,{355}},
  362.             {"Pussy Magnet",F_GiveWeapon,{363}},
  363.             {"Kick Me Sign",F_GiveWeapon,{372}},
  364.             {"Broom",F_GiveWeapon,{377}},
  365.             {"Old Slingshot",F_GiveWeapon,{303}},
  366.             {"Flashlight",F_GiveWeapon,{420}},
  367.             {"Shields",{
  368.                 {"Shield 1",F_GiveWeapon,{360}},
  369.                 {"Shield 2",F_GiveWeapon,{387}},
  370.                 {"Damaged Shield 1",F_GiveWeapon,{388}},
  371.                 {"Damaged Shield 2",F_GiveWeapon,{389}},
  372.             }},
  373.         }},
  374.     }
  375.     local garage = {
  376.         {"Bikes",{
  377.             {"Crap BMX",F_SpawnGarageVehicle,{274}},
  378.             {"Race BMX",F_SpawnGarageVehicle,{272}},
  379.             {"Retro BMX",F_SpawnGarageVehicle,{273}},
  380.             {"Aquaberry Bike",F_SpawnGarageVehicle,{283}},
  381.             {"Shop Class Bike",F_SpawnGarageVehicle,{277}},
  382.             {"Blue BMX",F_SpawnGarageVehicle,{278}},
  383.             {"Mountain Bike",F_SpawnGarageVehicle,{280}},
  384.             {"Old Lady Bike",F_SpawnGarageVehicle,{281}},
  385.             {"Racer Bike",F_SpawnGarageVehicle,{282}},
  386.             {"Bicycle",F_SpawnGarageVehicle,{279}},
  387.         }},
  388.         {"Cars",{
  389.             {"Taxi",F_SpawnGarageVehicle,{286,1}},
  390.             {"Limo",F_SpawnGarageVehicle,{290,1}},
  391.             {"70 Wagon",F_SpawnGarageVehicle,{294,1}},
  392.             {"Foreign Car",F_SpawnGarageVehicle,{292,1}},
  393.             {"Regular Car",F_SpawnGarageVehicle,{293,1}},
  394.             {"Domestic Car",F_SpawnGarageVehicle,{296,1}},
  395.         }},
  396.         {"Trucks",{
  397.             {"Truck",F_SpawnGarageVehicle,{297,1}},
  398.             {"Delivery Truck",F_SpawnGarageVehicle,{291,1}},
  399.         }},
  400.         {"Police",{
  401.             {"Police Bike",F_SpawnGarageVehicle,{275,1}},
  402.             {"Police Car",F_SpawnGarageVehicle,{295,1}},
  403.         }},
  404.         {"Arcade",{
  405.             {"Arcade 1",F_SpawnGarageVehicle,{298,2}},
  406.             {"Arcade 1",F_SpawnGarageVehicle,{287,2}},
  407.             {"Arcade 2",F_SpawnGarageVehicle,{285,2}},
  408.         }},
  409.         {"Other",{
  410.             {"Dozer",F_SpawnGarageVehicle,{288,1}},
  411.             {"Scooter",F_SpawnGarageVehicle,{276}},
  412.             {"Mower",F_SpawnGarageVehicle,{284}},
  413.             {"Go Cart",F_SpawnGarageVehicle,{289}},
  414.         }},
  415.     }
  416.    
  417.     -- Setup default blips:
  418.     gBlips = {
  419.         -- {prompt,a,x,y,z,icon,color,func,args,blip*,type*}
  420.         {"get stuff",14,-490.6,314.4,31.4,-1,1,MENU_BasicMenu,{"JIMMY'S STUFF",stuff,-492.24,311.63,33.4,-491.84,312.52,33.21}},
  421.         {"get vehicle",0,161.7,-7.84,6.04,-1,1,MENU_BasicMenu,{"GARAGE",garage,164.77,-3.12,9.41,165.53,-3.75,9.26}},
  422.     }
  423.    
  424.     -- Create debug blip:
  425.     if gDebugTests then
  426.         BLIP_Create("debug",14,-497.95,309.37,31.4,-1,12,MENU_BasicMenu,"DEBUG",gDebugMenu)
  427.     end
  428.    
  429.     -- Main loop:
  430.     while true do
  431.         -- Process blips:
  432.         for i,b in ipairs(gBlips) do
  433.             -- Create/edit blip:
  434.             if AreaGetVisible() == b[2] and PedIsInAreaXYZ(gPlayer,b[3],b[4],b[5],30) then
  435.                 if b[11] ~= 1 then
  436.                     if b[10] then
  437.                         BlipRemove(b[10])
  438.                     end
  439.                     b[10] = BlipAddXYZ(b[3],b[4],b[5],b[6],b[6] ~= -1 and 1 or 0,b[7])
  440.                     b[11] = 1
  441.                 end
  442.             elseif b[11] ~= 2 then
  443.                 if b[10] then
  444.                     BlipRemove(b[10])
  445.                 end
  446.                 b[10] = BlipAddXYZ(b[3],b[4],b[5],b[6],b[6] ~= -1 and 1 or 0)
  447.                 b[11] = 2
  448.             end
  449.            
  450.             -- Use blip:
  451.             if PedIsInAreaXYZ(gPlayer,b[3],b[4],b[5],0.8) and PedMePlaying(gPlayer,"Default_KEY") then
  452.                 repeat
  453.                     TextPrintString("Press \b to "..b[1]..".",0,2)
  454.                     Wait(0)
  455.                     if IsButtonBeingPressed(9,0) then
  456.                         if b[8] then
  457.                             if b[9] then
  458.                                 b[8](unpack(b[9]))
  459.                             else
  460.                                 b[8]()
  461.                             end
  462.                         end
  463.                         b[12] = GetTimer()
  464.                     end
  465.                 until not b[11] or not PedIsInAreaXYZ(gPlayer,b[3],b[4],b[5],0.8) or not PedMePlaying(gPlayer,"Default_KEY")
  466.                 i = 1
  467.             end
  468.         end
  469.        
  470.         -- Wait:
  471.         Wait(0)
  472.     end
  473. end
  474. function BLIP_Create(prompt,a,x,y,z,icon,color,func,...)
  475.     local blip = {prompt,a,x,y,z,icon,color,func,arg}
  476.     table.insert(gBlips,blip)
  477.     return blip
  478. end
  479. function BLIP_Delete(blip)
  480.     for i,v in ipairs(gBlips) do
  481.         if v == blip then
  482.             if v[10] then
  483.                 BlipRemove(v[10])
  484.                 v[10] = nil
  485.                 v[11] = nil
  486.                 table.remove(gBlips,i)
  487.                 break
  488.             end
  489.         end
  490.     end
  491. end
  492. function BLIP_Reset(blip)
  493.     for i,v in ipairs(gBlips) do
  494.         if v == blip then
  495.             if v[10] then
  496.                 BlipRemove(v[10])
  497.                 v[10] = nil
  498.                 v[11] = nil
  499.                 break
  500.             end
  501.         end
  502.     end
  503. end
  504. function BLIP_SetPrompt(blip,prompt)
  505.     blip[1] = prompt
  506. end
  507. function BLIP_SetPosition(blip,x,y,z,a)
  508.     blip[3],blip[4],blip[5] = x,y,z
  509.     if a then
  510.         blip[2] = a
  511.     end
  512.     BLIP_Reset(blip)
  513. end
  514. function BLIP_SetColor(blip,color)
  515.     blip[7] = color
  516.     BLIP_Reset(blip)
  517. end
  518. function BLIP_SetFunc(blip,func,...)
  519.     blip[8] = func
  520.     blip[9] = arg
  521. end
  522. function BLIP_GetLastUse(blip)
  523.     return blip[12]
  524. end
  525.  
  526. --[[ T_Events:
  527.     Random events may randomly occur at random times doing random things.
  528. ]]
  529. function T_Events()
  530.     -- Variables:
  531.     local settings = gSettings.events
  532.     local t = GetTimer() + settings.initialTime
  533.     gEvents = {
  534.         F_EV_Sheldonator,
  535.         F_EV_Crabblesnitch,
  536.         F_EV_Joyride,
  537.         F_EV_GangAttack,
  538.         F_EV_Talk,
  539.         F_EV_Abduction,
  540.     }
  541.    
  542.     -- Main loop:
  543.     while true do
  544.         if GetTimer() >= t and table.getn(gAllPeds) <= 18 then
  545.             local x,y,z = PedFindRandomSpawnPosition()
  546.             if x ~= 9999 then
  547.                 local vehicles = VehicleFindInAreaXYZ(0,0,0,9999999)
  548.                 if (not vehicles or table.getn(vehicles) <= 10) and gEvents[math.random(1,table.getn(gEvents))](x,y,z) ~= false then
  549.                     t = GetTimer() + math.random(settings.timeRange[1],settings.timeRange[2])
  550.                 end
  551.             end
  552.         end
  553.         Wait(0)
  554.     end
  555. end
  556. function F_EV_Sheldonator(x,y,z)
  557.     local ped = PedCreateSheldonator(x,y,z)
  558.     if ped then
  559.         PedMakeAmbient(ped)
  560.     else
  561.         return false
  562.     end
  563. end
  564. function F_EV_Crabblesnitch(x,y,z)
  565.     local ped = PedCreateXYZ(65,x,y,z)
  566.     PED_SetMissionPed(ped,true)
  567.     PedSetActionTree(ped,"/Global/Authority","Act/Anim/Authority.act")
  568.     for f = 0,13 do
  569.         if f ~= PedGetFaction(ped) and f ~= 12 then
  570.             PedSetPedToTypeAttitude(ped,f,0)
  571.         end
  572.     end
  573.     GameSetPedStat(ped,8,100)
  574.     GameSetPedStat(ped,12,70)
  575.     GameSetPedStat(ped,20,GameGetPedStat(ped,20)*1.4)
  576.     GameSetPedStat(ped,39,100)
  577.     GameSetPedStat(ped,61,100)
  578.     GameSetPedStat(ped,62,0)
  579.     GameSetPedStat(ped,63,10)
  580.     PedSetInfiniteSprint(ped,true)
  581.     local enemy = gAllPeds[math.random(1,table.getn(gAllPeds))]
  582.     if PedIsValid(enemy) then
  583.         PedAttack(ped,enemy,3)
  584.     end
  585.     PedMakeAmbient(ped)
  586. end
  587. function F_EV_Joyride(x,y,z)
  588.     local peds = {165,219,253,58,87,84}
  589.     local ped = PedCreateXYZ(peds[math.random(1,table.getn(peds))],x+0.5,y,z)
  590.     local veh = VehicleCreateXYZ(276,x-0.5,y,z)
  591.     VehicleSetAccelerationMult(veh,100)
  592.     PedEnterVehicle(ped,veh)
  593.     PedMakeAmbient(ped)
  594.     VehicleMakeAmbient(veh)
  595. end
  596. function F_EV_GangAttack(x,y,z)
  597.     local victim = gAllPeds[math.random(1,table.getn(gAllPeds))]
  598.     if not PedIsValid(victim) then
  599.         return false
  600.     end
  601.     local allModels = {
  602.         {83,97,234,238},
  603.         {49,50,51,52},
  604.         {4,4,4,155},
  605.         {160,141,220},
  606.         {230,229,75},
  607.         {84,87},
  608.         {88,88,88,88},
  609.         {186,208,209,210},
  610.         {math.random(2,97),math.random(2,97),math.random(99,258),math.random(99,258)},
  611.     }
  612.     local models = allModels[math.random(1,table.getn(allModels))]
  613.     local weapons = {360,324,305,323,300,357}
  614.     for i,model in ipairs(models) do
  615.         local h = (i/table.getn(models))*(math.pi*2)
  616.         local cop = PedCreateXYZ(model,x-math.sin(h)/2,y+math.cos(h)/2,z)
  617.         PED_SetMissionPed(cop,true)
  618.         PedSetHealth(cop,PedGetMaxHealth(cop)*math.random(1,60)/10)
  619.         PedSetMaxHealth(cop,PedGetHealth(cop))
  620.         GameSetPedStat(cop,8,100)
  621.         GameSetPedStat(cop,12,80)
  622.         GameSetPedStat(cop,20,GameGetPedStat(cop,20)*1.3)
  623.         GameSetPedStat(cop,39,100)
  624.         GameSetPedStat(cop,61,100)
  625.         GameSetPedStat(cop,62,0)
  626.         GameSetPedStat(cop,63,5)
  627.         PedSetInfiniteSprint(cop,true)
  628.         PedSetWeapon(cop,weapons[math.random(1,table.getn(weapons))],50)
  629.         for f = 0,13 do
  630.             if f ~= PedGetFaction(ped) and f ~= 12 then
  631.                 PedSetPedToTypeAttitude(ped,f,0)
  632.             end
  633.         end
  634.         PedAttack(cop,victim,3)
  635.         PedMakeAmbient(cop)
  636.     end
  637. end
  638. function F_EV_Talk()
  639.     local buyer = gAllPeds[math.random(1,table.getn(gAllPeds))]
  640.     local seller = gAllPeds[math.random(1,table.getn(gAllPeds))]
  641.     local arePedsDead = function()
  642.         return not (PedIsValid(buyer) and not PedIsDead(buyer) and PedIsValid(seller) and not PedIsDead(seller))
  643.     end
  644.     if buyer == seller or gIgnorePeds[buyer] or gIgnorePeds[seller] or arePedsDead() then
  645.         return false
  646.     end
  647.     PED_SetMissionPed(buyer,true)
  648.     PED_SetMissionPed(seller,true)
  649.     PedClearObjectives(buyer)
  650.     PedClearObjectives(seller)
  651.     PedSetStationary(seller,true)
  652.     local x,y,z = PedGetPosXYZ(seller)
  653.     PedMoveToXYZ(buyer,2,x,y,z)
  654.     while not PedIsInAreaXYZ(buyer,x,y,z,0.8) do
  655.         Wait(0)
  656.         if arePedsDead() then
  657.             return
  658.         end
  659.     end
  660.     PedSetStationary(seller,false)
  661.     PedStop(buyer)
  662.     PedStop(seller)
  663.     PedFaceXYZ(buyer,PedGetPosXYZ(seller))
  664.     PedFaceXYZ(seller,PedGetPosXYZ(buyer))
  665.     PedSetActionNode(buyer,"/Global/1_02/Talking/Talk","Act/Conv/1_02.act")
  666.     PedSetActionNode(seller,"/Global/1_02/Talking/Talk","Act/Conv/1_02.act")
  667.     local t = GetTimer()
  668.     repeat
  669.         Wait(0)
  670.         if arePedsDead() then
  671.             return
  672.         end
  673.     until GetTimer() >= t + 6450
  674.     PedSetActionNode(buyer,"/Global","Act/Globals.act")
  675.     PedSetActionNode(seller,"/Global","Act/Globals.act")
  676.     PED_SetMissionPed(buyer,false)
  677.     PED_SetMissionPed(seller,false)
  678. end
  679. function F_EV_Abduction()
  680.     local ped = gAllPeds[math.random(1,table.getn(gAllPeds))]
  681.     if not PedIsValid(ped) or gIgnorePeds[ped] or MissionActive() or GetCutsceneRunning() ~= 0 then
  682.         return false
  683.     end
  684.     PED_SetMissionPed(ped,true)
  685.     SoundPlayAmbientSpeechEvent(ped,"SCARED")
  686.     local x,y,z = PedGetPosXYZ(ped)
  687.     local t = GetTimer()
  688.     repeat
  689.         PedSetEffectedByGravity(ped,false)
  690.         if not PedIsPlaying(ped,"/Global/1_06/HoboFly",true) then
  691.             PedSetActionNode(ped,"/Global/1_06/HoboFly","Act/Conv/1_06.act")
  692.         end
  693.         PedSetPosXYZ(ped,x,y,z + ((GetTimer()-t)/10000)*20)
  694.         Wait(0)
  695.     until not PedIsValid(ped) or (not PedIsOnScreen(ped) and GetTimer() >= t + 10000)
  696.     if PedIsValid(ped) then
  697.         PedDelete(ped)
  698.     end
  699. end
  700.  
  701. --[[ T_Errands:
  702.     Needy peds will on occassion ask Jimmy to do shit.
  703.     Some errands are small simple things, while others are short missions.
  704.     All errands can only start when the player is not on a mission.
  705. ]]
  706. function T_Errands()
  707.     -- Variables:
  708.     local settings = gSettings.errands
  709.     local inMission = false
  710.     local t = GetTimer() + math.random(settings.timeRange[1],settings.timeRange[2])
  711.    
  712.     -- Setup errands:
  713.     gErrands = {
  714.         {
  715.             ped = 87,
  716.             area = {0,426.6,-461.1,3,300},
  717.             chapter = 2,
  718.             main = F_ER_Crack,
  719.         },
  720.         {
  721.             ped = 6,
  722.             area = {0,160.24,-73.79,6.37,350},
  723.             chapter = 3,
  724.             main = F_ER_Melvin,
  725.         },
  726.     }
  727.    
  728.     -- Main loop:
  729.     while true do
  730.         if ERRAND_ShouldStop() then
  731.             if not inMission then
  732.                 inMission = true
  733.             end
  734.         else
  735.             if inMission then
  736.                 t = GetTimer() + math.random(settings.timeRange[1],settings.timeRange[2])
  737.                 inMission = false
  738.             end
  739.             if GetTimer() >= t and table.getn(gErrands) > 0 and table.getn(gAllPeds) <= 18 then
  740.                 local x,y,z = PedFindRandomSpawnPosition()
  741.                 if x ~= 9999 then
  742.                     local vehicles = VehicleFindInAreaXYZ(0,0,0,9999999)
  743.                     if not vehicles or table.getn(vehicles) <= 10 then
  744.                         local i = math.random(1,table.getn(gErrands))
  745.                         local s = ERRAND_Play(gErrands[i])
  746.                         if s then
  747.                             t = GetTimer() + math.random(settings.timeRange[1],settings.timeRange[2])
  748.                             if s == 2 then
  749.                                 table.remove(gErrands,i)
  750.                             end
  751.                         end
  752.                     end
  753.                 end
  754.             end
  755.         end
  756.         Wait(0)
  757.     end
  758. end
  759. function ERRAND_Play(errand)
  760.     -- Variables:
  761.     local started,control,ped,blip,t = false,true
  762.    
  763.     -- Cleanup:
  764.     local cleanup = function()
  765.         if ped and PedIsValid(ped) then
  766.             PedStop(ped)
  767.             PedMakeAmbient(ped)
  768.             PED_SetMissionPed(ped,false)
  769.         end
  770.         if blip then
  771.             BlipRemove(blip)
  772.         end
  773.         if not control then
  774.             PlayerSetControl(1)
  775.         end
  776.     end
  777.    
  778.     -- Should stop errand:
  779.     local shouldStopErrand = function()
  780.         if ERRAND_ShouldStop() or (ped and (not PedIsValid(ped) or PedIsDead(ped) or PedDislikesPlayer(ped) or (not started and PedGetDistanceFromPed(gPlayer,ped) > 50))) then
  781.             return true
  782.         end
  783.     end
  784.    
  785.     -- Check that the errand can start:
  786.     if shouldStopErrand() or errand.chapter and ChapterGet() < errand.chapter or gAuthority[errand.ped] and PlayerGetPunishmentPoints() > 0 then
  787.         cleanup()
  788.         return nil
  789.     end
  790.    
  791.     -- Check that the player is in the correct area:
  792.     if errand.area then
  793.         if errand.area[1] ~= AreaGetVisible() then
  794.             cleanup()
  795.             return nil
  796.         elseif errand.area[2] and not PedIsInAreaXYZ(gPlayer,errand.area[2],errand.area[3],errand.area[4],errand.area[5]) then
  797.             cleanup()
  798.             return nil
  799.         end
  800.     end
  801.    
  802.     -- Get spawn position:
  803.     local x,y,z = PedFindRandomSpawnPosition()
  804.     if x == 9999 then
  805.         cleanup()
  806.         return nil
  807.     end
  808.    
  809.     -- Create and ped:
  810.     ped = PedCreateXYZ(errand.ped,x,y,z)
  811.     blip = AddBlipForChar(ped,0,1,4)
  812.     PedMakeNeutral(ped)
  813.     PED_SetMissionPed(ped,true)
  814.     if errand.setup and (errand.setup(ped) == false or shouldStopErrand()) then
  815.         cleanup()
  816.         return nil
  817.     end
  818.    
  819.     -- Wait for player to trigger errand:
  820.     PedMoveToObject(ped,gPlayer,2,1,nil,2)
  821.     t = GetTimer()
  822.     repeat
  823.         Wait(0)
  824.         if GetTimer() >= t + 25000 or shouldStopErrand() then
  825.             cleanup()
  826.             return 1
  827.         end
  828.     until PedGetTargetPed(gPlayer) == ped and IsButtonBeingPressed(7,0) and PedMePlaying(gPlayer,"Default_KEY") and PedMePlaying(ped,"Default_KEY")
  829.     PedStop(ped)
  830.     BlipRemove(blip)
  831.     blip = nil
  832.    
  833.     -- Setup talk:
  834.     PlayerSetControl(0)
  835.     control = false
  836.     if PedGetDistanceFromPed(gPlayer,ped) > 1.5 then
  837.         PedMoveToXYZ(ped,0,PlayerGetPosXYZ())
  838.         t = GetTimer()
  839.         repeat
  840.             Wait(0)
  841.             if GetTimer() >= t + 10000 or shouldStopErrand() then
  842.                 cleanup()
  843.                 return 1
  844.             end
  845.         until PedGetDistanceFromPed(gPlayer,ped) <= 1.5
  846.         PedStop(ped)
  847.     end
  848.    
  849.     -- Talk:
  850.     PedFaceXYZ(gPlayer,PedGetPosXYZ(ped))
  851.     PedFaceXYZ(ped,PlayerGetPosXYZ())
  852.     PedSetActionNode(gPlayer,"/Global/1_02/Talking/Talk","Act/Conv/1_02.act")
  853.     PedSetActionNode(ped,"/Global/1_02/Talking/Talk","Act/Conv/1_02.act")
  854.     t = GetTimer()
  855.     repeat
  856.         Wait(0)
  857.         if shouldStopErrand() then
  858.             cleanup()
  859.             return 1
  860.         end
  861.     until GetTimer() >= t + 5000
  862.    
  863.     -- Stop talk:
  864.     PedSetActionNode(gPlayer,"/Global","Act/Globals.act")
  865.     PedSetActionNode(ped,"/Global","Act/Globals.act")
  866.     PlayerSetControl(1)
  867.     control = true
  868.    
  869.     -- Do errand:
  870.     started = true
  871.     errand.main(ped)
  872.     cleanup()
  873.     return 2
  874. end
  875. function ERRAND_ShouldStop()
  876.     return MissionActive() or GetCutsceneRunning() ~= 0 or PedIsDead(gPlayer)
  877. end
  878. function F_ER_Crack(ped)
  879.     -- Variables:
  880.     local blip1,blip2,blip3
  881.    
  882.     -- Cleanup:
  883.     local cleanup = function()
  884.         if blip1 then
  885.             BLIP_Delete(blip1)
  886.         end
  887.         if blip2 then
  888.             BlipRemove(blip2)
  889.         end
  890.         if blip3 then
  891.             BlipRemove(blip3)
  892.         end
  893.     end
  894.    
  895.     -- Should stop errand:
  896.     local shouldStopErrand = function()
  897.         return ERRAND_ShouldStop() or PedDislikesPlayer(ped)
  898.     end
  899.    
  900.     -- Go to destination:
  901.     PedWander(ped)
  902.     TextPrintString("Go get the crack",3,1)
  903.     blip1 = BLIP_Create("steal crack",0,426.6,-461.1,3,0,1)
  904.     while AreaGetVisible() ~= 0 or not PedIsInAreaXYZ(gPlayer,431.1,-456,2.6,6) do
  905.         Wait(0)
  906.         if shouldStopErrand() then
  907.             cleanup()
  908.             return
  909.         end
  910.     end
  911.    
  912.     -- Get the crack:
  913.     TextPrintString("Steal the crack",3,1)
  914.     while not BLIP_GetLastUse(blip1) do
  915.         Wait(0)
  916.         if shouldStopErrand() then
  917.             cleanup()
  918.             return
  919.         end
  920.     end
  921.    
  922.     -- Celebrate:
  923.     PlayerSetControl(0)
  924.     PedSetActionNode(gPlayer,"/Global","Act/Globals.act")
  925.     CameraFade(1500,0)
  926.     Wait(2500)
  927.     BLIP_Delete(blip1)
  928.     blip1 = nil
  929.     PedFaceXYZ(gPlayer,435.4,-450.1,2.5)
  930.     PedSetActionNode(gPlayer,"/Global/C31Strt/PlayerVictory","Act/Conv/C3_1.act")
  931.     CameraSetXYZ(432,-456.8,5,429.7,-458.8,4.5)
  932.     CameraFade(1500,1)
  933.     local t = GetTimer()
  934.     while GetTimer() < t + 3000 or PedIsPlaying(gPlayer,"/Global/C31Strt/PlayerVictory",true) do
  935.         TextPrintString("You got the crack!",0,1)
  936.         Wait(0)
  937.     end
  938.    
  939.     -- Create enemy:
  940.     local enemy = PedCreateXYZ(105,435.4,-450.1,2.5)
  941.     PED_SetMissionPed(enemy,true)
  942.     PedSetActionTree(enemy,"/Global/DO_Grappler_A","Act/Anim/DO_Grappler_A.act")
  943.     GameSetPedStat(enemy,8,100)
  944.     PedClearAllWeapons(enemy)
  945.     PedFaceXYZ(enemy,PlayerGetPosXYZ())
  946.     PedSetPedToTypeAttitude(enemy,13,0)
  947.     PedAttackPlayer(enemy,3)
  948.     blip2 = AddBlipForChar(enemy,0,26,1)
  949.     PedSetActionNode(enemy,"/Global/6_02/HeadButt/HeadButt_AnticStart","Act/Conv/6_02.act")
  950.     CameraSetXYZ(429.1,-460.7,5,430.5,-458,4.5)
  951.     TextPrintString("The dealer saw you!",2,1)
  952.     Wait(2000)
  953.     CameraReset()
  954.     CameraReturnToPlayer()
  955.     PlayerSetControl(1)
  956.    
  957.     -- Fight or escape:
  958.     PedMakeAmbient(enemy)
  959.     PED_SetMissionPed(enemy,false)
  960.     local givenWeapon = false
  961.     while PedIsValid(enemy) and not PedIsDead(enemy) do
  962.         if not givenWeapon and PedGetHealth(enemy) < PedGetMaxHealth(enemy)*0.4 and PedMePlaying(enemy,"Default_KEY") then
  963.             PedSetWeapon(enemy,418)
  964.             givenWeapon = true
  965.         end
  966.         Wait(0)
  967.         if shouldStopErrand() then
  968.             cleanup()
  969.             return
  970.         end
  971.     end
  972.    
  973.     -- Deliver:
  974.     TextPrintString("Deliver the crack",3,1)
  975.     blip3 = AddBlipForChar(ped,0,0,1)
  976.     repeat
  977.         Wait(0)
  978.         if shouldStopErrand() then
  979.             cleanup()
  980.             return
  981.         end
  982.     until PedGetTargetPed(gPlayer) == ped and IsButtonBeingPressed(7,0) and PedMePlaying(gPlayer,"Default_KEY") and PedMePlaying(ped,"Default_KEY")
  983.    
  984.     -- Final cutscene:
  985.     PedLockTarget(gPlayer,ped)
  986.     PedLockTarget(ped,gPlayer)
  987.     PedSetActionNode(gPlayer,"/Global/Player/Gifts/Errand_IND_Package","Act/Player.act")
  988.     while PedIsPlaying(gPlayer,"/Global/Player/Gifts/Errand_IND_Package","Act/Player.act") do
  989.         Wait(0)
  990.         if shouldStopErrand() then
  991.             cleanup()
  992.             return
  993.         end
  994.     end
  995.     PedSetActionNode(gPlayer,"/Global/Player/Gifts/GetMoney","Act/Player.act")
  996.     while PedIsPlaying(gPlayer,"/Global/Player/Gifts/GetMoney","Act/Player.act") do
  997.         Wait(0)
  998.         if shouldStopErrand() then
  999.             cleanup()
  1000.             return
  1001.         end
  1002.     end
  1003.     PlayerAddMoney(math.random(2500,5000))
  1004.     PedLockTarget(gPlayer,-1)
  1005.     PedLockTarget(ped,-1)
  1006.     PlayerSetControl(1)
  1007.     cleanup()
  1008. end
  1009. function F_ER_Melvin(ped)
  1010.     -- Variables:
  1011.     local blip,c
  1012.    
  1013.     -- Cleanup:
  1014.     local cleanup = function()
  1015.         if blip then
  1016.             BlipRemove(blip)
  1017.         end
  1018.         if c then
  1019.             for i,ped in ipairs(c.peds) do
  1020.                 if PedIsValid(ped) then
  1021.                     PedDelete(ped)
  1022.                 end
  1023.             end
  1024.         end
  1025.     end
  1026.    
  1027.     -- Should stop errand:
  1028.     local shouldStopErrand = function()
  1029.         return ERRAND_ShouldStop() or PedDislikesPlayer(ped)
  1030.     end
  1031.    
  1032.     -- Follow:
  1033.     TextPrintString("Follow Melvin",3,1)
  1034.     PedSetInvulnerable(ped,true)
  1035.     blip = AddBlipForChar(ped,0,0,1)
  1036.     PedClearAllWeapons(ped)
  1037.     PedMoveToXYZ(ped,2,30.5,-224.6,3.2)
  1038.     GameSetPedStat(ped,20,200)
  1039.     PedSetInfiniteSprint(ped,true)
  1040.     local warped = false
  1041.     while not PedIsInAreaXYZ(gPlayer,30.5,-224.6,3.2,15) or not PedIsInAreaXYZ(ped,30.5,-224.6,3.2,15) do
  1042.         if warped and not PedIsInAreaXYZ(ped,30.5,-224.6,3.2,1) then
  1043.             PedMoveToXYZ(ped,2,30.5,-224.6,3.2)
  1044.         elseif not PedIsOnScreen(ped) then
  1045.             PedSetPosXYZ(ped,30.6,-224.6,3.2)
  1046.             warped = true
  1047.         end
  1048.         Wait(0)
  1049.         if shouldStopErrand() then
  1050.             cleanup()
  1051.             return
  1052.         end
  1053.     end
  1054.     GameSetPedStat(ped,20,100)
  1055.     BlipRemove(blip)
  1056.     PlayerSetControl(0)
  1057.     PedStop(gPlayer)
  1058.     PedStop(ped)
  1059.    
  1060.     -- Setup:
  1061.     CameraSetXYZ(19.4,-214.7,9.3,30.6,-224.6,3.2)
  1062.     PedFaceXYZ(gPlayer,PedGetPosXYZ(ped))
  1063.     PedFaceXYZ(ped,PlayerGetPosXYZ())
  1064.     PlayerSetPosXYZ(37.9,-216.7,3)
  1065.     PedSetPosXYZ(ped,30.6,-224.6,3.2)
  1066.     Wait(2000)
  1067.     PedSetActionNode(ped,"/Global/1_06/HoboFly","Act/Conv/1_06.act")
  1068.     PedSetEffectedByGravity(ped,false)
  1069.    
  1070.     -- Initialize circle of Melvins:
  1071.     local x,y,z = PedGetPosXYZ(ped)
  1072.     c = {
  1073.         -- Position:
  1074.         cx = x, -- current position x
  1075.         cy = y, -- current position y
  1076.         cz = z,  -- current position z
  1077.        
  1078.         -- Radius:
  1079.         cr = 0, -- current radius
  1080.        
  1081.         -- Speed:
  1082.         ch = 0, -- current heading
  1083.         s = 0, -- current speed (full rotations per second)
  1084.         st = GetTimer(), -- start time (last time "ch" set)
  1085.        
  1086.         -- Peds:
  1087.         peds = {ped}, -- spawned peds
  1088.         cc = 1, -- current count
  1089.     }
  1090.    
  1091.     -- Circle functions:
  1092.     local processCircle = function()
  1093.         -- Get time:
  1094.         local ct = GetTimer()
  1095.        
  1096.         -- Position:
  1097.         if c.tp then
  1098.             c.tx,c.ty,c.tz = PedGetPosXYZ(c.tp)
  1099.         end
  1100.         if c.tx and (c.cx ~= c.tx or c.cy ~= c.ty or c.cz ~= c.tz) then
  1101.             local t = c.pt ~= 0 and (ct-c.pst)/c.pt or 1
  1102.             if t > 1 then
  1103.                 t = 1
  1104.             end
  1105.             c.cx = c.sx + (c.tx-c.sx)*t
  1106.             c.cy = c.sy + (c.ty-c.sy)*t
  1107.             c.cz = c.sz + (c.tz-c.sz)*t
  1108.         end
  1109.        
  1110.         -- Radius:
  1111.         if c.tr and c.cr ~= c.tr then
  1112.             local t = c.rt ~= 0 and (ct-c.rst)/c.rt or 1
  1113.             if t > 1 then
  1114.                 t = 1
  1115.             end
  1116.             c.cr = c.sr + (c.tr-c.sr)*t
  1117.         end
  1118.        
  1119.         -- Count:
  1120.         if c.tc and c.cc ~= c.tc then
  1121.             if c.cc > c.tc then
  1122.                 repeat
  1123.                     if PedIsValid(c.peds[cc]) then
  1124.                         PedDelete(c.peds[cc])
  1125.                     end
  1126.                     table.remove(c.peds,cc)
  1127.                 until table.getn(c.peds) == c.tc
  1128.             else
  1129.                 repeat
  1130.                     local ped = PedCreateXYZ(6,c.cx,c.cy,c.cz)
  1131.                     PED_SetMissionPed(ped,true)
  1132.                     PedMakeNeutral(ped)
  1133.                     PedSetInvulnerable(ped,true)
  1134.                     PedSetActionNode(ped,"/Global/1_06/HoboFly","Act/Conv/1_06.act")
  1135.                     PedSetEffectedByGravity(ped,false)
  1136.                     table.insert(c.peds,ped)
  1137.                 until table.getn(c.peds) == c.tc
  1138.             end
  1139.             c.cc = c.tc
  1140.         end
  1141.        
  1142.         -- Move peds:
  1143.         c.ch = math.mod(c.ch+((GetTimer()-c.st)/(1000/c.s))*math.pi*2,math.pi*2)
  1144.         c.st = GetTimer()
  1145.         for i,ped in ipairs(c.peds) do
  1146.             if PedIsValid(ped) then
  1147.                 local h = c.ch + (i/table.getn(c.peds))*math.pi*2
  1148.                 local x = c.cx - math.sin(h)*c.cr
  1149.                 local y = c.cy + math.cos(h)*c.cr
  1150.                 PedFaceXYZ(ped,c.cx,c.cy,c.cz)
  1151.                 PedSetPosXYZ(ped,x,y,c.cz)
  1152.             end
  1153.         end
  1154.     end
  1155.     local setPosition = function(x,y,z,t)
  1156.         c.sx,c.sy,c.sz = c.cx,c.cy,c.cz
  1157.         c.tx,c.ty,c.tz = x,y,z
  1158.         c.pt = t or 0
  1159.         c.pst = GetTimer()
  1160.     end
  1161.     local setFollowPed = function(ped,t)
  1162.         c.sx,c.sy,c.sz = c.cx,c.cy,c.cz
  1163.         c.tp = ped
  1164.         c.pt = t or 0
  1165.         c.pst = GetTimer()
  1166.     end
  1167.     local setRadius = function(r,t)
  1168.         c.sr = c.cr
  1169.         c.tr = r
  1170.         c.rt = t or 0
  1171.         c.rst = GetTimer()
  1172.     end
  1173.     local setCount = function(n)
  1174.         c.tc = n
  1175.     end
  1176.     local setSpeed = function(s,i)
  1177.         if not i or s > c.s then
  1178.             c.s = s
  1179.         end
  1180.     end
  1181.     local F_Wait = function(ms)
  1182.         local t = GetTimer()
  1183.         repeat
  1184.             Wait(0)
  1185.             processCircle()
  1186.         until GetTimer() >= t + ms
  1187.     end
  1188.    
  1189.     -- Disable peds:
  1190.     StopPedProduction(true)
  1191.    
  1192.     -- Do shit:
  1193.     setPosition(30.6,-224.6,6.6,2000)
  1194.     F_Wait(3000)
  1195.     setCount(8)
  1196.     setRadius(3.5,3000)
  1197.     setSpeed(0.2)
  1198.     F_Wait(6000)
  1199.    
  1200.     -- Restore control for a bit:
  1201.     CameraReset()
  1202.     CameraReturnToPlayer()
  1203.     PlayerSetControl(1)
  1204.     F_Wait(10000)
  1205.    
  1206.     -- Follow player:
  1207.     setFollowPed(gPlayer,2000)
  1208.     setRadius(1.5,5000)
  1209.     local t = GetTimer()
  1210.     repeat
  1211.         setSpeed(0.2 + ((GetTimer()-t)/7500))
  1212.         F_Wait(0)
  1213.     until GetTimer() >= t + 10000
  1214.    
  1215.     -- To graveyard:
  1216.     CameraFade(500,0)
  1217.     F_Wait(2000)
  1218.     setPosition(614.3,166,47.5)
  1219.     setFollowPed(nil)
  1220.     PlayerSetPosXYZ(614.3,166,47.5)
  1221.     ClothingSetPlayerOutfit("Underwear")
  1222.     ClothingBuildPlayer()
  1223.     CameraFade(500,1)
  1224.     F_Wait(10000)
  1225.    
  1226.     -- Resume ped production:
  1227.     StopPedProduction(false)
  1228.    
  1229.     -- Finish:
  1230.     cleanup()
  1231. end
  1232.  
  1233. --[[ T_Weapons:
  1234.     Some weapons behave a little differently than usual.
  1235. ]]
  1236. function T_Weapons()
  1237.     -- Variables:
  1238.     local peds = {}
  1239.     local specialWeapons = {
  1240.         -- {conditionFunc,startFunc,endFunc,backupTable*}
  1241.         { -- sledgehammer
  1242.             function(ped) -- condition
  1243.                 return PedHasWeapon(ped,324) and PedIsPlaying(ped,"/Global/SledgeHammer/Actions/Attacks/Player",true)
  1244.             end,
  1245.             function(ped,t) -- start
  1246.                 t.speed = GameGetPedStat(ped,20)
  1247.                 t.damage = GameGetPedStat(ped,31)
  1248.                 GameSetPedStat(ped,20,t.speed*1.5)
  1249.                 GameSetPedStat(ped,31,t.damage*3)
  1250.             end,
  1251.             function(ped,t) -- end
  1252.                 GameSetPedStat(ped,20,t.speed)
  1253.                 GameSetPedStat(ped,31,t.damage)
  1254.             end,
  1255.         },
  1256.         { -- eggs
  1257.             function(ped) -- condition
  1258.                 return PedHasWeapon(ped,312) and (PedMePlaying(ped,"Default_KEY") or PedIsInAnyVehicle(ped))
  1259.             end,
  1260.             function(ped,t) -- start
  1261.                 t.damage = GameGetPedStat(ped,31)
  1262.                 GameSetPedStat(ped,31,t.damage*100)
  1263.             end,
  1264.             function(ped,t) -- end
  1265.                 GameSetPedStat(ped,31,t.damage)
  1266.             end,
  1267.         },
  1268.     }
  1269.    
  1270.     -- Debug slingshot:
  1271.     if gDebugSlingshot then
  1272.         table.insert(specialWeapons,{
  1273.             function(ped)
  1274.                 return ped == gPlayer and (PedHasWeapon(ped,303) or PedHasWeapon(ped,306)) and PedMePlaying(ped,"Default_KEY")
  1275.             end,
  1276.             function(ped,t) -- start
  1277.                 t.speed = GameGetPedStat(ped,20)
  1278.                 t.damage = GameGetPedStat(ped,31)
  1279.                 GameSetPedStat(ped,20,t.speed*2)
  1280.                 GameSetPedStat(ped,31,t.damage*1000)
  1281.             end,
  1282.             function(ped,t) -- end
  1283.                 GameSetPedStat(ped,20,t.speed)
  1284.                 GameSetPedStat(ped,31,t.damage)
  1285.             end,
  1286.         })
  1287.     end
  1288.    
  1289.     -- Setup default backup tables:
  1290.     for i,v in ipairs(specialWeapons) do
  1291.         if not v[4] then
  1292.             v[4] = {}
  1293.         end
  1294.     end
  1295.    
  1296.     -- Main loop:
  1297.     while true do
  1298.         -- Special weapons:
  1299.         for i,ped in ipairs(gAllPeds) do
  1300.             if PedIsValid(ped) then
  1301.                 local w = peds[ped]
  1302.                 if w then
  1303.                     if not w[1](ped) then
  1304.                         w[3](ped,w[4])
  1305.                         peds[ped] = nil
  1306.                     end
  1307.                 else
  1308.                     for i,w in ipairs(specialWeapons) do
  1309.                         if w[1](ped) then
  1310.                             w[2](ped,w[4])
  1311.                             peds[ped] = w
  1312.                             break
  1313.                         end
  1314.                     end
  1315.                 end
  1316.             end
  1317.         end
  1318.        
  1319.         -- Wait:
  1320.         Wait(0)
  1321.        
  1322.         -- Clean:
  1323.         for ped,t in ipairs(peds) do
  1324.             if not PedIsValid(ped) then
  1325.                 peds[ped] = nil
  1326.             end
  1327.         end
  1328.     end
  1329. end
  1330.  
  1331. --[[ T_Grapples:
  1332.     This thread simply makes sure grappling peds have matched speeds.
  1333. ]]
  1334. function T_Grapples()
  1335.     -- Variables:
  1336.     local peds = {}
  1337.    
  1338.     -- Main loop:
  1339.     while true do
  1340.         -- Process peds:
  1341.         for i,ped in ipairs(gAllPeds) do
  1342.             if PedIsValid(ped) then
  1343.                 local s = peds[ped]
  1344.                 local target = PedGetGrappleTargetPed(ped)
  1345.                 if s then
  1346.                     if target ~= s[1] then
  1347.                         GameSetPedStat(ped,20,s[2])
  1348.                         peds[ped] = nil
  1349.                     elseif GameGetPedStat(ped,20) ~= GameGetPedStat(target,20) then
  1350.                         GameSetPedStat(ped,20,GameGetPedStat(target,20))
  1351.                     end
  1352.                 elseif PedIsValid(target) and not PedIsDead(target) and GameGetPedStat(ped,20) ~= GameGetPedStat(target,20) then
  1353.                     peds[ped] = {target,GameGetPedStat(ped,20)}
  1354.                     GameSetPedStat(ped,20,GameGetPedStat(target,20))
  1355.                 end
  1356.             end
  1357.         end
  1358.        
  1359.         -- Wait:
  1360.         Wait(0)
  1361.        
  1362.         -- Clean:
  1363.         for ped,s in ipairs(peds) do
  1364.             if not PedIsValid(ped) then
  1365.                 peds[ped] = nil
  1366.             end
  1367.         end
  1368.     end
  1369. end
  1370.  
  1371. --[[ T_Areas:
  1372.     Special shit for each area/interior.
  1373. ]]
  1374. function T_Areas()
  1375.     -- Variables:
  1376.     local areas = {
  1377.         {8,function()
  1378.             local peds = {}
  1379.             local t = GetTimer() + math.random(1000,10000)
  1380.             local spawns = {
  1381.                 {-772.09,123.02,7.37},
  1382.                 {-766.47,-90.14,8.46},
  1383.                 {-773.56,-59.9,12.38},
  1384.                 {-764.24,-53.2,9.34},
  1385.                 {-754.9,-83.97,8.72},
  1386.                 {-745.71,-85.9,8.11},
  1387.                 {-734.15,-61.26,8.72},
  1388.                 {-732.3,-50.77,9.45},
  1389.                 {-761.12,-154.69,7.42},
  1390.             }
  1391.             local spawnSheldonator = function()
  1392.                 local t = {}
  1393.                 local px,py,pz = PlayerGetPosXYZ()
  1394.                 for i,v in ipairs(spawns) do
  1395.                     local x,y,z = v[1]-px,v[2]-py,v[3]-pz
  1396.                     local dist = math.sqrt(x*x + y*y + z*z)
  1397.                     for i = 1,3 do
  1398.                         if not t[i] or dist > t[i][1] then
  1399.                             table.insert(t,i,{dist,v})
  1400.                             break
  1401.                         end
  1402.                     end
  1403.                 end
  1404.                 local sx,sy,sz = unpack(t[math.random(1,3)][2])
  1405.                 for i,v in ipairs(peds) do
  1406.                     local px,py,pz = PedGetPosXYZ(v)
  1407.                     local x,y,z = sx-px,sy-py,sz-pz
  1408.                     local dist = math.sqrt(x*x + y*y + z*z)
  1409.                     if dist < 0.1 then
  1410.                         return nil
  1411.                     end
  1412.                 end
  1413.                 return PedCreateSheldonator(sx,sy,sz)
  1414.             end
  1415.             repeat
  1416.                 if GetTimer() >= t and table.getn(gAllPeds) < 20 then
  1417.                     local ped = spawnSheldonator()
  1418.                     if ped then
  1419.                         table.insert(peds,ped)
  1420.                         local count = table.getn(peds)
  1421.                         if count == 1 then
  1422.                             t = GetTimer() + math.random(10000,50000)
  1423.                         elseif count == 2 then
  1424.                             t = GetTimer() + math.random(10000,30000)
  1425.                         elseif count <= 5 then
  1426.                             t = GetTimer() + math.random(5000,20000)
  1427.                         elseif count <= 10 then
  1428.                             t = GetTimer() + math.random(5000,10000)
  1429.                         elseif count <= 20 then
  1430.                             t = GetTimer() + math.random(2000,8000)
  1431.                         elseif count <= 30 then
  1432.                             t = GetTimer() + math.random(1000,5000)
  1433.                         elseif math.mod(count,40) == 0 then
  1434.                             t = GetTimer() + math.random(30000,90000)
  1435.                         else
  1436.                             t = GetTimer() + math.random(0,10000)
  1437.                         end
  1438.                     end
  1439.                 end
  1440.                 Wait(0)
  1441.             until AreaGetVisible() ~= 8
  1442.             for i,v in ipairs(peds) do
  1443.                 if PedIsValid(v) then
  1444.                     PedMakeAmbient(v)
  1445.                 end
  1446.             end
  1447.         end},
  1448.     }
  1449.    
  1450.     -- Main loop:
  1451.     local area
  1452.     while true do
  1453.         local a = AreaGetVisible()
  1454.         if a ~= area then
  1455.             area = a
  1456.             for i,v in ipairs(areas) do
  1457.                 if v[1] == a then
  1458.                     v[2]()
  1459.                     break
  1460.                 end
  1461.             end
  1462.         else
  1463.             Wait(0)
  1464.         end
  1465.     end
  1466. end
  1467.  
  1468. --[[ T_Garbage:
  1469.     Collects garbage every frame, last created thread so it can run after all other threads.
  1470. ]]
  1471. function T_Garbage()
  1472.     while true do
  1473.         collectgarbage()
  1474.         Wait(0)
  1475.     end
  1476. end
  1477.  
  1478. --[[ Main:
  1479.     Randomizes default peds and starts all the other threads.
  1480. ]]
  1481. function main()
  1482.     -- Fuck up the peds:
  1483.     if not gForceNormalPeds then
  1484.         F_FuckUpThePeds()
  1485.         collectgarbage()
  1486.     end
  1487.    
  1488.     -- Wait for the game to start up:
  1489.     while not SystemIsReady() or AreaIsLoading() do
  1490.         Wait(0)
  1491.     end
  1492.    
  1493.     -- Load animation groups:
  1494.     F_LoadAnimations()
  1495.    
  1496.     -- Create threads:
  1497.     CreateThread("T_Peds")
  1498.     CreateThread("T_Blips")
  1499.     CreateThread("T_Events")
  1500.     CreateThread("T_Errands")
  1501.     CreateThread("T_Weapons")
  1502.     CreateThread("T_Grapples")
  1503.     CreateThread("T_Areas")
  1504.     CreateThread("T_Garbage")
  1505.    
  1506.     -- Main loop:
  1507.     while true do
  1508.         Wait(0)
  1509.     end
  1510. end
  1511. function F_FuckUpThePeds()
  1512.     -- Setup authority tables:
  1513.     gAuthority = {}
  1514.    
  1515.     -- Setup peds table:
  1516.     local peds = {
  1517.         -- {Index, model, winter texture, size}
  1518.         --{0,"player","player","Medium"},
  1519.         --{1,"DEFAULTPED","DEFAULTPED","Medium"},
  1520.         {2,"DOgirl_Zoe_EG","DOgirl_Zoe_EG","Medium"},
  1521.         {3,"NDGirl_Beatrice","NDGirl_Beatrice_W","Medium"},
  1522.         {4,"NDH1a_Algernon","NDH1a_Algernon_W","Fat"},
  1523.         {5,"NDH1_Fatty","NDH1_Fatty_W","Fat"},
  1524.         {6,"ND2nd_Melvin","ND2nd_Melvin_W","Fat"},
  1525.         {7,"NDH2_Thad","NDH2_Thad_W","Large"},
  1526.         {8,"NDH3_Bucky","NDH3_Bucky_W","Medium"},
  1527.         {9,"NDH2a_Cornelius","NDH2a_Cornelius_W","Large"},
  1528.         {10,"NDLead_Earnest","NDlead_Earnest_W","Medium"},
  1529.         {11,"NDH3a_Donald","NDH3a_Donald_W","Medium"},
  1530.         {12,"JKH1_Damon","JKH1_Damon_W","Huge"},
  1531.         {13,"JKH1a_Kirby","JKH1a_KirbyWinter","Medium"},
  1532.         {14,"JKGirl_Mandy","JKGirl_Mandy_W","Medium"},
  1533.         {15,"JKH2_Dan","JKH2_DanWinter","Medium"},
  1534.         {16,"JKH2a_Luis","JKH2a_Luis_W","Huge"},
  1535.         {17,"JKH3_Casey","JKH3_Casey_W","Huge"},
  1536.         {18,"JKH3a_Bo","JKH3a_Bo_W","Large"},
  1537.         {19,"JKlead_Ted","JKlead_Ted_W","Large"},
  1538.         {20,"JK2nd_Juri","JK2nd_Juri_W","Huge"},
  1539.         {21,"GR2nd_Peanut","GR2nd_Peanut_W","Large"},
  1540.         {22,"GRH2A_Hal","GRH2A_Hal","Large"},
  1541.         {23,"GRlead_Johnny","GRlead_Johnny_W","Large"},
  1542.         {24,"GRH1_Lefty","GRH1_Lefty_W","Medium"},
  1543.         {25,"GRGirl_Lola","GRGirl_Lola_W","Medium"},
  1544.         {26,"GRH3_Lucky","GRH3_Lucky_W","Large"},
  1545.         {27,"GRH1a_Vance","GRH1a_Vance","Medium"},
  1546.         {28,"GRH3a_Ricky","GRH3a_Ricky_W","Large"},
  1547.         {29,"GRH2_Norton","GRH2_Norton","Huge"},
  1548.         {30,"PRH1_Gord","PRH1_Gord_W","Medium"},
  1549.         {31,"PRH1a_Tad","PRH1a_Tad_W","Medium"},
  1550.         {32,"PRH2a_Chad","PRH2_Chad_W","Large"},
  1551.         {33,"PR2nd_Bif","PR2nd_Bif_W","Huge"},
  1552.         {34,"PRH3_Justin","PRH3_Justin_W","Large"},
  1553.         {35,"PRH2_Bryce","PRH2_Bryce_W","Large"},
  1554.         {36,"PRH2_Bryce_OBOX","PRH2_Bryce_OBOX","Large"},
  1555.         {37,"PRlead_Darby","PRlead_Darby_W","Large"},
  1556.         {38,"PRGirl_Pinky","PRGirl_Pinky_W","Medium"},
  1557.         {39,"GN_Asiangirl","GN_Asiangirl_W","Medium"},
  1558.         {40,"PRH3a_Parker","PRH3a_Parker_W","Large"},
  1559.         {41,"DOH2_Jerry","DOH2_Jerry_W","Large"},
  1560.         {42,"DOH1a_Otto","DOH1a_Otto_W","Medium"},
  1561.         {43,"DOH2a_Leon","DOH2a_Leon","Huge"},
  1562.         {44,"DOH1_Duncan","DOH1_Duncan_W","Medium"},
  1563.         {45,"DOH3_Henry","DOH3_Henry_W","Large"},
  1564.         {46,"DOH3a_Gurney","DOH3a_Gurney_W","Huge"},
  1565.         {47,"DO2nd_Omar","DO2nd_Omar","Huge"},
  1566.         {48,"DOGirl_Zoe","DOGirl_Zoe_W","Medium"},
  1567.         {49,"PF2nd_Max","PF2nd_Max_W","Huge"},
  1568.         {50,"PFH1_Seth","PFH1_Seth_W","Huge"},
  1569.         {51,"PFH2_Edward","PFH2_Edward_W","Huge"},
  1570.         {52,"PFlead_Karl","PFlead_Karl_W","Large"},
  1571.         {53,"TO_Orderly","TO_Orderly_W","Huge"},
  1572.         {54,"TE_HallMonitor","TE_Hallmonitor_W","Large"},
  1573.         {55,"TE_GymTeacher","TE_GymTeacher_W","Huge"},
  1574.         {56,"TE_Janitor","TE_Janitor","Huge"},
  1575.         {57,"TE_English","TE_English_W","Huge"},
  1576.         {58,"TE_Cafeteria","TE_Cafeteria_W","Huge"},
  1577.         {59,"TE_Secretary","TE_Secretary","Large"},
  1578.         {60,"TE_Nurse","TE_Nurse_W","Large"},
  1579.         {61,"TE_MathTeacher","TE_MathTeacher_W","Fat"},
  1580.         {62,"TE_Librarian","TE_Librarian_W","Large"},
  1581.         {63,"TE_Art","TE_Art","Large"},
  1582.         {64,"TE_Biology","TE_Biology_W","Huge"},
  1583.         {65,"TE_Principal","TE_Principal_W","Huge"},
  1584.         {66,"GN_Littleblkboy","GN_Littleblkboy_W","Small"},
  1585.         {67,"GN_SexyGirl","GN_SexyGirl_W","Medium"},
  1586.         {68,"GN_Littleblkgirl","GN_Littleblkgirl_W","Small"},
  1587.         {69,"GN_Hispanicboy","GN_Hispanicboy_W","Small"},
  1588.         {70,"GN_Greekboy","GN_Greekboy_W","Medium"},
  1589.         {71,"GN_Fatboy","GN_Fatboy_W","Fat"},
  1590.         {72,"GN_Boy01","GN_Boy01_W","Medium"},
  1591.         {73,"GN_Boy02","GN_Boy02_W","Large"},
  1592.         {74,"GN_Fatgirl","GN_Fatgirl_W","Fat"},
  1593.         {75,"DOlead_Russell","DOlead_Russell_W","Huge"},
  1594.         {76,"TO_Business1","TO_Business_01_W","Large"},
  1595.         {77,"TO_Business2","TO_Business2_W","Large"},
  1596.         {78,"TO_BusinessW1","TO_BusinessW1_W","Large"},
  1597.         {79,"TO_BusinessW2","TO_BusinessW2_W","Large"},
  1598.         {80,"TO_RichW1","TO_RichW1_W","Large"},
  1599.         {81,"TO_RichW2","TO_RichW2_W","Large"},
  1600.         {82,"TO_Fireman","TO_Fireman","Large"},
  1601.         {83,"TO_Cop","TO_Cop","Huge"},
  1602.         {84,"TO_Comic","TO_Comic","Fat"},
  1603.         {85,"GN_Bully03","GN_Bully03_W","Large"},
  1604.         {86,"TO_Bikeowner","TO_Bikeowner","Huge"},
  1605.         {87,"TO_Hobo","TO_Hobo_W","Huge"},
  1606.         {88,"Player_Mascot","Player_Mascot_W","Medium"},
  1607.         {89,"TO_GroceryOwner","TO_GroceryOwner","Huge"},
  1608.         {90,"GN_Sexygirl_UW","GN_Sexygirl_UW","Medium"},
  1609.         {91,"DOLead_Edgar","DOLead_Edgar_W","Large"},
  1610.         {92,"JK_LuisWrestle","JK_LuisWrestle","Huge"},
  1611.         {93,"JKGirl_MandyUW","JKGirl_MandyUW","Medium"},
  1612.         {94,"PRGirl_PinkyUW","PRGirl_PinkyUW","Medium"},
  1613.         {95,"NDGirl_BeatriceUW","NDGirl_BeatriceUW","Medium"},
  1614.         {96,"GRGirl_LolaUW","GRGirl_LolaUW","Medium"},
  1615.         {97,"TO_Cop2","TO_Cop2","Huge"},
  1616.         --{98,"Player_OWres","Player_Owres","Medium"},
  1617.         {99,"GN_Bully02","GN_Bully02_W","Medium"},
  1618.         {100,"TO_RichM1","TO_RichM1_W","Large"},
  1619.         {101,"TO_RichM2","TO_RichM2_W","Large"},
  1620.         {102,"GN_Bully01","GN_Bully01_W","Large"},
  1621.         {103,"TO_FireOwner","TO_FireOwner","Huge"},
  1622.         {104,"TO_CSOwner_2","TO_CSOwner_2","Huge"},
  1623.         {105,"TO_CSOwner_3","TO_CSOwner_3","Huge"},
  1624.         {106,"TE_Chemistry","TE_Chemistry_W","Huge"},
  1625.         {107,"TO_Poorwoman","TO_Poorwoman_W","Large"},
  1626.         {108,"TO_MotelOwner","TO_Motelowner_W","Huge"},
  1627.         {109,"JKKirby_FB","JKKirby_FB","Medium"},
  1628.         {110,"JKTed_FB","JKTed_FB","Large"},
  1629.         {111,"JKDan_FB","JKDan_FB","Medium"},
  1630.         {112,"JKDamon_FB","JKDamon_FB","Huge"},
  1631.         {113,"TO_Carny02","TO_Carny02_W","Huge"},
  1632.         {114,"TO_Carny01","TO_Carny01","Huge"},
  1633.         {115,"TO_CarnyMidget","TO_CarnyMidget_W","Small"},
  1634.         {116,"TO_Poorman2","TO_Poorman2_W","Huge"},
  1635.         {117,"PRH2A_Chad_OBOX","PRH2A_Chad_OBOX","Large"},
  1636.         {118,"PRH3_Justin_OBOX","PRH3_Justin_OBOX","Large"},
  1637.         {119,"PRH3a_Parker_OBOX","PRH3a_Parker_OBOX","Large"},
  1638.         {120,"TO_BarberRich","TO_BarberRich","Huge"},
  1639.         {121,"GenericWrestler","GenericWrestler","Huge"},
  1640.         {122,"ND_FattyWrestle","ND_FattyWrestle","Fat"},
  1641.         {123,"TO_Industrial","TO_Industrial_W","Huge"},
  1642.         {124,"TO_Associate","TO_Associate","Huge"},
  1643.         {125,"TO_Asylumpatient","TO_Asylumpatient","Huge"},
  1644.         {126,"TE_Autoshop","TE_Autoshop_W","Huge"},
  1645.         {127,"TO_Mailman","TO_Mailman_W","Huge"},
  1646.         {128,"TO_Tattooist","TO_Tattooist","Huge"},
  1647.         {129,"TE_Assylum","TE_Assylum","Huge"},
  1648.         {130,"Nemesis_Gary","Nemesis_Gary_W","Medium"},
  1649.         {131,"TO_Oldman2","TO_Oldman2_W","Large"},
  1650.         {132,"TO_BarberPoor","TO_BarberPoor","Large"},
  1651.         {133,"PR2nd_Bif_OBOX","PR2nd_Bif_OBOX","Huge"},
  1652.         {134,"Peter","Peter_W","Medium"},
  1653.         {135,"TO_RichM3","TO_RichM3_W","Large"},
  1654.         --{136,"Rat_Ped","Rat_Ped","Small"},
  1655.         {137,"GN_LittleGirl_2","GN_LittleGirl_2_W","Small"},
  1656.         {138,"GN_LittleGirl_3","GN_LittleGirl_3_W","Small"},
  1657.         {139,"GN_WhiteBoy","GN_WhiteBoy_W","Medium"},
  1658.         {140,"TO_FMidget","TO_FMidget","Small"},
  1659.         {141,"Dog_Pitbull","Dog_Pitbull","Small"},
  1660.         {142,"GN_SkinnyBboy","GN_SkinnyBboy_W","Medium"},
  1661.         {143,"TO_Carnie_female","TO_Carnie_fem_W","Large"},
  1662.         {144,"TO_Business3","TO_Business_03_W","Huge"},
  1663.         {145,"GN_Bully04","GN_Bully04_W","Large"},
  1664.         {146,"GN_Bully05","GN_Bully05_W","Medium"},
  1665.         {147,"GN_Bully06","GN_Bully06_W","Large"},
  1666.         {148,"TO_Business4","TO_Business4_W","Huge"},
  1667.         {149,"TO_Business5","TO_Business5_W","Huge"},
  1668.         {150,"DO_Otto_asylum","DO_Otto_asylum","Medium"},
  1669.         {151,"TE_History","TE_History","Huge"},
  1670.         {152,"TO_Record","TO_Record_W","Huge"},
  1671.         {153,"DO_Leon_Assylum","DO_Leon_Assylum","Huge"},
  1672.         {154,"DO_Henry_Assylum","DO_Henry_Assylum","Large"},
  1673.         {155,"NDH1_FattyChocolate","NDH1_FattyChocolate","Fat"},
  1674.         {156,"TO_GroceryClerk","TO_GroceryClerk","Huge"},
  1675.         {157,"TO_Handy","TO_Handy_W","Huge"},
  1676.         {158,"TO_Orderly2","TO_Orderly2_W","Huge"},
  1677.         {159,"GN_Hboy_Ween","GN_Hboy_Ween","Small"},
  1678.         {160,"Nemesis_Ween","Nemesis_Ween","Medium"},
  1679.         {161,"GRH3_Lucky_Ween","GRH3_Lucky_Ween","Large"},
  1680.         {162,"NDH3a_Donald_ween","NDH3a_Donald_ween","Medium"},
  1681.         {163,"PRH3a_Parker_Ween","PRH3a_Parker_Ween","Large"},
  1682.         {164,"JKH3_Casey_Ween","JKH3_Casey_Ween","Huge"},
  1683.         {165,"Peter_Ween","Peter_Ween","Medium"},
  1684.         {166,"GN_AsianGirl_Ween","GN_AsianGirl_Ween","Medium"},
  1685.         {167,"PRGirl_Pinky_Ween","PRGirl_Pinky_Ween","Medium"},
  1686.         {168,"JKH1_Damon_ween","JKH1_Damon_ween","Huge"},
  1687.         {169,"GN_WhiteBoy_Ween","GN_WhiteBoy_Ween","Medium"},
  1688.         {170,"GN_Bully01_Ween","GN_Bully01_Ween","Large"},
  1689.         {171,"GN_Boy02_Ween","GN_Boy02_Ween","Medium"},
  1690.         {172,"PR2nd_Bif_OBOX_D1","PR2nd_Bif_OBOX_D1","Huge"},
  1691.         {173,"GRH1a_Vance_Ween","GRH1a_Vance_Ween","Medium"},
  1692.         {174,"NDH2_Thad_Ween","NDH2_Thad_Ween","Large"},
  1693.         {175,"PRGirl_Pinky_BW","PRGirl_Pinky_BW","Medium"},
  1694.         {176,"DOlead_Russell_BU","DOlead_Russell_BU","Huge"},
  1695.         {177,"PRH1a_Tad_BW","PRH1a_Tad_BW","Medium"},
  1696.         {178,"PRH2_Bryce_BW","PRH2_Bryce_BW","Large"},
  1697.         {179,"PRH3_Justin_BW","PRH3_Justin_BW","Large"},
  1698.         {180,"GN_Asiangirl_CH","GN_Asiangirl_CH","Medium"},
  1699.         {181,"GN_Sexygirl_CH","GN_Sexygirl_CH","Medium"},
  1700.         {182,"PRGirl_Pinky_CH","PRGirl_Pinky_CH","Medium"},
  1701.         {183,"TO_NH_Res_01","TO_NH_Res_01","Large"},
  1702.         {184,"TO_NH_Res_02","TO_NH_Res_02","Large"},
  1703.         {185,"TO_NH_Res_03","TO_NH_Res_03","Medium"},
  1704.         {186,"NDH1_Fatty_DM","NDH1_Fatty_DM","Fat"},
  1705.         {187,"TO_PunkBarber","TO_PunkBarber","Huge"},
  1706.         {188,"FightingMidget_01","FightingMidget_01","Small"},
  1707.         {189,"FightingMidget_02","FightingMidget_02","Small"},
  1708.         {190,"TO_Skeletonman","TO_Skeletonman","Huge"},
  1709.         {191,"TO_Beardedwoman","TO_Beardedwoman","Huge"},
  1710.         {192,"TO_CarnieMermaid","TO_CarnieMermaid","Medium"},
  1711.         {193,"TO_Siamesetwin2","TO_Siamesetwin2","Medium"},
  1712.         {194,"TO_Paintedman","TO_Paintedman","Huge"},
  1713.         {195,"TO_GN_Workman","TO_GN_Workman","Huge"},
  1714.         {196,"DOLead_Edgar_GS","DOLead_Edgar_GS","Large"},
  1715.         {197,"DOH3a_Gurney_GS","DOH3a_Gurney_GS","Huge"},
  1716.         {198,"DOH2_Jerry_GS","DOH2_Jerry_GS","Large"},
  1717.         {199,"DOH2a_Leon_GS","DOH2a_Leon_GS","Huge"},
  1718.         {200,"GRH2a_Hal_GS","GRH2a_Hal_GS","Large"},
  1719.         {201,"GRH2_Norton_GS","GRH2_Norton_GS","Huge"},
  1720.         {202,"GR2nd_Peanut_GS","GR2nd_Peanut_GS","Large"},
  1721.         {203,"GRH1a_Vance_GS","GRH1a_Vance_GS","Medium"},
  1722.         {204,"JKH3a_Bo_GS","JKH3a_Bo_GS","Large"},
  1723.         {205,"JKH1_Damon_GS","JKH1_Damon_GS","Huge"},
  1724.         {206,"JK2nd_Juri_GS","JK2nd_Juri_GS","Huge"},
  1725.         {207,"JKH1a_Kirby_GS","JKH1a_Kirby_GS","Medium"},
  1726.         {208,"NDH1a_Algernon_GS","NDH1a_Algernon_GS","Fat"},
  1727.         {209,"NDH3_Bucky_GS","NDH3_Bucky_GS","Large"},
  1728.         {210,"NDH2_Thad_GS","NDH2_Thad_GS","Large"},
  1729.         {211,"PRH3a_Parker_GS","PRH3a_Parker_GS","Large"},
  1730.         {212,"PRH3_Justin_GS","PRH3_Justin_GS","Large"},
  1731.         {213,"PRH1a_Tad_GS","PRH1a_Tad_GS","Medium"},
  1732.         {214,"PRH1_Gord_GS","PRH1_Gord_GS","Medium"},
  1733.         {215,"NDLead_Earnest_EG","NDLead_Earnest_EG","Medium"},
  1734.         {216,"JKlead_Ted_EG","JKlead_Ted_EG","Large"},
  1735.         {217,"GRlead_Johnny_EG","GRlead_Johnny_EG","Large"},
  1736.         {218,"PRlead_Darby_EG","PRlead_Darby_EG","Large"},
  1737.         {219,"Dog_Pitbull2","Dog_Pitbull2","Small"},
  1738.         {220,"Dog_Pitbull3","Dog_Pitbull3","Small"},
  1739.         {221,"TE_CafeMU_W","TE_CafeMU_W","Huge"},
  1740.         {222,"TO_Millworker","TO_Millworker","Huge"},
  1741.         {223,"TO_Dockworker","TO_Dockworker","Huge"},
  1742.         {224,"NDH2_Thad_PJ","NDH2_Thad_PJ","Large"},
  1743.         {225,"GN_Lblkboy_PJ","GN_Lblkboy_PJ","Small"},
  1744.         {226,"GN_Hboy_PJ","GN_Hboy_PJ","Small"},
  1745.         {227,"GN_Boy01_PJ","GN_Boy01_PJ","Medium"},
  1746.         {228,"GN_Boy02_PJ","GN_Boy02_PJ","Large"},
  1747.         {229,"TE_Gym_Incog","TE_Gym_Incog_W","Huge"},
  1748.         {230,"JK_Mandy_Towel","JK_Mandy_Towel","Medium"},
  1749.         {231,"JK_Bo_FB","JK_Bo_FB","Large"},
  1750.         {232,"JK_Casey_FB","JK_Casey_FB","Huge"},
  1751.         --{233,"PunchBag","PunchBag","Large"},
  1752.         {234,"TO_Cop3","TO_Cop3","Huge"},
  1753.         {235,"GN_GreekboyUW","GN_GreekboyUW","Medium"},
  1754.         {236,"TO_Construct01","TO_Construct01","Huge"},
  1755.         {237,"TO_Construct02","TO_Construct02","Huge"},
  1756.         {238,"TO_Cop4","TO_Cop4","Huge"},
  1757.         {239,"PRH2_Bryce_OBOX_D1","PRH2_Bryce_OBOX_D1","Large"},
  1758.         {240,"PRH2_Bryce_OBOX_D2","PRH2_Bryce_OBOX_D2","Large"},
  1759.         {241,"PRH2A_Chad_OBOX_D1","PRH2A_Chad_OBOX_D1","Large"},
  1760.         {242,"PRH2A_Chad_OBOX_D2","PRH2A_Chad_OBOX_D2","Large"},
  1761.         {243,"PR2nd_Bif_OBOX_D2","PR2nd_Bif_OBOX_D2","Huge"},
  1762.         {244,"PRH3_Justin_OBOX_D1","PRH3_Justin_OBOX_D1","Large"},
  1763.         {245,"PRH3_Justin_OBOX_D2","PRH3_Justin_OBOX_D2","Large"},
  1764.         {246,"PRH3a_Prkr_OBOX_D1","PRH3a_Prkr_OBOX_D1","Large"},
  1765.         {247,"PRH3a_Prkr_OBOX_D2","PRH3a_Prkr_OBOX_D2","Large"},
  1766.         {248,"TE_Geography","TE_Geography","Huge"},
  1767.         {249,"TE_Music","TE_Music","Huge"},
  1768.         {250,"TO_ElfF","TO_ElfF","Medium"},
  1769.         {251,"TO_ElfM","TO_ElfM","Medium"},
  1770.         {252,"TO_HoboSanta","TO_HoboSanta","Huge"},
  1771.         {253,"TO_Santa","TO_Santa","Huge"},
  1772.         {254,"TO_Santa_NB","TO_Santa_NB","Huge"},
  1773.         {255,"Peter_Nutcrack","Peter_Nutcrack","Medium"},
  1774.         {256,"GN_Fatgirl_Fairy","GN_Fatgirl_Fairy","Fat"},
  1775.         {257,"GN_Lgirl_2_Flower","GN_Lgirl_2_Flower","Small"},
  1776.         {258,"GN_Hboy_Flower","GN_Hboy_Flower","Small"},
  1777.     }
  1778.    
  1779.     -- Setup other tables:
  1780.     local factions = {
  1781.         -- {Chance, name}
  1782.         -- [8] and beyond are adult
  1783.         {100,"NERD"},
  1784.         {100,"JOCK"},
  1785.         {100,"DROPOUT"},
  1786.         {100,"GREASER"},
  1787.         {100,"PREPPY"},
  1788.         {100,"STUDENT"},
  1789.         {100,"BULLY"},
  1790.         {50,"TOWNPERSON"},
  1791.         {50,"SHOPKEEP"},
  1792.         {10,"PREFECT"},
  1793.         {10,"COP"},
  1794.         {10,"TEACHER"},
  1795.     }
  1796.     local stats = {
  1797.         -- {Chance, stat}
  1798.         {1,"STAT_AN_DOG_A"},
  1799.         {1,"STAT_AN_RAT_A"},
  1800.         {1,"STAT_B_RUSSELL_A"},
  1801.         {1,"STAT_B_STRIKER_A"},
  1802.         {1,"STAT_B_STRIKER_B"},
  1803.         {1,"STAT_B_STRIKER_S"},
  1804.         {1,"STAT_CV_FEMALE_A"},
  1805.         {1,"STAT_CV_FEMALE_OLD"},
  1806.         {1,"STAT_CV_MALE_A"},
  1807.         {1,"STAT_CV_MALE_OLD"},
  1808.         {1,"STAT_DEFAULT"},
  1809.         {1,"STAT_DO_EDGAR"},
  1810.         {1,"STAT_DO_GRAPPLER_A"},
  1811.         {1,"STAT_DO_STRIKER_A"},
  1812.         {1,"STAT_GS_FEMALE_A"},
  1813.         {1,"STAT_GS_FEMALE_S"},
  1814.         {1,"STAT_GS_FEMALE_SMKID"},
  1815.         {1,"STAT_GS_GARY"},
  1816.         {1,"STAT_GS_MALE_A"},
  1817.         {1,"STAT_GS_MALE_SMKID"},
  1818.         {1,"STAT_GS_MALE_TATTLER"},
  1819.         {1,"STAT_G_GRAPPLER_A"},
  1820.         {1,"STAT_G_JOHNNY"},
  1821.         {1,"STAT_G_MELEE_A"},
  1822.         {1,"STAT_G_PIRATE"},
  1823.         {1,"STAT_G_STRIKER_A"},
  1824.         {1,"STAT_HOBO"},
  1825.         {1,"STAT_J_DAMON"},
  1826.         {1,"STAT_J_GRAPPLER_A"},
  1827.         {1,"STAT_J_GRAPPLER_B"},
  1828.         {1,"STAT_J_MASCOT"},
  1829.         {1,"STAT_J_MELEE_A"},
  1830.         {1,"STAT_J_STRIKER_A"},
  1831.         {1,"STAT_J_TED"},
  1832.         {1,"STAT_LE_OFFICER_A"},
  1833.         {1,"STAT_LE_ORDERLY_A"},
  1834.         {1,"STAT_N_EARNEST"},
  1835.         {1,"STAT_N_MELEE_A"},
  1836.         {1,"STAT_N_RANGED_A"},
  1837.         {1,"STAT_N_RANGED_S"},
  1838.         {1,"STAT_N_STRIKER_A"},
  1839.         {1,"STAT_N_STRIKER_B"},
  1840.         {1,"STAT_PF_BASIC_A"},
  1841.         {1,"STAT_PF_BASIC_S"},
  1842.         {1,"STAT_PLAYER"},
  1843.         {1,"STAT_P_BOXING"},
  1844.         {1,"STAT_P_BOXING_Bif"},
  1845.         {1,"STAT_P_BOXING_Bryce"},
  1846.         {1,"STAT_P_BOXING_Chad"},
  1847.         {1,"STAT_P_BOXING_Justin"},
  1848.         {1,"STAT_P_BOXING_Parker"},
  1849.         {1,"STAT_P_GRAPPLER_A"},
  1850.         {1,"STAT_P_STRIKER_A"},
  1851.         {1,"STAT_P_STRIKER_B"},
  1852.         {1,"STAT_TE_FEMALE_A"},
  1853.         {1,"STAT_TE_JANITOR"},
  1854.         {1,"STAT_TE_MALE_A"},
  1855.         {1,"STAT_TO_SIAMESE"},
  1856.         {1,"STAT_WRESTLING_FAT"},
  1857.         {1,"STAT_WRESTLING_GEN"},
  1858.         {1,"STAT_WRESTLING_LUIS"},
  1859.     }
  1860.     local styles = {
  1861.         -- {Chance, name}
  1862.         {50,"AN_DOG"},
  1863.         {20,"Authority"},
  1864.         {100,"B_Striker_A"},
  1865.         {200,"CV_Female_A"},
  1866.         {50,"CV_Male_A"},
  1867.         {100,"CV_OLD"},
  1868.         {100,"DO_Grappler_A"},
  1869.         {100,"DO_Striker_A"},
  1870.         {100,"GS_Fat_A"},
  1871.         {200,"GS_Female_A"},
  1872.         {100,"GS_Male_A"},
  1873.         {100,"G_Grappler_A"},
  1874.         {100,"G_Johnny"},
  1875.         {100,"G_Melee_A"},
  1876.         {100,"G_Striker_A"},
  1877.         {100,"J_Grappler_A"},
  1878.         {100,"J_Mascot"},
  1879.         {100,"J_Melee_A"},
  1880.         {100,"J_Striker_A"},
  1881.         {50,"LE_Orderly_A"},
  1882.         {100,"N_Ranged_A"},
  1883.         {100,"N_Striker_A"},
  1884.         {100,"N_Striker_B"},
  1885.         {100,"P_Grappler_A"},
  1886.         {100,"P_Striker_A"},
  1887.         {100,"P_Striker_B"},
  1888.         {50,"TE_Female_A"},
  1889.         {50,"Crazy_Basic"},
  1890.         {50,"BOSS_Russell"},
  1891.     }
  1892.    
  1893.     -- Setup chance:
  1894.     for i,t in ipairs({factions,stats,styles}) do
  1895.         local total = 0
  1896.         for i,v in ipairs(t) do
  1897.             total = total + v[1]
  1898.             v[1] = total
  1899.         end
  1900.     end
  1901.    
  1902.     -- Setup chance function:
  1903.     local getRandomShit = function(t,m)
  1904.         if not m then
  1905.             m = t[table.getn(t)][1]
  1906.         end
  1907.         if m >= 1 then
  1908.             local r = math.random(1,m)
  1909.             for i = table.getn(t),1,-1 do
  1910.                 local c = t[i-1]
  1911.                 if not c then
  1912.                     return t[i]
  1913.                 elseif r > c[1] then
  1914.                     return t[i]
  1915.                 end
  1916.             end
  1917.         end
  1918.         return t[1]
  1919.     end
  1920.    
  1921.     -- Setup ped tables:
  1922.     local texture = ChapterGet() == 2 and 3 or 2
  1923.     for k,v in ipairs(peds) do
  1924.         -- Sex and faction:
  1925.         local sex,faction
  1926.         if v[1] == 66 then
  1927.             sex = 0
  1928.             faction = getRandomShit(factions,factions[7][1])[2]
  1929.         else
  1930.             sex = chance(25) and 1 or 0
  1931.             faction = getRandomShit(factions)[2]
  1932.             if faction == "PREFECT" or faction == "COP" or faction == "TEACHER" then
  1933.                 gAuthority[v[1]] = true
  1934.             end
  1935.         end
  1936.        
  1937.         -- Style:
  1938.         local style = getRandomShit(styles)[2]
  1939.        
  1940.         -- Setup ped object:
  1941.         SetupPedObject(
  1942.             v[1], -- index
  1943.             v[2], -- model
  1944.             v[texture], -- texture (use model in every season but winter)
  1945.             sex, -- sex (1 = female)
  1946.             v[4], -- size (for animation)
  1947.             faction, -- faction
  1948.             getRandomShit(stats)[2], -- stat
  1949.             "null", -- animation group 1
  1950.             "null", -- animation group 2
  1951.             "null", -- animation group 3
  1952.             "null", -- animation group 4
  1953.             chance(10) and 2 or 1, -- unique model status (1 = one copy of this ped at a time, 2 = multiple)
  1954.             "/Global/"..style, -- style root
  1955.             "Act/Anim/"..style..".act", -- style file
  1956.             "/Global/AI", -- ai root
  1957.             "Act/AI/AI.act" -- ai file
  1958.         )
  1959.     end
  1960. end
  1961. function F_LoadAnimations()
  1962.     -- Setup animation groups:
  1963.     local anims = {
  1964.         -- Insanity animations:
  1965.         "4_04_FunhouseFun",
  1966.         "Boxing",
  1967.         "Hang_Talking",
  1968.         "MINI_React",
  1969.         "Russell",
  1970.         "Nemesis",
  1971.         "V_Bike",
  1972.         "bike",
  1973.         "F_Crazy",
  1974.        
  1975.         -- Default ped animations:
  1976.         "Authority",
  1977.         "B_Striker",
  1978.         "CV_Female",
  1979.         "CV_Male",
  1980.         "DO_Edgar",
  1981.         "DO_Grap",
  1982.         "DO_StrikeCombo",
  1983.         "DO_Striker",
  1984.         "F_Adult",
  1985.         "F_BULLY",
  1986.         "F_Douts",
  1987.         "F_Girls",
  1988.         "F_Greas",
  1989.         "F_Jocks",
  1990.         "F_Nerds",
  1991.         "F_OldPeds",
  1992.         "F_Pref",
  1993.         "F_Preps",
  1994.         "G_Grappler",
  1995.         "G_Johnny",
  1996.         "G_Striker",
  1997.         "Grap",
  1998.         "J_Damon",
  1999.         "J_Grappler",
  2000.         "J_Melee",
  2001.         "J_Ranged",
  2002.         "J_Striker",
  2003.         "LE_Orderly",
  2004.         "N_Ranged",
  2005.         "N_Striker",
  2006.         "N_Striker_A",
  2007.         "N_Striker_B",
  2008.         "P_Grappler",
  2009.         "P_Striker",
  2010.         "PunchBag",
  2011.         "Qped",
  2012.         "Rat_Ped",
  2013.         "Russell_Pbomb",
  2014.         "Straf_Dout",
  2015.         "Straf_Fat",
  2016.         "Straf_Female",
  2017.         "Straf_Male",
  2018.         "Straf_Nerd",
  2019.         "Straf_Prep",
  2020.         "Straf_Savage",
  2021.         "Straf_Wrest",
  2022.         "TE_Female",
  2023.     }
  2024.    
  2025.     -- Load animation groups:
  2026.     for i,v in ipairs(anims) do
  2027.         LoadAnimationGroup(v)
  2028.     end
  2029. end
  2030.  
  2031. -- General functions:
  2032. function PedCreateSheldonator(x,y,z)
  2033.     -- Create thread and table:
  2034.     if not gSheldonators then
  2035.         gSheldonators = {}
  2036.         gSheldonatorThread = function()
  2037.             local px,py,pz,near,nearBefore,notWanted
  2038.             local processSheldonator = function(v)
  2039.                 local x,y,z = PedGetPosXYZ(v[1])
  2040.                 local dist = math.sqrt((px-x)*(px-x) + (py-y)*(py-y) + (pz-z)*(pz-z))
  2041.                 if v[3] then
  2042.                     if GetTimer() >= v[3] + 1100/(v[2]/100) then
  2043.                         if PedGetGrappleTargetPed(v[1]) == gPlayer then
  2044.                             PlayerSetControl(0)
  2045.                             repeat
  2046.                                 PedSetActionNode(v[1],"/Global/Actions/Grapples/GrappleReversals/MountReversals/MountReversalPunches","Act/Globals.act")
  2047.                                 for hit = 1,2 do
  2048.                                     Wait(325/(v[2]/100))
  2049.                                     if not PedIsValid(v[1]) then
  2050.                                         return false
  2051.                                     end
  2052.                                     PlayerSetHealth(PlayerGetHealth()-7)
  2053.                                 end
  2054.                                 Wait(0)
  2055.                                 if not PedIsValid(v[1]) then
  2056.                                     return false
  2057.                                 end
  2058.                             until PedGetGrappleTargetPed(v[1]) ~= gPlayer or PlayerGetHealth() <= 0
  2059.                             while PedIsPlaying(v[1],"/Global/Actions/Grapples/GrappleReversals/MountReversals/MountReversalPunches",true) do
  2060.                                 Wait(0)
  2061.                                 if not PedIsValid(v[1]) then
  2062.                                     return false
  2063.                                 end
  2064.                             end
  2065.                             if PlayerGetHealth() <= 0 then
  2066.                                 PedSetActionNode(v[1],"/Global/404Conv/Nerds/Dance1","Act/Conv/4_04.act")
  2067.                             end
  2068.                             PlayerSetControl(1)
  2069.                         end
  2070.                         v[3] = nil
  2071.                     elseif PedGetGrappleTargetPed(v[1]) == gPlayer and IsButtonBeingPressed(9,0) then
  2072.                         local original = GameGetPedStat(v[1],39)
  2073.                         GameSetPedStat(v[1],39,0)
  2074.                         PedSetActionNode(gPlayer,"/Global/Actions/Grapples/Front/Grapples/GrappleMoves/DirectionalPush","Act/Globals.act")
  2075.                         PedSetActionNode(v[1],"/Global/Actions/Grapples/Front/Grapples/GrappleMoves/DirectionalPush/RCV","Act/Globals.act")
  2076.                         repeat
  2077.                             Wait(0)
  2078.                             if not PedIsValid(v[1]) then
  2079.                                 return false
  2080.                             end
  2081.                         until PedGetGrappleTargetPed(v[1]) ~= gPlayer
  2082.                         GameSetPedStat(v[1],39,original)
  2083.                         v[3] = nil
  2084.                     end
  2085.                 elseif PedMePlaying(v[1],"Default_KEY") and not PedIsDead(gPlayer) then
  2086.                     if GetTimer() >= v[4] then
  2087.                         if dist < 2.6 then
  2088.                             PedFaceXYZ(v[1],px,py,pz)
  2089.                             PedSetActionNode(v[1],"/Global/J_Damon/Offense/Medium/Grapples/GrapplesAttempt","Act/Anim/J_Damon.act")
  2090.                             v[3] = GetTimer()
  2091.                             v[4] = GetTimer() + math.random(2000,12500)
  2092.                         end
  2093.                     elseif GetTimer() >= v[6] then
  2094.                         if dist < 1.2 then
  2095.                             local reversed = false
  2096.                             PedFaceXYZ(v[1],px,py,pz)
  2097.                             PedSetActionNode(v[1],"/Global/Actions/Grapples/Front/Grapples/GrappleAttempt","Act/Globals.act")
  2098.                             while PedIsPlaying(v[1],"/Global/Actions/Grapples/Front/Grapples/GrappleAttempt",true) do
  2099.                                 Wait(0)
  2100.                                 if not PedIsValid(v[1]) then
  2101.                                     return false
  2102.                                 elseif PedGetGrappleTargetPed(v[1]) == gPlayer and IsButtonBeingPressed(9,0) then
  2103.                                     PedSetActionNode(gPlayer,"/Global/Actions/Grapples/Front/Grapples/GrappleMoves/DirectionalPush","Act/Globals.act")
  2104.                                     reversed = true
  2105.                                 end
  2106.                             end
  2107.                             if not reversed and PedGetGrappleTargetPed(v[1]) == gPlayer and PedIsPlaying(v[1],"/Global/Actions/Grapples/Front/Grapples/Hold_Idle",true) then
  2108.                                 local moves = {"GrappleStrikes/HitA/Charge","GrappleStrikes/HitB/Charge","GrappleStrikes/HitC/Charge","DirectionalPush","HeadButt","BodySlam"}
  2109.                                 local move = "/Global/Actions/Grapples/Front/Grapples/GrappleMoves/"..moves[math.random(1,table.getn(moves))]
  2110.                                 PedSetActionNode(v[1],move,"Act/Globals.act")
  2111.                                 while PedIsPlaying(v[1],move,true) do
  2112.                                     Wait(0)
  2113.                                     if not PedIsValid(v[1]) then
  2114.                                         return false
  2115.                                     end
  2116.                                 end
  2117.                             end
  2118.                             v[6] = GetTimer() + math.random(3000,9500)
  2119.                         end
  2120.                     elseif GetTimer() >= v[7] then
  2121.                         if dist < 1.4 then
  2122.                             PedFaceXYZ(v[1],px,py,pz)
  2123.                             PedSetActionNode(v[1],"/Global/BOSS_Darby/Offense/Short/Grapples/HeavyAttacks/Catch_Throw","Act/Anim/BOSS_Darby.act")
  2124.                         end
  2125.                         v[7] = GetTimer() + math.random(6000,14500)
  2126.                     end
  2127.                 end
  2128.                 if not near then
  2129.                     near = (dist < 10 or (dist < 50 and PedIsOnScreen(v[1]))) and not PedIsDead(v[1])
  2130.                 end
  2131.                 return true
  2132.             end
  2133.             while true do
  2134.                 px,py,pz = PlayerGetPosXYZ()
  2135.                 near = false
  2136.                 for i,v in ipairs(gSheldonators) do
  2137.                     if not PedIsValid(v[1]) or not processSheldonator(v) then
  2138.                         table.remove(gSheldonators,i)
  2139.                         i = i - 1
  2140.                     end
  2141.                 end
  2142.                 if near then
  2143.                     if not nearBefore then
  2144.                         notWanted = PlayerGetPunishmentPoints() <= 200
  2145.                     end
  2146.                     if notWanted then
  2147.                         if PlayerGetPunishmentPoints() > 200 then
  2148.                             PlayerSetPunishmentPoints(200)
  2149.                         end
  2150.                     elseif nearBefore then
  2151.                         notWanted = PlayerGetPunishmentPoints() <= 200
  2152.                     end
  2153.                 end
  2154.                 nearBefore = near
  2155.                 Wait(0)
  2156.             end
  2157.         end
  2158.         gSheldonatorThread = CreateThread("gSheldonatorThread")
  2159.     end
  2160.    
  2161.     -- Get spawn position:
  2162.     if not x or not y or not z then
  2163.         x,y,z = PedFindRandomSpawnPosition()
  2164.         if x == 9999 then
  2165.             return nil
  2166.         end
  2167.     end
  2168.    
  2169.     -- Spawn ped:
  2170.     local ped = PedCreateXYZ(66,x,y,z)
  2171.     PED_SetMissionPed(ped,true)
  2172.    
  2173.     -- Set stats:
  2174.     local health = math.random(150,400)
  2175.     local speed = gForceSlowSheldonator and 50 or math.random(145,265)
  2176.     PedSetHealth(ped,health)
  2177.     PedSetMaxHealth(ped,health)
  2178.     PedSetInfiniteSprint(ped,true)
  2179.     GameSetPedStat(ped,0,chance(10) and 363 or 358)
  2180.     GameSetPedStat(ped,1,10)
  2181.     GameSetPedStat(ped,2,360)
  2182.     GameSetPedStat(ped,3,500)
  2183.     GameSetPedStat(ped,6,0)
  2184.     GameSetPedStat(ped,7,0)
  2185.     GameSetPedStat(ped,8,100)
  2186.     GameSetPedStat(ped,12,math.random(40,65))
  2187.     GameSetPedStat(ped,14,100)
  2188.     GameSetPedStat(ped,20,speed)
  2189.     GameSetPedStat(ped,39,math.random(20,60))
  2190.     GameSetPedStat(ped,61,math.random(50,75))
  2191.     GameSetPedStat(ped,62,math.random(0,1))
  2192.     GameSetPedStat(ped,63,10)
  2193.    
  2194.     -- Set style:
  2195.     local styles = {
  2196.         "Authority",
  2197.         "DO_Striker_A",
  2198.         "G_Grappler_A",
  2199.         "G_Striker_A",
  2200.         "J_Striker_A",
  2201.         "Nemesis",
  2202.         "P_Striker_A",
  2203.         "Russell_102",
  2204.     }
  2205.     local style = styles[math.random(1,table.getn(styles))]
  2206.     PedSetActionTree(ped,"/Global/"..style,"Act/Anim/"..style..".act")
  2207.    
  2208.     -- Clear weapons:
  2209.     PedClearAllWeapons(ped)
  2210.    
  2211.     -- Attack player:
  2212.     PedSetPedToTypeAttitude(ped,13,0)
  2213.     PedAttackPlayer(ped,3)
  2214.    
  2215.     -- Add to sheldonators:
  2216.     table.insert(gSheldonators,{ped,speed,[4] = 0,[6] = 4000,[7] = 7000})
  2217.    
  2218.     -- Return handle:
  2219.     return ped
  2220. end
  2221. function PedStopLove(ped)
  2222.     local faction = PedGetFaction(ped)
  2223.     for f = 0,13 do
  2224.         if f ~= 12 and f ~= faction and PedGetPedToTypeAttitude(ped,f) > 2 then
  2225.             PedSetPedToTypeAttitude(ped,f,2)
  2226.         end
  2227.     end
  2228. end
  2229. function PedMakeNeutral(ped)
  2230.     local faction = PedGetFaction(ped)
  2231.     for f = 0,13 do
  2232.         if f ~= 12 and f ~= faction and PedGetPedToTypeAttitude(ped,f) ~= 2 then
  2233.             PedSetPedToTypeAttitude(ped,f,2)
  2234.         end
  2235.     end
  2236. end
  2237. function PedDislikesPlayer(ped)
  2238.     local e = PedGetEmotionTowardsPed(ped,gPlayer)
  2239.     return e == 0 or e == 1 or e == 2 or e == 4 or e == 5 or e == 6 or PedGetPedToTypeAttitude(ped,13) < 2 or gAuthority[PedGetModel(ped)] and PlayerGetPunishmentPoints() > 0 or PedGetWhoHitMeLast(ped) == gPlayer
  2240. end
  2241. function PedGetDistanceFromPed(ped1,ped2)
  2242.     local x1,y1,z1 = PedGetPosXYZ(ped1)
  2243.     local x2,y2,z2 = PedGetPosXYZ(ped2)
  2244.     local x,y,z = x1-x2,y1-y2,z1-z1
  2245.     return math.sqrt(x*x + y*y + z*z)
  2246. end
  2247. function PedGetModel(ped)
  2248.     if not gPedModels then
  2249.         gPedModels = {}
  2250.     end
  2251.     if gPedModels[ped] then
  2252.         return gPedModels[ped]
  2253.     end
  2254.     for i = 0,258 do
  2255.         if PedIsModel(ped,i) then
  2256.             gPedModels[ped] = i
  2257.             return i
  2258.         end
  2259.     end
  2260.     return -1
  2261. end
  2262. function chance(p)
  2263.     return math.random(1,100) <= p
  2264. end
  2265.  
  2266. -- New PedCreateXYZ:
  2267. pcxyz = PedCreateXYZ
  2268. function PedCreateXYZ(m,x,y,z)
  2269.     local ped = pcxyz(m,x,y,z)
  2270.     table.insert(gAllPeds,ped)
  2271.     return ped
  2272. end
  2273.  
  2274. -- Menu functions:
  2275. function MENU_BasicMenu(title,options,x,y,z,xl,yl,zl)
  2276.     gMenuActive = true
  2277.     title = title.."\n\n"
  2278.     PlayerSetControl(0)
  2279.     local s = 1
  2280.     local allStuff = {options}
  2281.     while true do
  2282.         local stuff = allStuff[table.getn(allStuff)]
  2283.         local str = title
  2284.         for i=s-3,s+3 do
  2285.             if i == s then
  2286.                 str = str..">"
  2287.             end
  2288.             if stuff[i] then
  2289.                 str = str..stuff[i][1]
  2290.             end
  2291.             if i < table.getn(stuff) then
  2292.                 str = str.."\n"
  2293.             end
  2294.         end
  2295.         TextPrintString(str,0,1)
  2296.         if zl then
  2297.             CameraSetXYZ(x,y,z,xl,yl,zl)
  2298.         end
  2299.         Wait(0)
  2300.         if not PedMePlaying(gPlayer,"Default_KEY") and not PedIsPlaying(gPlayer,"/Global/Weapons/SelectActions",true) then
  2301.             break
  2302.         elseif IsButtonBeingPressed(2,0) then
  2303.             s = s - 1
  2304.             if s < 1 and table.getn(stuff) > 0 then
  2305.                 s = table.getn(stuff)
  2306.             end
  2307.         elseif IsButtonBeingPressed(3,0) then
  2308.             s = s + 1
  2309.             if s > table.getn(stuff) then
  2310.                 s = 1
  2311.             end
  2312.         elseif IsButtonBeingPressed(7,0) and stuff[s][2] then
  2313.             if type(stuff[s][2]) == "table" then
  2314.                 table.insert(allStuff,stuff[s][2])
  2315.                 s = 1
  2316.             elseif stuff[s][3] then
  2317.                 stuff[s][2](unpack(stuff[s][3]))
  2318.             else
  2319.                 stuff[s][2]()
  2320.             end
  2321.         elseif IsButtonBeingPressed(8,0) then
  2322.             table.remove(allStuff)
  2323.             if table.getn(allStuff) < 1 then
  2324.                 break
  2325.             end
  2326.             s = 1
  2327.         end
  2328.     end
  2329.     if zl then
  2330.         CameraReset()
  2331.         CameraReturnToPlayer()
  2332.     end
  2333.     PlayerSetControl(1)
  2334.     gMenuActive = nil
  2335. end
  2336.  
  2337. -- Other functions:
  2338. function F_SpawnGarageVehicle(vehicle,drive)
  2339.     -- Create driving thread:
  2340.     if not gDrivingThread and drive then
  2341.         gDrivingThread = function()
  2342.             local pressTime,stopped
  2343.             local initEngine = function()
  2344.                 VehicleEnableEngine(gSpawnedVehicle,gSpawnedVehicleEngine)
  2345.                 if gSpawnedVehicleEngine then
  2346.                     VehicleSetAccelerationMult(gSpawnedVehicle,1)
  2347.                 else
  2348.                     VehicleSetAccelerationMult(gSpawnedVehicle,0)
  2349.                 end
  2350.             end
  2351.             while true do
  2352.                 Wait(0)
  2353.                 if gSpawnedVehicleDrive and VehicleIsValid(gSpawnedVehicle) then
  2354.                     local x,y,z = VehicleGetPosXYZ(gSpawnedVehicle)
  2355.                     if IsButtonBeingReleased(9,0) then
  2356.                         if PedIsInAreaXYZ(gPlayer,x,y,z,3) and PedMePlaying(gPlayer,"Default_KEY") then
  2357.                             PedWarpIntoCar(gPlayer,gSpawnedVehicle)
  2358.                             VehicleSetStatic(gSpawnedVehicle,false)
  2359.                             initEngine()
  2360.                         elseif gSpawnedVehicleDrive == 2 and PedIsInVehicle(gPlayer,gSpawnedVehicle) then
  2361.                             PedWarpOutOfCar(gPlayer)
  2362.                             VehicleDelete(gSpawnedVehicle)
  2363.                             gSpawnedVehicle = nil
  2364.                         end
  2365.                     elseif IsButtonBeingPressed(8,0) and PedIsInVehicle(gPlayer,gSpawnedVehicle) and (VehicleIsModel(gSpawnedVehicle,275) or VehicleIsModel(gSpawnedVehicle,295)) then
  2366.                         gSpawnedVehicleSiren = not gSpawnedVehicleSiren
  2367.                         VehicleEnableSiren(gSpawnedVehicle,gSpawnedVehicleSiren)
  2368.                     elseif gSpawnedVehicleDrive == 1 and PedIsInVehicle(gPlayer,gSpawnedVehicle) then
  2369.                         if not pressTime then
  2370.                             if IsButtonBeingPressed(3,0) then
  2371.                                 pressTime = GetTimer()
  2372.                             end
  2373.                         elseif gSpawnedVehicleEngine and (IsButtonPressed(6,0) or IsButtonPressed(7,0)) then
  2374.                             pressTime = nil
  2375.                         elseif IsButtonPressed(3,0) and GetTimer() >= pressTime + 500 then
  2376.                             gSpawnedVehicleEngine = not gSpawnedVehicleEngine
  2377.                             initEngine()
  2378.                             pressTime = nil
  2379.                         end
  2380.                     end
  2381.                 end
  2382.             end
  2383.         end
  2384.         gDrivingThread = CreateThread("gDrivingThread")
  2385.     end
  2386.    
  2387.     -- Delete old:
  2388.     if gSpawnedVehicle and VehicleIsValid(gSpawnedVehicle) then
  2389.         VehicleDelete(gSpawnedVehicle)
  2390.     end
  2391.    
  2392.     -- Create new:
  2393.     gSpawnedVehicle = VehicleCreateXYZ(vehicle,174.83,-10.37,5.76)
  2394.     if VehicleIsValid(gSpawnedVehicle) then
  2395.         VehicleSetColor(gSpawnedVehicle,math.random(0,99))
  2396.         VehicleFaceHeading(gSpawnedVehicle,math.pi/2)
  2397.         VehicleSetOwner(gSpawnedVehicle,gPlayer)
  2398.         gSpawnedVehicleDrive = drive
  2399.         gSpawnedVehicleSiren = false
  2400.         gSpawnedVehicleEngine = true
  2401.     else
  2402.         TextPrintString("Failed to retrieve vehicle!",1.5,1)
  2403.         Wait(1500)
  2404.     end
  2405. end
  2406.  
  2407. --[[ Debug tests:
  2408.     For testing shit. Set "gDebugTests" to true to spawn a debug blip in Jimmy's room.
  2409. ]]
  2410. if gDebugTests then
  2411.     function T_TestEvents()
  2412.         local s = 1
  2413.         while true do
  2414.             TextPrintString("Event #"..s.."\nPress ~ddown~ to start.",0,2)
  2415.             Wait(0)
  2416.             if IsButtonBeingPressed(0,0) then
  2417.                 s = s - 1
  2418.                 if s < 1 then
  2419.                     s = table.getn(gEvents)
  2420.                 end
  2421.             elseif IsButtonBeingPressed(1,0) then
  2422.                 s = s + 1
  2423.                 if s > table.getn(gEvents) then
  2424.                     s = 1
  2425.                 end
  2426.             elseif IsButtonBeingPressed(3,0) and not gMenuActive then
  2427.                 local x,y,z = PlayerGetPosXYZ()
  2428.                 while gEvents[s](x+1,y,z) == false do
  2429.                     TextPrintString("Launching event...",0,2)
  2430.                     Wait(0)
  2431.                 end
  2432.             end
  2433.         end
  2434.     end
  2435.     function T_TestErrands()
  2436.         local s = 1
  2437.         while true do
  2438.             TextPrintString("Errand #"..s.."\nPress ~ddown~ to start.",0,2)
  2439.             Wait(0)
  2440.             if IsButtonBeingPressed(0,0) then
  2441.                 s = s - 1
  2442.                 if s < 1 then
  2443.                     s = table.getn(gErrands)
  2444.                 end
  2445.             elseif IsButtonBeingPressed(1,0) then
  2446.                 s = s + 1
  2447.                 if s > table.getn(gErrands) then
  2448.                     s = 1
  2449.                 end
  2450.             elseif IsButtonBeingPressed(3,0) and not gMenuActive and gErrands[s] then
  2451.                 while ERRAND_Play(gErrands[s]) ~= 2 do
  2452.                     TextPrintString("Launching errand...",0,2)
  2453.                     Wait(0)
  2454.                 end
  2455.             end
  2456.         end
  2457.     end
  2458.     function T_TestPedEvents()
  2459.         local ped
  2460.         local s = 1
  2461.         while true do
  2462.             TextPrintString("Ped Event #"..s.."\nPress ~ddown~ to start.",0,2)
  2463.             Wait(0)
  2464.             if IsButtonBeingPressed(0,0) then
  2465.                 s = s - 1
  2466.                 if s < 1 then
  2467.                     s = table.getn(gPedEvents)
  2468.                 end
  2469.             elseif IsButtonBeingPressed(1,0) then
  2470.                 s = s + 1
  2471.                 if s > table.getn(gPedEvents) then
  2472.                     s = 1
  2473.                 end
  2474.             elseif IsButtonBeingPressed(3,0) and not gMenuActive then
  2475.                 if ped and PedIsValid(ped) then
  2476.                     PedDelete(ped)
  2477.                 end
  2478.                 ped = PedCreateXYZ(math.random(2,48),270,-110,6)
  2479.                 PED_SetMissionPed(ped,true)
  2480.                 AddBlipForChar(ped,0,0,1)
  2481.                 PedMakeAmbient(ped)
  2482.                 while PedIsValid(ped) and gPedEvents[s](ped) == false do
  2483.                     TextPrintString("Launching event...",0,2)
  2484.                     Wait(0)
  2485.                 end
  2486.             end
  2487.         end
  2488.     end
  2489.     function T_TestPedWeapons()
  2490.         local weapons = gSettings.peds.weapons
  2491.         local s = 1
  2492.         while true do
  2493.             TextPrintString("Weapon #"..s.."\nPress ~ddown~ to give.",0,2)
  2494.             Wait(0)
  2495.             if IsButtonBeingPressed(0,0) then
  2496.                 s = s - 1
  2497.                 if s < 1 then
  2498.                     s = table.getn(weapons)
  2499.                 end
  2500.             elseif IsButtonBeingPressed(1,0) then
  2501.                 s = s + 1
  2502.                 if s > table.getn(weapons) then
  2503.                     s = 1
  2504.                 end
  2505.             elseif IsButtonBeingPressed(3,0) and not gMenuActive then
  2506.                 PedSetWeapon(gPlayer,weapons[s],50,false)
  2507.             end
  2508.         end
  2509.     end
  2510.     function T_TestPedCount()
  2511.         while true do
  2512.             TextPrintString("Peds: "..(table.getn({PedFindInAreaXYZ(0,0,0,9999999)})-1),0,2)
  2513.             Wait(0)
  2514.         end
  2515.     end
  2516.     function T_TestSheldonator()
  2517.         while true do
  2518.             TextPrintString("Press ~ddown~ to spawn.",0,2)
  2519.             Wait(0)
  2520.             if IsButtonBeingPressed(3,0) and not gMenuActive then
  2521.                 local ped = PedCreateSheldonator(270,-110,6)
  2522.                 AddBlipForChar(ped,0,26,1)
  2523.                 PedMakeAmbient(ped)
  2524.             end
  2525.         end
  2526.     end
  2527.     function T_TestHealth()
  2528.         while true do
  2529.             local ped = PedGetTargetPed(gPlayer)
  2530.             if ped ~= -1 then
  2531.                 local lastHealth,newTarget = PedGetHealth(ped)
  2532.                 repeat
  2533.                     local health = PedGetHealth(ped)
  2534.                     if health ~= lastHealth then
  2535.                         TextPrintString(PedGetName(ped)..": "..string.format("%.1f",health-lastHealth).."HP",3,1)
  2536.                         lastHealth = health
  2537.                     end
  2538.                     Wait(0)
  2539.                     newTarget = PedGetTargetPed(gPlayer)
  2540.                 until not PedIsValid(ped) or (newTarget ~= -1 and newTarget ~= ped)
  2541.             end
  2542.             Wait(0)
  2543.         end
  2544.     end
  2545.     function T_TestBlips()
  2546.         local blip = BLIP_Create("test",0,270,-110,6,0,1,TextPrintString,"RAWR!",1,1)
  2547.         local status = 0
  2548.         while true do
  2549.             TextPrintString("Press ~dright~ to move.\nPress ~ddown~ to delete.",0,2)
  2550.             Wait(0)
  2551.             if IsButtonBeingPressed(3,0) and not gMenuActive and status < 2 then
  2552.                 BLIP_Delete(blip)
  2553.                 status = 2
  2554.                 TextPrintString("Blip deleted.",1,2)
  2555.                 Wait(1000)
  2556.             elseif IsButtonBeingPressed(1,0) and status < 1 then
  2557.                 BLIP_SetPosition(blip,270,-105,6)
  2558.                 status = 1
  2559.                 TextPrintString("Blip moved.",1,2)
  2560.                 Wait(1000)
  2561.             end
  2562.         end
  2563.     end
  2564.     function T_TestEggs()
  2565.         while true do
  2566.             TextPrintString("Press ~ddown~ to spawn.",0,2)
  2567.             Wait(0)
  2568.             if IsButtonBeingPressed(3,0) and not gMenuActive then
  2569.                 local ped = PedCreateXYZ(165,270,-110,6)
  2570.                 PED_SetMissionPed(ped,true)
  2571.                 PedSetStationary(ped,true)
  2572.                 PedSetWeapon(ped,312,50)
  2573.                 PedAttackPlayer(ped,3)
  2574.                 GameSetPedStat(ped,10,100)
  2575.                 GameSetPedStat(ped,11,100)
  2576.                 AddBlipForChar(ped,0,26,1)
  2577.                 PedMakeAmbient(ped)
  2578.                 local lastHealth = PedGetHealth(gPlayer)
  2579.                 repeat
  2580.                     local health = PedGetHealth(gPlayer)
  2581.                     if health ~= lastHealth then
  2582.                         TextPrintString(PedGetName(gPlayer)..": "..string.format("%.1f",health-lastHealth).."HP",3,1)
  2583.                         lastHealth = health
  2584.                     end
  2585.                     Wait(0)
  2586.                 until not PedIsValid(ped) or PedIsDead(ped) or IsButtonBeingPressed(3,0) and not gMenuActive
  2587.                 if PedIsValid(ped) then
  2588.                     PedDelete(ped)
  2589.                 end
  2590.             end
  2591.         end
  2592.     end
  2593.     function T_TestAnims()
  2594.         while true do
  2595.             TextPrintString("Press ~ddown~ to play.",0,2)
  2596.             Wait(0)
  2597.             if IsButtonBeingPressed(3,0) and not gMenuActive then
  2598.                 PedSetActionNode(gPlayer,"/Global/404Conv/Nerds/Dance2","Act/Conv/4_04.act")
  2599.             end
  2600.         end
  2601.     end
  2602.     function F_DeleteDebugThread()
  2603.         if gDebugThread then
  2604.             TerminateThread(gDebugThread)
  2605.             gDebugThread = nil
  2606.         end
  2607.     end
  2608.     function F_CreateDebugThread(thread)
  2609.         F_DeleteDebugThread()
  2610.         gDebugThread = CreateThread(thread)
  2611.     end
  2612.     gDebugMenu = {
  2613.         {"Tests",{
  2614.             {"Events",F_CreateDebugThread,{"T_TestEvents"}},
  2615.             {"Errands",F_CreateDebugThread,{"T_TestErrands"}},
  2616.             {"Ped Events",F_CreateDebugThread,{"T_TestPedEvents"}},
  2617.             {"Ped Weapons",F_CreateDebugThread,{"T_TestPedWeapons"}},
  2618.             {"Ped Count",F_CreateDebugThread,{"T_TestPedCount"}},
  2619.             {"Sheldonator",F_CreateDebugThread,{"T_TestSheldonator"}},
  2620.             {"Health",F_CreateDebugThread,{"T_TestHealth"}},
  2621.             {"Blips",F_CreateDebugThread,{"T_TestBlips"}},
  2622.             {"Eggs",F_CreateDebugThread,{"T_TestEggs"}},
  2623.             {"Animation",F_CreateDebugThread,{"T_TestAnims"}},
  2624.             {"Stop Test",F_DeleteDebugThread},
  2625.         }},
  2626.         {"Ped Spawns",{
  2627.             {"Stop Ped Spawns",StopPedProduction,{true}},
  2628.             {"Resume Ped Spawns",StopPedProduction,{false}},
  2629.         }},
  2630.         {"Punishment System",{
  2631.             {"Disable Punishment",DisablePunishmentSystem,{true}},
  2632.             {"Enable Punishment",DisablePunishmentSystem,{false}},
  2633.         }},
  2634.     }
  2635. end
  2636.  
  2637. -- STimeCycle functions:
  2638. function F_AttendedClass()
  2639.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2640.         return
  2641.     end
  2642.     SetSkippedClass(false)
  2643.     PlayerSetPunishmentPoints(0)
  2644. end
  2645. function F_MissedClass()
  2646.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2647.         return
  2648.     end
  2649.     SetSkippedClass(true)
  2650.     StatAddToInt(166)
  2651. end
  2652. function F_AttendedCurfew()
  2653.     if not PedInConversation(gPlayer) and not MissionActive() then
  2654.         TextPrintString("You got home in time for curfew", 4)
  2655.     end
  2656. end
  2657. function F_MissedCurfew()
  2658.     if not PedInConversation(gPlayer) and not MissionActive() then
  2659.         TextPrint("TM_TIRED5", 4, 2)
  2660.     end
  2661. end
  2662. function F_StartClass()
  2663.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2664.         return
  2665.     end
  2666. end
  2667. function F_EndClass()
  2668.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2669.         return
  2670.     end
  2671. end
  2672. function F_StartMorning()
  2673.     F_UpdateTimeCycle()
  2674. end
  2675. function F_EndMorning()
  2676.     F_UpdateTimeCycle()
  2677. end
  2678. function F_StartLunch()
  2679.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2680.         F_UpdateTimeCycle()
  2681.         return
  2682.     end
  2683.     F_UpdateTimeCycle()
  2684. end
  2685. function F_EndLunch()
  2686.     F_UpdateTimeCycle()
  2687. end
  2688. function F_StartAfternoon()
  2689.     F_UpdateTimeCycle()
  2690. end
  2691. function F_EndAfternoon()
  2692.     F_UpdateTimeCycle()
  2693. end
  2694. function F_StartEvening()
  2695.     F_UpdateTimeCycle()
  2696. end
  2697. function F_EndEvening()
  2698.     F_UpdateTimeCycle()
  2699. end
  2700. function F_StartCurfew_SlightlyTired()
  2701.     F_UpdateTimeCycle()
  2702. end
  2703. function F_StartCurfew_Tired()
  2704.     F_UpdateTimeCycle()
  2705. end
  2706. function F_StartCurfew_MoreTired()
  2707.     F_UpdateTimeCycle()
  2708. end
  2709. function F_StartCurfew_TooTired()
  2710.     F_UpdateTimeCycle()
  2711. end
  2712. function F_EndCurfew_TooTired()
  2713.     F_UpdateTimeCycle()
  2714. end
  2715. function F_EndTired()
  2716.     F_UpdateTimeCycle()
  2717. end
  2718. function F_Nothing()
  2719. end
  2720. function F_ClassWarning()
  2721.     if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
  2722.         return
  2723.     end
  2724.     local l_23_0 = math.random(1, 2)
  2725. end
  2726. function F_UpdateTimeCycle()
  2727.     if not IsMissionCompleated("1_B") then
  2728.         local l_24_0 = GetCurrentDay(false)
  2729.         if l_24_0 < 0 or l_24_0 > 2 then
  2730.             SetCurrentDay(0)
  2731.         end
  2732.     end
  2733.     F_UpdateCurfew()
  2734. end
  2735. function F_UpdateCurfew()
  2736.     local l_25_0 = shared.gCurfewRules
  2737.     if not l_25_0 then
  2738.         l_25_0 = F_CurfewDefaultRules
  2739.     end
  2740.     l_25_0()
  2741. end
  2742. function F_CurfewDefaultRules()
  2743.     local l_26_0 = ClockGet()
  2744.     if l_26_0 >= 23 or l_26_0 < 7 then
  2745.         shared.gCurfew = true
  2746.     else
  2747.         shared.gCurfew = false
  2748.     end
  2749. end
Advertisement
Add Comment
Please, Sign In to add comment