Created
May 16, 2020 02:13
-
-
Save fusspawn/01f903a87bb5defff12abea5635f0d65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dofile "$SURVIVAL_DATA/Scripts/game/SurvivalPlayer.lua" | |
WaypointManager = class(nil) | |
WaypointManager.init = function(self) | |
self:load_from_database() | |
end | |
WaypointManager.create_waypoint = function(self, name, x,y,z, r,g,b, player) | |
if not self.waypoints_data then | |
self.waypoints_data = {} | |
self:save_to_database() | |
end | |
table.insert(self.waypoints_data, {name=name, x=x, y=y, z=z, r=r, g=g, b=b, world=player.character:getWorld()}) | |
self:save_to_database() | |
for k,v in pairs(sm.player.getAllPlayers()) do | |
self:send_to_player(v, {name=name, x=x, y=y, z=z, r=r, g=g, b=b, world=player.character:getWorld()}) | |
end | |
end | |
WaypointManager.send_to_player = function(self, player, waypoint) | |
if waypoint == nil then | |
print("tried to send a nil wp wtf") | |
return | |
end | |
sm.event.sendToPlayer(player, "sv_addWaypointMarkerGUI", waypoint) | |
end | |
WaypointManager.sync_to_player = function(self, player) | |
if not sm.isServer then | |
return | |
end | |
if not self.waypoints_data then | |
self:load_from_database() | |
end | |
for k, v in pairs(self.waypoints_data) do | |
self:send_to_player(player, v) | |
end | |
end | |
WaypointManager.save_to_database = function(self) | |
if not sm.isServer then | |
return | |
end | |
print("saving waypoints") | |
sm.storage.save("waypoints", self.waypoints_data) | |
end | |
WaypointManager.load_from_database = function(self) | |
if not sm.isServer then | |
return | |
end | |
self.waypoints_data = sm.storage.load("waypoints") | |
if not self.waypoints_data then | |
print("no previous waypoints found") | |
self.waypoints_data = {} | |
self:save_to_database() | |
end | |
end | |
WaypointManager.create_client_graphics = function(self, params) | |
self:cl_on_create_waypoint_graphics(params) | |
end | |
WaypointManager.cl_on_create_waypoint_graphics = function(self, params) | |
if not self.stored_gui then | |
self.stored_gui = {} | |
end | |
local guiBag = {shape=params.name, position= sm.vec3.new( params.x, params.y, params.z)} | |
local gui = sm.gui.createNameTagGui() | |
gui:setWorldPosition( guiBag.position + sm.vec3.new( 0, 0, 0.5 ) ) | |
gui:setRequireLineOfSight( false ) | |
gui:open() | |
gui:setMaxRenderDistance( 100000 ) | |
gui:setText( "Text", rgbToHex({r= params.r, g=params.g, b=params.b}) .. params.name ) | |
g_respawnManager:cl_markBag(guiBag) | |
table.insert(self.stored_gui, {tag=gui, name=params.name}) | |
end | |
local SurivalPlayerOnCreateOriginalServer = SurvivalPlayer.server_onCreate | |
SurvivalPlayer.server_onCreate = function(self, ...) | |
SurivalPlayerOnCreateOriginalServer(self, ...) | |
g_WaypointManager:sync_to_player(self) | |
end | |
SurvivalPlayer.sv_addWaypointMarkerGUI = function(self, params) | |
self.network:sendToClients("cl_addWaypointMarkerGUI", params) | |
end | |
SurvivalPlayer.cl_addWaypointMarkerGUI = function(self, params) | |
print("[Waypoints] received cl_addWaypointMarkerGUI param count: " .. tostring(#params)) | |
g_WaypointManager:create_client_graphics(params) | |
end | |
function rgbToHex(rgb) | |
local hexadecimal = '#' | |
for key, value in pairs(rgb) do | |
local hex = '' | |
while(value > 0)do | |
local index = math.fmod(value, 16) + 1 | |
value = math.floor(value / 16) | |
hex = string.sub('0123456789ABCDEF', index, index) .. hex | |
end | |
if(string.len(hex) == 0)then | |
hex = '00' | |
elseif(string.len(hex) == 1)then | |
hex = '0' .. hex | |
end | |
hexadecimal = hexadecimal .. hex | |
end | |
return hexadecimal | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment