Advertisement
HR_Shaft

Fling Race for bloodgulch & gephyrophobia PC/CE for SAPP

Oct 28th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.03 KB | None | 0 0
  1. -- Fling Race for bloodgulch and gephyrophobia PC/CE
  2. -- by H® Shaft for SAPP
  3.  
  4. -- A fun bloodgulch and gephyrophobia PC/CE race variant which flings players in vehicles from one location to another
  5. -- Note: Best results: the race gametype should have race navs in "Normal Order" - NOT "Any Order" or "Rally" but - will still work regardless
  6. -- if script is loaded on a gametype other than race, it will skip to next map, and log error in the sapp log
  7.  
  8. -- sapp api version
  9. api_version = "1.9.0.0"
  10.  
  11. function OnScriptLoad()
  12.     register_callback(cb['EVENT_TICK'],"OnTick")
  13.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  14.     if get_var(0, "$gt") ~= "n/a" then
  15.         if get_var(0, "$gt") == "race" then
  16.             CreateMarkers()
  17.         else
  18.             cprint("This script is intended for RACE gametypes only.")
  19.         end            
  20.     end
  21. end
  22.  
  23. function OnNewGame()
  24.     map_name = get_var(0,"$map")
  25.     if get_var(0, "$gt") == "race" then
  26.         CreateMarkers()
  27.     else
  28.         cprint("This script is intended for RACE gametypes only.")
  29.         local data = string.format("%s on %s: fling-race script is intended for RACE gametypes only.", tostring(map_name), tostring(get_var(0, "$gt")))
  30.         execute_command("log_note \""..data.."\"")
  31.         execute_command("sv_map_next")
  32.         return
  33.     end
  34. end
  35.  
  36. function CreateMarkers()
  37.     map_name = get_var(0,"$map") -- if reloaded after game started, ensure map name is read
  38.     if map_name == "gephyrophobia" then
  39.         -- flag markers used to mark teleports on gephyrophobia, disable them from being picked up
  40.         execute_command("disable_object weapons\\flag\\flag")
  41.         -- below red base teleport to top
  42.         local marker1 = spawn_object("weap", "weapons\\flag\\flag", 26.787, -124.054, -18.315)
  43.         -- below blue base teleport to top
  44.         local marker2 = spawn_object("weap", "weapons\\flag\\flag", 26.80, -20.015, -18.32)
  45.         -- nav3 - throws player thru center tower hole to lower level
  46.         local marker3 = spawn_object("weap", "weapons\\flag\\flag", 26.797, -101.776, -13.213) 
  47.     end
  48. end
  49.    
  50. function OnTick()
  51.     for PlayerIndex=1,16 do
  52.         if player_alive(PlayerIndex) then
  53.             local player_object = get_dynamic_player(PlayerIndex)
  54.             local player_obj_id = read_dword(get_player(PlayerIndex) + 0x34)
  55.             local vehicleId = read_dword(player_object + 0x11C)
  56.             local vehicle_object = get_object_memory(vehicleId)
  57.            
  58.             if (player_object ~= 0) then
  59.                 if isinvehicle(PlayerIndex) and PlayerIsDriver(PlayerIndex) then
  60.                     player_obj_id = vehicleId
  61.                    
  62.                     -- bloodgulch specific settings
  63.                     if map_name == "bloodgulch" then
  64.                         local nav1 = inSphere(player_obj_id, 59.785, -121.995, 0.268, 2)
  65.                         local nav2 = inSphere(player_obj_id, 95.514, -171.713, 0.329, 2)
  66.                         local nav3 = inSphere(player_obj_id, 40.367, -66.605, 0.640, 2)
  67.                         local nav4 = inSphere(player_obj_id, 71.166, -92.553, 4.665, 2)
  68.                         local nav5 = inSphere(player_obj_id, 60.645, -150.747, 6.292, 2)   
  69.  
  70.                         if nav1 then
  71.                             moveobject(player_obj_id, 59.818, -121.994, 2.224)
  72.                             write_float(vehicle_object + 0x6C, -0.35)
  73.                             write_float(vehicle_object + 0x68, 0.15)
  74.                             write_float(vehicle_object + 0x70, 0.25)
  75.                             write_float(vehicle_object + 0x8C, 0)
  76.                             write_float(vehicle_object + 0x90, 0)
  77.                             write_float(vehicle_object + 0x94, -0.2)
  78.                             local grunt = generategrunt(grunt)
  79.                             rprint(PlayerIndex, "|c".. grunt)                          
  80.                         end
  81.                        
  82.                         if nav2 then
  83.                             moveobject(player_obj_id, 95.504, -171.680, 2.224)
  84.                             write_float(vehicle_object + 0x6C, 0.89)
  85.                             write_float(vehicle_object + 0x68, -0.388)
  86.                             write_float(vehicle_object + 0x70, 0.265)
  87.                             write_float(vehicle_object + 0x8C, 0)
  88.                             write_float(vehicle_object + 0x90, 0)
  89.                             write_float(vehicle_object + 0x94, -0.2)
  90.                             local grunt = generategrunt(grunt)
  91.                             rprint(PlayerIndex, "|c".. grunt)
  92.                         end
  93.  
  94.                         if nav3 then
  95.                             moveobject(player_obj_id, 40.427, -66.627, 2.224)
  96.                             write_float(vehicle_object + 0x6C, -0.35)
  97.                             write_float(vehicle_object + 0x68, 0.15)
  98.                             write_float(vehicle_object + 0x70, 0.3)
  99.                             write_float(vehicle_object + 0x8C, 0)
  100.                             write_float(vehicle_object + 0x90, 0)
  101.                             write_float(vehicle_object + 0x94, -0.2)
  102.                             local grunt = generategrunt(grunt)
  103.                             rprint(PlayerIndex, "|c".. grunt)                          
  104.                         end
  105.  
  106.                         if nav4 then
  107.                             moveobject(player_obj_id, 70.608, -96.019, 6.444)
  108.                             write_float(vehicle_object + 0x6C, -0.30)
  109.                             write_float(vehicle_object + 0x68, -0.15)
  110.                             write_float(vehicle_object + 0x70, 0.25)
  111.                             write_float(vehicle_object + 0x8C, 0)
  112.                             write_float(vehicle_object + 0x90, 0)
  113.                             write_float(vehicle_object + 0x94, -0.2)
  114.                             local grunt = generategrunt(grunt)
  115.                             rprint(PlayerIndex, "|c".. grunt)                          
  116.                         end
  117.  
  118.                         if nav5 then
  119.                             moveobject(player_obj_id, 60.312, -149.034, 7.904)
  120.                             write_float(vehicle_object + 0x6C, 0.25)
  121.                             write_float(vehicle_object + 0x68, 0.11)
  122.                             write_float(vehicle_object + 0x70, 0.20)
  123.                             write_float(vehicle_object + 0x8C, 0)
  124.                             write_float(vehicle_object + 0x90, 0)
  125.                             write_float(vehicle_object + 0x94, -0.2)
  126.                             local grunt = generategrunt(grunt)
  127.                             rprint(PlayerIndex, "|c".. grunt)
  128.                         end                    
  129.                     end -- end bloodgulch specific settings
  130.                    
  131.                     -- gephyrophobia specific settings
  132.                     if map_name == "gephyrophobia" then
  133.                         local nav3 = inSphere(player_obj_id, 26.797, -101.776, -13.213, 2)
  134.                         local nav5 = inSphere(player_obj_id, 26.804, -45.347, -17.465, 2)
  135.                         local bottomsupred = inSphere(player_obj_id, 26.787, -124.054, -18.315, 2)
  136.                         local bottomsupblu = inSphere(player_obj_id, 26.80, -20.015, -18.32, 2)                    
  137.                         if nav3 then
  138.                             moveobject(player_obj_id, 26.797, -101.776, -10.583)
  139.                             write_float(vehicle_object + 0x6C, 0)
  140.                             write_float(vehicle_object + 0x68, 0)
  141.                             write_float(vehicle_object + 0x6C, 0.52)
  142.                             write_float(vehicle_object + 0x70, 0.15)
  143.                             write_float(vehicle_object + 0x8C, 0)
  144.                             write_float(vehicle_object + 0x90, 0)
  145.                             write_float(vehicle_object + 0x94, 0.2)
  146.                             local grunt = generategrunt(grunt)
  147.                             rprint(PlayerIndex, "|c".. grunt)                          
  148.                         end
  149.                        
  150.                         if nav5 then
  151.                             moveobject(player_obj_id, 26.804, -45.347, -10.445)
  152.                             write_float(vehicle_object + 0x6C, 0)
  153.                             write_float(vehicle_object + 0x68, 0)
  154.                             write_float(vehicle_object + 0x6C, -0.52)
  155.                             write_float(vehicle_object + 0x70, 0.15)
  156.                             write_float(vehicle_object + 0x8C, 0)
  157.                             write_float(vehicle_object + 0x90, 0)
  158.                             write_float(vehicle_object + 0x94, -0.23)
  159.                             local grunt = generategrunt(grunt)
  160.                             rprint(PlayerIndex, "|c".. grunt)                          
  161.                         end
  162.                        
  163.                         if bottomsupred then -- teleport up
  164.                             moveobject(player_obj_id, 14.227, -93.119, -13.975)
  165.                             local grunt = generategrunt(grunt)
  166.                             rprint(PlayerIndex, "|c".. grunt)                          
  167.                         end
  168.                        
  169.                         if bottomsupblu then -- teleport up
  170.                             moveobject(player_obj_id, 39.58, -51.50, -13.975)
  171.                             local grunt = generategrunt(grunt)
  172.                             rprint(PlayerIndex, "|c".. grunt)                          
  173.                         end
  174.                        
  175.                     end -- end gephyrophobia specific settings
  176.                    
  177.                 end
  178.             end
  179.         end
  180.     end
  181. end
  182.        
  183. function isinvehicle(PlayerIndex)
  184.     local player_object = get_dynamic_player(PlayerIndex)
  185.     local vehicleId = read_dword(player_object + 0x11C)
  186.     if vehicleId == 0xFFFFFFFF then
  187.         return false
  188.     else
  189.         return true
  190.     end
  191. end
  192.  
  193. function PlayerIsDriver(PlayerIndex)
  194.     if (player_alive(PlayerIndex) == false) then return false end
  195.     local player_object = get_dynamic_player(PlayerIndex)
  196.     local player_object_id = read_dword(get_player(PlayerIndex) + 0x34)
  197.     local vehicleId = read_dword(player_object + 0x11C)
  198.     if (vehicleId == 0xFFFFFFFF) then return false end
  199.     local obj_id = get_object_memory(vehicleId)
  200.     return read_dword(obj_id + 0x324) == player_object_id
  201. end
  202.        
  203. function moveobject(ObjectID, x, y, z)
  204.     local object = get_object_memory(ObjectID)
  205.     if get_object_memory(ObjectID) ~= 0 then
  206.         local veh_obj = get_object_memory(read_dword(object + 0x11C))
  207.         write_vector3d((veh_obj ~= 0 and veh_obj or object) + 0x5C, x, y, z)
  208.     end
  209. end
  210.  
  211. function inSphere(ObjectID, X, Y, Z, R)
  212.     if get_object_memory(ObjectID) ~= 0 then
  213.         local x,y,z = getobjectcoords(ObjectID)
  214.         if (X - x)^2 + (Y - y)^2 + (Z - z)^2 <= R then
  215.             return true
  216.         else
  217.             return false
  218.         end
  219.     end
  220. end
  221.    
  222. function getobjectcoords(ObjectID)
  223.     local object = get_object_memory(ObjectID)
  224.     if get_object_memory(ObjectID) ~= 0 then
  225.         local veh_obj = get_object_memory(read_dword(object + 0x11C))
  226.         if veh_obj ~= 0 then
  227.             object = veh_obj
  228.         end
  229.     end
  230.     return read_vector3d(object + 0x5C)
  231. end
  232.  
  233. function generategrunt(grunt)
  234.     local grunt = {"WEEEE!", "Whoa!", "Holy Crap!", "WTF!", "Fuuuh!", "Efff!", "Nuhuh!", "Arrg!", "GEEEZ!", "Who Flung Poo?!"}
  235.     local gruntcount = #grunt
  236.     local rand_grunt = rand(1, gruntcount+1)
  237.     local grunt_type = string.format("%s",  grunt[rand_grunt])
  238.     if grunt_type then
  239.         return grunt_type
  240.     else
  241.         return "DUDE!"
  242.     end
  243. end
  244.    
  245. -- Created by H® Shaft
  246. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement