Created
May 10, 2020 16:46
-
-
Save fusspawn/a41b5ebc1eb4a178b610302fe0363c68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
_WAYPOINTS = {} | |
_WAYPOINTS.stored_waypoints = {} | |
_WAYPOINTS.old_chat_handler = nil | |
_WAYPOINTS.installed = false | |
--[[ | |
"uuid": "869d4736-289a-4952-96cd-8a40117a2d28", | |
"name": "obj_consumable_water", | |
]] | |
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 | |
function INIT_SURVIVALGAME_MODS() | |
sm.game.bindChatCommand( "/addwp", {{ "string", "name", false },{ "string", "r", true },{ "string", "g", true },{ "string", "b", true } }, "cl_onChatCommand", "Add a waypoint [name] <r> <g> <b>") | |
sm.game.bindChatCommand( "/delwp", {{ "string", "name", false } }, "cl_onChatCommand", "Remove a waypoint <name>") | |
_WAYPOINTS.old_chat_handler = SurvivalGame.sv_onChatCommand | |
SurvivalGame.sv_onChatCommand = SERVER_ON_CHAT_COMMAND | |
end | |
function INIT_WORLD_MODS(Overworld) | |
Overworld.cl_worldHandleWp = function(self, params) | |
if params.action == "/addwp" then | |
local guiBag = {shape=params.shape, position=params.position} | |
local gui = sm.gui.createNameTagGui() | |
gui:setWorldPosition( params.position + sm.vec3.new( 0, 0, 0.5 ) ) | |
gui:setRequireLineOfSight( false ) | |
gui:open() | |
gui:setMaxRenderDistance( 100000 ) | |
gui:setText( "Text", rgbToHex(params.colour) .. params.shape ) | |
sm.gui.chatMessage("color: " .. rgbToHex(params.colour)) | |
_WAYPOINTS.stored_waypoints[params.shape] = gui | |
g_respawnManager:cl_markBag(guiBag) | |
elseif params.action == "/delwp" then | |
if _WAYPOINTS.stored_waypoints[params.shape] then | |
_WAYPOINTS.stored_waypoints[params.shape]:close() | |
_WAYPOINTS.stored_waypoints[params.shape]:destroy() | |
end | |
g_respawnManager:cl_unmarkBag({shape=params.shape}) | |
else | |
sm.gui.chatMessage("invalid cl_world_handle_wp: " .. tostring(params.action)) | |
end | |
end | |
Overworld.sv_HandleWPEvent = function(self, params) | |
print( "world handle wp " ); | |
if params[1] == "/addwp" then | |
local player = params[3] | |
local character = player.character | |
local position = character.worldPosition | |
local guiBag = {} | |
local col | |
if #params == 5 then | |
col = params[5] | |
else | |
col = {255,255,255} | |
end | |
self.network:sendToClients("cl_worldHandleWp", {action="/addwp", shape=params[2], position=position, colour=col}) | |
_WAYPOINTS.stored_waypoints[params[2]] = guiBag | |
elseif params[1] == "/delwp" then | |
self.network:sendToClients("cl_worldHandleWp", {action="/delwp", shape=params[2]}) | |
print("invalid param to SERVER_WAYPOINT_EVENT_WORLD" .. tostring(params[1])) | |
end | |
end | |
end | |
function SERVER_ON_CHAT_COMMAND(self, params, player) | |
if params[1] == "/addwp" then | |
local use_color = #params == 5 | |
if use_color then | |
col = {tonumber(params[3]), tonumber(params[4]), tonumber(params[5])} | |
end | |
sm.gui.chatMessage( "waypoint hack" ) | |
sm.gui.chatMessage( params[1] ) | |
sm.gui.chatMessage( params[2] ) | |
params[3] = player | |
params[4] = player.character:getWorld() | |
if use_color then | |
params[5] = col | |
end | |
sm.event.sendToWorld(params[4], "sv_HandleWPEvent", params) | |
elseif params[1] == "/delwp" then | |
sm.gui.chatMessage( "waypoint hack" ) | |
sm.gui.chatMessage( params[1] ) | |
sm.gui.chatMessage( params[2] ) | |
params[3] = player | |
params[4] = player.character:getWorld() | |
sm.event.sendToWorld(params[4], "sv_HandleWPEvent", params) | |
else | |
_WAYPOINTS.old_chat_handler(self, params, player) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment