Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Custom Team Spawns by H® Shaft for SAPP
- -- All players spawn at their own base or custom locations you setup for red and blue teams.
- -- 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)
- -- Initially designed for Team Race (on the maps listed below) but can be used for other game types
- -- Spawns setup/completed for these maps only: bloodgulch, dangercanyon, deathisland, gephyrophobia, infinity, icefields, sidewinder, timberland
- -- sapp api version
- api_version = "1.9.0.0"
- team_play = false
- loop_end = 8
- function OnScriptLoad()
- register_callback(cb['EVENT_GAME_START'], "OnNewGame")
- register_callback(cb['EVENT_PRESPAWN'], "OnPlayerPrespawn")
- register_callback(cb['EVENT_CHAT'], "OnPlayerChat")
- if get_var(0, "$gt") ~= "n/a" then
- map_name = get_var(0,"$map")
- team_play = getteamplay()
- Load_Tables()
- end
- end
- function OnNewGame()
- map_name = get_var(0,"$map")
- team_play = getteamplay()
- Load_Tables()
- end
- function OnPlayerChat(PlayerIndex, Message)
- local response = nil
- local Message = string.lower(Message)
- local isadmin = nil
- if (tonumber(get_var(PlayerIndex,"$lvl"))) > 0 then
- isadmin = true
- else
- isadmin = false
- end
- -- | type "coord" to retrieve your coordinates x,y,z and rotation (rotation is yaw = the direction you are facing, not the same as "aim")
- -- | records map name and coordinates entries into log: map name, x,y,z,r
- if (Message == "coord") then
- if isadmin == true then
- local player_static = get_player(PlayerIndex)
- local x,y,z = GetPlayerCoords(PlayerIndex)
- local rotation = read_float(player_static + 0x138)
- local map_name = get_var(0,"$map")
- local data = string.format("%s, %s, %s, %s, %s", tostring(map_name),tostring(x),tostring(y),tostring(z),tostring(math.round(rotation, 2)))
- execute_command("log_note \""..data.."\"")
- say(PlayerIndex, "X: " .. x .. " Y: " .. y .. " Z: " .. z .. " R: " .. math.round(rotation, 2))
- response = false
- else
- response = true
- end
- end
- return response
- end
- function OnPlayerPrespawn(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- if (player_object ~= 0) then
- if team_play then
- local team = get_var(PlayerIndex, "$team")
- if team == "red" then
- local redcoord = SelectRedSpawnCoord()
- if redcoord then
- write_vector3d(player_object + 0x5C, red_spawn_coord[redcoord][1], red_spawn_coord[redcoord][2], red_spawn_coord[redcoord][3])
- write_dword(get_player(PlayerIndex) + 0xF0, 0) -- sync instantly to the player
- write_dword(get_player(PlayerIndex) + 0x164, 0) -- sync instantly to others
- local fx, fy, fz = red_rotation[1][1],red_rotation[1][2],red_rotation[1][3]
- local px, py, pz = GetPlayerCoords(PlayerIndex)
- local vx = fx - px
- local vy = fy - py
- local vz = fz - pz
- -- normalize it
- local magnitude = math.sqrt(vx*vx + vy*vy + vz*vz)
- vx = vx / magnitude
- vy = vy / magnitude
- vz = vz / magnitude
- write_float(player_object + 0x74, vx)
- write_float(player_object + 0x78, vy)
- write_float(player_object + 0x7c, vz)
- end
- elseif team == "blue" then
- local blucoord = SelectBluSpawnCoord()
- if blucoord then
- write_vector3d(player_object + 0x5C, blu_spawn_coord[blucoord][1], blu_spawn_coord[blucoord][2], blu_spawn_coord[blucoord][3])
- write_dword(get_player(PlayerIndex) + 0xF0, 0) -- sync instantly to the player
- write_dword(get_player(PlayerIndex) + 0x164, 0) -- sync instantly to others
- local fx, fy, fz = blue_rotation[1][1],blue_rotation[1][2],blue_rotation[1][3]
- local px, py, pz = GetPlayerCoords(PlayerIndex) --read_vector3d(player_object + 0x5C)
- local vx = fx - px
- local vy = fy - py
- local vz = fz - pz
- -- normalize it
- local magnitude = math.sqrt(vx*vx + vy*vy + vz*vz)
- vx = vx / magnitude
- vy = vy / magnitude
- vz = vz / magnitude
- write_float(player_object + 0x74, vx)
- write_float(player_object + 0x78, vy)
- write_float(player_object + 0x7c, vz)
- end
- end
- end
- end
- end
- function SelectRedSpawnCoord()
- if #red_spawn_coord > 0 then
- local index = rand(1, #red_spawn_coord+1)
- local coord = red_spawn_coord[index]
- if (CheckForDuplicateSpawn(coord) == false) then
- return index
- end
- end
- return nil
- end
- function SelectBluSpawnCoord()
- if #blu_spawn_coord > 0 then
- local index = rand(1, #blu_spawn_coord+1)
- local coord = blu_spawn_coord[index]
- if (CheckForDuplicateSpawn(coord) == false) then
- return index
- end
- end
- return nil
- end
- -- written by 002:
- function CheckForDuplicateSpawn(coord)
- for i=1,loop_end do
- local dyn_player = get_dynamic_player(i)
- if(dyn_player ~= 0) then
- local px,py,pz = GetPlayerCoords(i)
- local distance = DistanceFormula(coord[1],coord[2],coord[3],px,py,pz)
- if(distance < 1) then
- return true
- end
- end
- end
- return false
- end
- -- written by 002:
- function DistanceFormula(x1,y1,z1,x2,y2,z2)
- return math.sqrt(math.pow(x1 - x2,2) + math.pow(y1 - y2,2) + math.pow(z1 - z2,2))
- end
- function Load_Tables()
- red_spawn_coord = {}
- blu_spawn_coord = {}
- red_rotation = {}
- blue_rotation = {}
- if map_name == "bloodgulch" then
- red_rotation[1] = {60.987, -121.606, 0.274} -- direction a red player faces relative to this x,y,z coordinate
- blue_rotation[1] = {60.987, -121.606, 0.274} -- direction a blue player faces relative to this x,y,z coordinate
- -- player spawns by team - for best results, have a MINIMUM of 8 per team, more is better
- -- 8 red player spawns
- red_spawn_coord[1] = {68.911, -173.686, 1.815}
- red_spawn_coord[2] = {74.323, -173.370, 0.817}
- red_spawn_coord[3] = {79.380, -173.402, 0.410}
- red_spawn_coord[4] = {84.011, -173.499, 0.307}
- red_spawn_coord[5] = {89.487, -173.463, 0.344}
- red_spawn_coord[6] = {95.069, -173.863, 0.718}
- red_spawn_coord[7] = {100.525, -174.038, 0.813}
- red_spawn_coord[8] = {105.292, -173.656, 0.229}
- -- 8 blue player spawns
- blu_spawn_coord[1] = {61.292, -65.713, 1.693}
- blu_spawn_coord[2] = {57.520, -65.796, 1.233}
- blu_spawn_coord[3] = {53.473, -66.050, 0.927}
- blu_spawn_coord[4] = {49.578, -66.108, 0.848}
- blu_spawn_coord[5] = {32.593, -65.859, 0.447}
- blu_spawn_coord[6] = {29.079, -65.796, 0.793}
- blu_spawn_coord[7] = {26.038, -65.906, 1.243}
- blu_spawn_coord[8] = {23.010, -65.879, 1.813}
- elseif map_name == "dangercanyon" then
- red_rotation[1] = {-37.219, 0.058, -2.172}
- blue_rotation[1] = {37.756, 0.404, -2.172}
- red_spawn_coord[1] = {-16.254, -1.222, -4.030}
- red_spawn_coord[2] = {-16.235, -5.483, -4.030}
- red_spawn_coord[3] = {-15.767, 2.010, -4.000}
- red_spawn_coord[4] = {-14.096, -7.125, -4.000}
- red_spawn_coord[5] = {-6.198, -0.202, -4.028}
- red_spawn_coord[6] = {-8.746, -7.146, -4.025}
- red_spawn_coord[7] = {-3.195, -6.566, -4.022}
- red_spawn_coord[8] = {-3.244, -1.144, -4.028}
- blu_spawn_coord[1] = {16.140, -1.544, -4.030}
- blu_spawn_coord[2] = {16.068, -5.484, -4.030}
- blu_spawn_coord[3] = {15.730, 1.627, -3.990}
- blu_spawn_coord[4] = {13.715, -7.029, -3.990}
- blu_spawn_coord[5] = {3.785, -1.194, -4.028}
- blu_spawn_coord[6] = {3.375, -6.669, -4.022}
- blu_spawn_coord[7] = {5.585, -1.158, -3.998}
- blu_spawn_coord[8] = {8.429, -6.587, -4.025}
- elseif map_name == "deathisland" then
- red_rotation[1] = {-61.327, -9.832, 1.843}
- blue_rotation[1] = {55.415, 13.656, 1.775}
- red_spawn_coord[1] = {-36.889, -4.007, 9.417}
- red_spawn_coord[2] = {-36.853, -9.937, 9.417}
- red_spawn_coord[3] = {-38.445, -2.989, 5.744}
- red_spawn_coord[4] = {-37.452, -11.724, 5.056}
- red_spawn_coord[5] = {-39.155, -5.780, 5.225}
- red_spawn_coord[6] = {-39.095, -8.268, 5.064}
- red_spawn_coord[7] = {-41.475, -5.493, 4.936}
- red_spawn_coord[8] = {-41.673, -8.819, 4.706}
- blu_spawn_coord[1] = {40.430, 13.260, 8.050}
- blu_spawn_coord[2] = {40.381, 18.714, 8.050}
- blu_spawn_coord[3] = {40.268, 11.340, 4.605}
- blu_spawn_coord[4] = {40.245, 20.333, 4.498}
- blu_spawn_coord[5] = {42.548, 15.075, 4.772}
- blu_spawn_coord[6] = {42.434, 17.335, 4.657}
- blu_spawn_coord[7] = {44.715, 15.356, 4.298}
- blu_spawn_coord[8] = {44.632, 17.430, 4.509}
- elseif map_name == "gephyrophobia" then
- red_rotation[1] = {26.831, -72.683, -10.699}
- blue_rotation[1] = {26.831, -72.683, -10.699}
- red_spawn_coord[1] = {23.064, -126.660, -15.626}
- red_spawn_coord[2] = {25.562, -125.415, -15.624}
- red_spawn_coord[3] = {28.091, -125.388, -15.624}
- red_spawn_coord[4] = {30.670, -126.631, -15.626}
- red_spawn_coord[5] = {21.893, -123.528, -15.632}
- red_spawn_coord[6] = {23.724, -124.808, -15.628}
- red_spawn_coord[7] = {29.853, -124.809, -15.628}
- red_spawn_coord[8] = {31.707, -123.409, -15.632}
- blu_spawn_coord[1] = {23.085, -17.469, -15.626}
- blu_spawn_coord[2] = {25.546, -18.771, -15.624}
- blu_spawn_coord[3] = {28.144, -18.726, -15.624}
- blu_spawn_coord[4] = {30.708, -17.435, -15.626}
- blu_spawn_coord[5] = {21.866, -20.804, -15.632}
- blu_spawn_coord[6] = {25.564, -21.533, -15.632}
- blu_spawn_coord[7] = {28.048, -21.506, -15.632}
- blu_spawn_coord[8] = {31.697, -20.837, -15.631}
- elseif map_name == "infinity" then
- red_rotation[1] = {0.676, -164.567, 15.049}
- blue_rotation[1] = {0.676, -164.567, 15.049}
- red_spawn_coord[1] = {-4.009, -141.548, 13.948}
- red_spawn_coord[2] = {-6.345, -138.274, 12.774}
- red_spawn_coord[3] = {-9.914, -139.481, 12.981}
- red_spawn_coord[4] = {-13.352, -137.575, 13.256}
- red_spawn_coord[5] = {-11.814, -135.970, 13.288}
- red_spawn_coord[6] = {-9.080, -134.124, 12.868}
- red_spawn_coord[7] = {-6.184, -134.323, 12.745}
- red_spawn_coord[8] = {-8.609, -137.069, 12.865}
- blu_spawn_coord[1] = {15.132, -140.947, 12.237}
- blu_spawn_coord[2] = {7.642, -140.089, 12.666}
- blu_spawn_coord[3] = {5.193, -142.325, 13.779}
- blu_spawn_coord[4] = {13.618, -138.929, 11.898}
- blu_spawn_coord[5] = {16.507, -132.527, 14.684}
- blu_spawn_coord[6] = {14.987, -136.355, 12.257}
- blu_spawn_coord[7] = {9.523, -135.474, 12.582}
- blu_spawn_coord[8] = {6.412, -133.836, 12.622}
- elseif map_name == "icefields" then
- red_rotation[1] = {19.573, -2.920, 0.791}
- blue_rotation[1] = {-72.611, 67.428, 0.781}
- red_spawn_coord[1] = {33.716, -30.292, 0.814}
- red_spawn_coord[2] = {28.352, -33.786, 1.779}
- red_spawn_coord[3] = {21.291, -33.896, 1.742}
- red_spawn_coord[4] = {18.527, -33.562, 0.919}
- red_spawn_coord[5] = {36.429, -26.407, 0.852}
- red_spawn_coord[6] = {13.779, -25.712, 0.865}
- red_spawn_coord[7] = {14.735, -26.288, 0.755}
- red_spawn_coord[8] = {34.516, -25.876, 0.787}
- blu_spawn_coord[1] = {-84.048, 97.797, 1.206}
- blu_spawn_coord[2] = {-81.324, 98.501, 1.873}
- blu_spawn_coord[3] = {-74.521, 98.328, 1.805}
- blu_spawn_coord[4] = {-71.704, 97.779, 0.874}
- blu_spawn_coord[5] = {-67.641, 91.366, 0.786}
- blu_spawn_coord[6] = {-87.249, 91.701, 0.730}
- blu_spawn_coord[7] = {-67.949, 90.537, 0.749}
- blu_spawn_coord[8] = {-86.628, 90.800, 0.746}
- elseif map_name == "sidewinder" then
- red_rotation[1] = {2.708, 55.001, -2.791}
- blue_rotation[1] = {2.708, 55.001, -2.791}
- red_spawn_coord[1] = {-28.435, -29.414, -3.84}
- red_spawn_coord[2] = {-30.924, -28.509, -3.841}
- red_spawn_coord[3] = {-33.996, -28.264, -3.835}
- red_spawn_coord[4] = {-36.305, -28.492, -3.744}
- red_spawn_coord[5] = {-41.707, -28.023, -3.745}
- red_spawn_coord[6] = {-35.948, -24.355, -3.607}
- red_spawn_coord[7] = {-27.586, -27.538, -3.841}
- red_spawn_coord[8] = {-23.380, -28.505, -3.841}
- blu_spawn_coord[1] = {33.463, -33.008, -3.841}
- blu_spawn_coord[2] = {31.670, -32.148, -3.815}
- blu_spawn_coord[3] = {29.094, -32.326, -3.803}
- blu_spawn_coord[4] = {27.602, -32.158, -3.776}
- blu_spawn_coord[5] = {38.559, -30.418, -3.839}
- blu_spawn_coord[6] = {34.422, -27.695, -3.648}
- blu_spawn_coord[7] = {26.203, -27.890, -3.658}
- blu_spawn_coord[8] = {21.464, -30.625, -3.841}
- elseif map_name == "timberland" then
- red_rotation[1] = {16.607, -31.762, -15.401}
- blue_rotation[1] = {-15.884, 31.805, -15.291}
- red_spawn_coord[1] = {24.903, -49.360, -17.249}
- red_spawn_coord[2] = {23.912, -45.946, -17.514}
- red_spawn_coord[3] = {20.483, -48.143, -17.734}
- red_spawn_coord[4] = {20.946, -50.218, -17.584}
- red_spawn_coord[5] = {18.867, -45.628, -18.047}
- red_spawn_coord[6] = {15.356, -45.680, -17.951}
- red_spawn_coord[7] = {13.913, -48.065, -17.71}
- red_spawn_coord[8] = {10.964, -48.303, -17.250}
- blu_spawn_coord[1] = {-23.846, 50.052, -17.228}
- blu_spawn_coord[2] = {-19.738, 48.242, -17.692}
- blu_spawn_coord[3] = {-17.530, 46.434, -17.954}
- blu_spawn_coord[4] = {-15.200, 46.523, -17.872}
- blu_spawn_coord[5] = {-13.178, 48.048, -17.714}
- blu_spawn_coord[6] = {-7.965, 47.485, -17.085}
- blu_spawn_coord[7] = {-12.055, 49.968, -17.395}
- blu_spawn_coord[8] = {-20.413, 50.131, -17.395}
- -- 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
- -- remove the "--" below (in front of 'elseif') and add your map name, and replace 0,0,0 with your custom coordinates
- -- elseif map_name == "YOUR_MAP_NAME" then
- --red_spawn_coord[1] = {0,0,0}
- --red_spawn_coord[2] = {0,0,0}
- --red_spawn_coord[3] = {0,0,0}
- --red_spawn_coord[4] = {0,0,0}
- --red_spawn_coord[5] = {0,0,0}
- --red_spawn_coord[6] = {0,0,0}
- --red_spawn_coord[7] = {0,0,0}
- --red_spawn_coord[8] = {0,0,0}
- --blu_spawn_coord[1] = {0,0,0}
- --blu_spawn_coord[2] = {0,0,0}
- --blu_spawn_coord[3] = {0,0,0}
- --blu_spawn_coord[4] = {0,0,0}
- --blu_spawn_coord[5] = {0,0,0}
- --blu_spawn_coord[6] = {0,0,0}
- --blu_spawn_coord[7] = {0,0,0}
- --blu_spawn_coord[8] = {0,0,0}
- end
- end
- function getteamplay()
- if (get_var(0, "$ffa") == "0") then
- return true
- else
- return false
- end
- end
- function GetPlayerCoords(PlayerIndex)
- local player_object = get_dynamic_player(PlayerIndex)
- if (player_object ~= 0) then
- local x,y,z = read_vector3d(get_dynamic_player(PlayerIndex) + 0x5C)
- local vehicle_objectid = read_dword(player_object + 0x11C)
- local vehicle_object = get_object_memory(vehicle_objectid)
- if(vehicle_object ~= 0 and vehicle_object ~= nil) then
- local vx,vy,vz = read_vector3d(vehicle_object + 0x5C)
- x = x + vx
- y = y + vy
- z = z + vz
- end
- return math.round(x, 2),math.round(y, 2),math.round(z, 2)
- end
- return nil
- end
- function math.round(num, idp)
- return tonumber(string.format("%." .. (idp or 0) .. "f", num))
- end
- function OnError(Message)
- print(debug.traceback())
- end
- -- Created by H® Shaft
- -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement