Advertisement
HR_Shaft

Custom Team Spawns by H® Shaft for SAPP

Oct 27th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.83 KB | None | 0 0
  1. -- Custom Team Spawns by H® Shaft for SAPP
  2.  
  3. -- All players spawn at their own base or custom locations you setup for red and blue teams.  
  4. -- Admins (levels > 0) can type 'coord' to retreive their coordinates (x,y,z,rotation) and log it to setup custom spawns (see function Load_Tables at line 155 for more info)
  5. -- Initially designed for Team Race (on the maps listed below) but can be used for other game types
  6. -- Spawns setup/completed for these maps only: bloodgulch, dangercanyon, deathisland, gephyrophobia, infinity, icefields, sidewinder, timberland
  7.  
  8. -- sapp api version
  9. api_version = "1.9.0.0"
  10. team_play = false
  11. loop_end = 8
  12.  
  13. function OnScriptLoad()
  14.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  15.     register_callback(cb['EVENT_PRESPAWN'], "OnPlayerPrespawn")
  16.     register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
  17.     if get_var(0, "$gt") ~= "n/a" then
  18.         map_name = get_var(0,"$map")
  19.         team_play = getteamplay()
  20.         Load_Tables()
  21.     end
  22. end
  23.  
  24. function OnNewGame()
  25.     map_name = get_var(0,"$map")
  26.     team_play = getteamplay()
  27.     Load_Tables()
  28. end
  29.  
  30. function OnPlayerChat(PlayerIndex, Message)
  31.     local response = nil
  32.     local Message = string.lower(Message)
  33.     local isadmin = nil
  34.    
  35.     if (tonumber(get_var(PlayerIndex,"$lvl"))) > 0 then
  36.         isadmin = true
  37.     else
  38.         isadmin = false
  39.     end    
  40.    
  41.     -- | type "coord" to retrieve your coordinates x,y,z and rotation (rotation is yaw = the direction you are facing, not the same as "aim")
  42.     -- | records map name and coordinates entries into log: map name, x,y,z,r
  43.     if (Message == "coord") then
  44.         if isadmin == true then
  45.             local player_static = get_player(PlayerIndex)
  46.             local x,y,z = GetPlayerCoords(PlayerIndex)
  47.             local rotation = read_float(player_static + 0x138)
  48.             local map_name = get_var(0,"$map")
  49.             local data = string.format("%s, %s, %s, %s, %s", tostring(map_name),tostring(x),tostring(y),tostring(z),tostring(math.round(rotation, 2)))
  50.             execute_command("log_note \""..data.."\"")     
  51.             say(PlayerIndex, "X: " .. x .. "  Y: " .. y .. "  Z: " .. z .. "  R: " .. math.round(rotation, 2))
  52.             response = false
  53.         else
  54.             response = true
  55.         end
  56.     end
  57.    
  58.     return response
  59. end
  60.    
  61. function OnPlayerPrespawn(PlayerIndex)
  62.     local player_object = get_dynamic_player(PlayerIndex)
  63.     if (player_object ~= 0) then
  64.         if team_play then
  65.             local team = get_var(PlayerIndex, "$team")
  66.  
  67.             if team == "red" then
  68.                 local redcoord = SelectRedSpawnCoord()
  69.                 if redcoord then       
  70.                     write_vector3d(player_object + 0x5C, red_spawn_coord[redcoord][1], red_spawn_coord[redcoord][2], red_spawn_coord[redcoord][3])
  71.                     write_dword(get_player(PlayerIndex) + 0xF0, 0) -- sync instantly to the player
  72.                     write_dword(get_player(PlayerIndex) + 0x164, 0) -- sync instantly to others                
  73.                     local fx, fy, fz = red_rotation[1][1],red_rotation[1][2],red_rotation[1][3]
  74.                     local px, py, pz = GetPlayerCoords(PlayerIndex)
  75.                     local vx = fx - px
  76.                     local vy = fy - py
  77.                     local vz = fz - pz
  78.                     -- normalize it
  79.                     local magnitude = math.sqrt(vx*vx + vy*vy + vz*vz)
  80.                     vx = vx / magnitude
  81.                     vy = vy / magnitude
  82.                     vz = vz / magnitude    
  83.                     write_float(player_object + 0x74, vx)
  84.                     write_float(player_object + 0x78, vy)
  85.                     write_float(player_object + 0x7c, vz)          
  86.                 end
  87.                
  88.             elseif team == "blue" then
  89.                 local blucoord = SelectBluSpawnCoord()
  90.                 if blucoord then       
  91.                     write_vector3d(player_object + 0x5C, blu_spawn_coord[blucoord][1], blu_spawn_coord[blucoord][2], blu_spawn_coord[blucoord][3])
  92.                     write_dword(get_player(PlayerIndex) + 0xF0, 0) -- sync instantly to the player
  93.                     write_dword(get_player(PlayerIndex) + 0x164, 0) -- sync instantly to others
  94.                     local fx, fy, fz = blue_rotation[1][1],blue_rotation[1][2],blue_rotation[1][3]
  95.                     local px, py, pz = GetPlayerCoords(PlayerIndex) --read_vector3d(player_object + 0x5C)
  96.                     local vx = fx - px
  97.                     local vy = fy - py
  98.                     local vz = fz - pz
  99.                     -- normalize it
  100.                     local magnitude = math.sqrt(vx*vx + vy*vy + vz*vz)
  101.                     vx = vx / magnitude
  102.                     vy = vy / magnitude
  103.                     vz = vz / magnitude    
  104.                     write_float(player_object + 0x74, vx)
  105.                     write_float(player_object + 0x78, vy)
  106.                     write_float(player_object + 0x7c, vz)                          
  107.                 end
  108.             end
  109.         end
  110.     end        
  111. end
  112.  
  113. function SelectRedSpawnCoord()
  114.     if #red_spawn_coord > 0 then
  115.         local index = rand(1, #red_spawn_coord+1)
  116.         local coord = red_spawn_coord[index]
  117.         if (CheckForDuplicateSpawn(coord) == false) then
  118.             return index    
  119.         end
  120.     end    
  121.     return nil 
  122. end
  123.  
  124. function SelectBluSpawnCoord()
  125.     if #blu_spawn_coord > 0 then
  126.         local index = rand(1, #blu_spawn_coord+1)
  127.         local coord = blu_spawn_coord[index]   
  128.         if (CheckForDuplicateSpawn(coord) == false) then
  129.             return index       
  130.         end
  131.     end
  132.     return nil 
  133. end
  134.  
  135. -- written by 002:
  136. function CheckForDuplicateSpawn(coord)
  137.     for i=1,loop_end do
  138.         local dyn_player = get_dynamic_player(i)
  139.         if(dyn_player ~= 0) then
  140.             local px,py,pz = GetPlayerCoords(i)
  141.             local distance = DistanceFormula(coord[1],coord[2],coord[3],px,py,pz)
  142.             if(distance < 1) then
  143.                 return true
  144.             end
  145.         end
  146.     end
  147.     return false
  148. end
  149.  
  150. -- written by 002:
  151. function DistanceFormula(x1,y1,z1,x2,y2,z2)
  152.     return math.sqrt(math.pow(x1 - x2,2) + math.pow(y1 - y2,2) + math.pow(z1 - z2,2))
  153. end
  154.  
  155. function Load_Tables()
  156.     red_spawn_coord = {}
  157.     blu_spawn_coord = {}
  158.     red_rotation = {}
  159.     blue_rotation = {}
  160.    
  161.     if map_name == "bloodgulch" then
  162.         red_rotation[1] = {60.987, -121.606, 0.274} -- direction a red player faces relative to this x,y,z coordinate
  163.         blue_rotation[1] = {60.987, -121.606, 0.274} -- direction a blue player faces relative to this x,y,z coordinate
  164.         -- player spawns by team - for best results, have a MINIMUM of 8 per team, more is better
  165.         -- 8 red player spawns
  166.         red_spawn_coord[1] = {68.911, -173.686, 1.815}
  167.         red_spawn_coord[2] = {74.323, -173.370, 0.817}
  168.         red_spawn_coord[3] = {79.380, -173.402, 0.410}
  169.         red_spawn_coord[4] = {84.011, -173.499, 0.307}
  170.         red_spawn_coord[5] = {89.487, -173.463, 0.344}
  171.         red_spawn_coord[6] = {95.069, -173.863, 0.718}
  172.         red_spawn_coord[7] = {100.525, -174.038, 0.813}
  173.         red_spawn_coord[8] = {105.292, -173.656, 0.229}
  174.         -- 8 blue player spawns
  175.         blu_spawn_coord[1] = {61.292, -65.713, 1.693}
  176.         blu_spawn_coord[2] = {57.520, -65.796, 1.233}
  177.         blu_spawn_coord[3] = {53.473, -66.050, 0.927}
  178.         blu_spawn_coord[4] = {49.578, -66.108, 0.848}
  179.         blu_spawn_coord[5] = {32.593, -65.859, 0.447}
  180.         blu_spawn_coord[6] = {29.079, -65.796, 0.793}
  181.         blu_spawn_coord[7] = {26.038, -65.906, 1.243}
  182.         blu_spawn_coord[8] = {23.010, -65.879, 1.813}      
  183.        
  184.     elseif map_name == "dangercanyon" then
  185.         red_rotation[1] = {-37.219, 0.058, -2.172}
  186.         blue_rotation[1] = {37.756, 0.404, -2.172} 
  187.    
  188.         red_spawn_coord[1] = {-16.254, -1.222, -4.030}
  189.         red_spawn_coord[2] = {-16.235, -5.483, -4.030}
  190.         red_spawn_coord[3] = {-15.767, 2.010, -4.000}
  191.         red_spawn_coord[4] = {-14.096, -7.125, -4.000}
  192.         red_spawn_coord[5] = {-6.198, -0.202, -4.028}
  193.         red_spawn_coord[6] = {-8.746, -7.146, -4.025}
  194.         red_spawn_coord[7] = {-3.195, -6.566, -4.022}
  195.         red_spawn_coord[8] = {-3.244, -1.144, -4.028}
  196.        
  197.         blu_spawn_coord[1] = {16.140, -1.544, -4.030}
  198.         blu_spawn_coord[2] = {16.068, -5.484, -4.030}
  199.         blu_spawn_coord[3] = {15.730, 1.627, -3.990}
  200.         blu_spawn_coord[4] = {13.715, -7.029, -3.990}
  201.         blu_spawn_coord[5] = {3.785, -1.194, -4.028}
  202.         blu_spawn_coord[6] = {3.375, -6.669, -4.022}
  203.         blu_spawn_coord[7] = {5.585, -1.158, -3.998}
  204.         blu_spawn_coord[8] = {8.429, -6.587, -4.025}   
  205.        
  206.     elseif map_name == "deathisland" then
  207.         red_rotation[1] = {-61.327, -9.832, 1.843}
  208.         blue_rotation[1] = {55.415, 13.656, 1.775} 
  209.    
  210.         red_spawn_coord[1] = {-36.889, -4.007, 9.417}
  211.         red_spawn_coord[2] = {-36.853, -9.937, 9.417}
  212.         red_spawn_coord[3] = {-38.445, -2.989, 5.744}
  213.         red_spawn_coord[4] = {-37.452, -11.724, 5.056}
  214.         red_spawn_coord[5] = {-39.155, -5.780, 5.225}
  215.         red_spawn_coord[6] = {-39.095, -8.268, 5.064}
  216.         red_spawn_coord[7] = {-41.475, -5.493, 4.936}
  217.         red_spawn_coord[8] = {-41.673, -8.819, 4.706}
  218.        
  219.         blu_spawn_coord[1] = {40.430, 13.260, 8.050}
  220.         blu_spawn_coord[2] = {40.381, 18.714, 8.050}
  221.         blu_spawn_coord[3] = {40.268, 11.340, 4.605}
  222.         blu_spawn_coord[4] = {40.245, 20.333, 4.498}
  223.         blu_spawn_coord[5] = {42.548, 15.075, 4.772}
  224.         blu_spawn_coord[6] = {42.434, 17.335, 4.657}
  225.         blu_spawn_coord[7] = {44.715, 15.356, 4.298}
  226.         blu_spawn_coord[8] = {44.632, 17.430, 4.509}
  227.        
  228.     elseif map_name == "gephyrophobia" then
  229.         red_rotation[1] = {26.831, -72.683, -10.699}
  230.         blue_rotation[1] = {26.831, -72.683, -10.699}
  231.        
  232.         red_spawn_coord[1] = {23.064, -126.660, -15.626}
  233.         red_spawn_coord[2] = {25.562, -125.415, -15.624}
  234.         red_spawn_coord[3] = {28.091, -125.388, -15.624}
  235.         red_spawn_coord[4] = {30.670, -126.631, -15.626}
  236.         red_spawn_coord[5] = {21.893, -123.528, -15.632}
  237.         red_spawn_coord[6] = {23.724, -124.808, -15.628}
  238.         red_spawn_coord[7] = {29.853, -124.809, -15.628}
  239.         red_spawn_coord[8] = {31.707, -123.409, -15.632}
  240.        
  241.         blu_spawn_coord[1] = {23.085, -17.469, -15.626}
  242.         blu_spawn_coord[2] = {25.546, -18.771, -15.624}
  243.         blu_spawn_coord[3] = {28.144, -18.726, -15.624}
  244.         blu_spawn_coord[4] = {30.708, -17.435, -15.626}
  245.         blu_spawn_coord[5] = {21.866, -20.804, -15.632}
  246.         blu_spawn_coord[6] = {25.564, -21.533, -15.632}
  247.         blu_spawn_coord[7] = {28.048, -21.506, -15.632}
  248.         blu_spawn_coord[8] = {31.697, -20.837, -15.631}
  249.  
  250.     elseif map_name == "infinity" then
  251.         red_rotation[1] = {0.676, -164.567, 15.049}
  252.         blue_rotation[1] = {0.676, -164.567, 15.049}
  253.        
  254.         red_spawn_coord[1] = {-4.009, -141.548, 13.948}
  255.         red_spawn_coord[2] = {-6.345, -138.274, 12.774}
  256.         red_spawn_coord[3] = {-9.914, -139.481, 12.981}
  257.         red_spawn_coord[4] = {-13.352, -137.575, 13.256}
  258.         red_spawn_coord[5] = {-11.814, -135.970, 13.288}
  259.         red_spawn_coord[6] = {-9.080, -134.124, 12.868}
  260.         red_spawn_coord[7] = {-6.184, -134.323, 12.745}
  261.         red_spawn_coord[8] = {-8.609, -137.069, 12.865}
  262.        
  263.         blu_spawn_coord[1] = {15.132, -140.947, 12.237}
  264.         blu_spawn_coord[2] = {7.642, -140.089, 12.666}
  265.         blu_spawn_coord[3] = {5.193, -142.325, 13.779}
  266.         blu_spawn_coord[4] = {13.618, -138.929, 11.898}
  267.         blu_spawn_coord[5] = {16.507, -132.527, 14.684}
  268.         blu_spawn_coord[6] = {14.987, -136.355, 12.257}
  269.         blu_spawn_coord[7] = {9.523, -135.474, 12.582}
  270.         blu_spawn_coord[8] = {6.412, -133.836, 12.622}
  271.        
  272.     elseif map_name == "icefields" then
  273.         red_rotation[1] = {19.573, -2.920, 0.791}
  274.         blue_rotation[1] = {-72.611, 67.428, 0.781}
  275.        
  276.         red_spawn_coord[1] = {33.716, -30.292, 0.814}
  277.         red_spawn_coord[2] = {28.352, -33.786, 1.779}
  278.         red_spawn_coord[3] = {21.291, -33.896, 1.742}
  279.         red_spawn_coord[4] = {18.527, -33.562, 0.919}
  280.         red_spawn_coord[5] = {36.429, -26.407, 0.852}
  281.         red_spawn_coord[6] = {13.779, -25.712, 0.865}
  282.         red_spawn_coord[7] = {14.735, -26.288, 0.755}
  283.         red_spawn_coord[8] = {34.516, -25.876, 0.787}
  284.        
  285.         blu_spawn_coord[1] = {-84.048, 97.797, 1.206}
  286.         blu_spawn_coord[2] = {-81.324, 98.501, 1.873}
  287.         blu_spawn_coord[3] = {-74.521, 98.328, 1.805}
  288.         blu_spawn_coord[4] = {-71.704, 97.779, 0.874}
  289.         blu_spawn_coord[5] = {-67.641, 91.366, 0.786}
  290.         blu_spawn_coord[6] = {-87.249, 91.701, 0.730}
  291.         blu_spawn_coord[7] = {-67.949, 90.537, 0.749}
  292.         blu_spawn_coord[8] = {-86.628, 90.800, 0.746}
  293.        
  294.     elseif map_name == "sidewinder" then
  295.         red_rotation[1] = {2.708, 55.001, -2.791}
  296.         blue_rotation[1] = {2.708, 55.001, -2.791}
  297.        
  298.         red_spawn_coord[1] = {-28.435, -29.414, -3.84}
  299.         red_spawn_coord[2] = {-30.924, -28.509, -3.841}
  300.         red_spawn_coord[3] = {-33.996, -28.264, -3.835}
  301.         red_spawn_coord[4] = {-36.305, -28.492, -3.744}
  302.         red_spawn_coord[5] = {-41.707, -28.023, -3.745}
  303.         red_spawn_coord[6] = {-35.948, -24.355, -3.607}
  304.         red_spawn_coord[7] = {-27.586, -27.538, -3.841}
  305.         red_spawn_coord[8] = {-23.380, -28.505, -3.841}
  306.        
  307.         blu_spawn_coord[1] = {33.463, -33.008, -3.841}
  308.         blu_spawn_coord[2] = {31.670, -32.148, -3.815}
  309.         blu_spawn_coord[3] = {29.094, -32.326, -3.803}
  310.         blu_spawn_coord[4] = {27.602, -32.158, -3.776}
  311.         blu_spawn_coord[5] = {38.559, -30.418, -3.839}
  312.         blu_spawn_coord[6] = {34.422, -27.695, -3.648}
  313.         blu_spawn_coord[7] = {26.203, -27.890, -3.658}
  314.         blu_spawn_coord[8] = {21.464, -30.625, -3.841}
  315.        
  316.     elseif map_name == "timberland" then
  317.         red_rotation[1] = {16.607, -31.762, -15.401}
  318.         blue_rotation[1] = {-15.884, 31.805, -15.291}
  319.    
  320.         red_spawn_coord[1] = {24.903, -49.360, -17.249}
  321.         red_spawn_coord[2] = {23.912, -45.946, -17.514}
  322.         red_spawn_coord[3] = {20.483, -48.143, -17.734}
  323.         red_spawn_coord[4] = {20.946, -50.218, -17.584}
  324.         red_spawn_coord[5] = {18.867, -45.628, -18.047}
  325.         red_spawn_coord[6] = {15.356, -45.680, -17.951}
  326.         red_spawn_coord[7] = {13.913, -48.065, -17.71}
  327.         red_spawn_coord[8] = {10.964, -48.303, -17.250}
  328.        
  329.         blu_spawn_coord[1] = {-23.846, 50.052, -17.228}
  330.         blu_spawn_coord[2] = {-19.738, 48.242, -17.692}
  331.         blu_spawn_coord[3] = {-17.530, 46.434, -17.954}
  332.         blu_spawn_coord[4] = {-15.200, 46.523, -17.872}
  333.         blu_spawn_coord[5] = {-13.178, 48.048, -17.714}
  334.         blu_spawn_coord[6] = {-7.965, 47.485, -17.085}
  335.         blu_spawn_coord[7] = {-12.055, 49.968, -17.395}
  336.         blu_spawn_coord[8] = {-20.413, 50.131, -17.395}
  337.  
  338.     -- add your map name here, with a) map name, b) RED rotation c) BLUE rotation d) RED player spawn coordinates e) BLUE player spawn coordinates
  339.     -- remove the "--" below (in front of 'elseif') and add your map name, and replace 0,0,0 with your custom coordinates
  340.    
  341.     -- elseif map_name == "YOUR_MAP_NAME" then
  342.         --red_spawn_coord[1] = {0,0,0}
  343.         --red_spawn_coord[2] = {0,0,0}
  344.         --red_spawn_coord[3] = {0,0,0}
  345.         --red_spawn_coord[4] = {0,0,0}
  346.         --red_spawn_coord[5] = {0,0,0}
  347.         --red_spawn_coord[6] = {0,0,0}
  348.         --red_spawn_coord[7] = {0,0,0}
  349.         --red_spawn_coord[8] = {0,0,0}
  350.        
  351.         --blu_spawn_coord[1] = {0,0,0}
  352.         --blu_spawn_coord[2] = {0,0,0}
  353.         --blu_spawn_coord[3] = {0,0,0}
  354.         --blu_spawn_coord[4] = {0,0,0}
  355.         --blu_spawn_coord[5] = {0,0,0}
  356.         --blu_spawn_coord[6] = {0,0,0}
  357.         --blu_spawn_coord[7] = {0,0,0}
  358.         --blu_spawn_coord[8] = {0,0,0} 
  359.        
  360.     end
  361. end
  362.  
  363. function getteamplay()
  364.    if (get_var(0, "$ffa") == "0") then
  365.        return true
  366.    else
  367.        return false
  368.    end
  369. end
  370.  
  371. function GetPlayerCoords(PlayerIndex)
  372.     local player_object = get_dynamic_player(PlayerIndex)
  373.     if (player_object ~= 0) then
  374.         local x,y,z = read_vector3d(get_dynamic_player(PlayerIndex) + 0x5C)
  375.         local vehicle_objectid = read_dword(player_object + 0x11C)
  376.         local vehicle_object = get_object_memory(vehicle_objectid)
  377.         if(vehicle_object ~= 0 and vehicle_object ~= nil) then
  378.             local vx,vy,vz = read_vector3d(vehicle_object + 0x5C)
  379.             x = x + vx
  380.             y = y + vy
  381.             z = z + vz
  382.         end
  383.         return math.round(x, 2),math.round(y, 2),math.round(z, 2)
  384.     end
  385.     return nil 
  386. end
  387.  
  388. function math.round(num, idp)
  389.   return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  390. end
  391.  
  392. function OnError(Message)
  393.     print(debug.traceback())
  394. end
  395.  
  396. -- Created by H® Shaft
  397. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement