Trololarion Posted September 5, 2019 Share Posted September 5, 2019 I need to use my mod on dedicated server, but code dont works, code is here: TheInput=GLOBAL.TheInput TheNet=GLOBAL.TheNet TheFrontEnd=GLOBAL.TheFrontEnd DragObjects={} AddModRPCHandler(modname,"DRAG",function(player,down,entity,mx,mz) if TheNet:GetClientTableForUser(player.userid).admin then if down then local x,y,z=entity.Transform:GetWorldPosition() local offset={x=x-mx,z=z-mz} DragObjects[player.userid]={entity=entity,offset=offset} else DragObjects[player.userid]=nil end end end) AddModRPCHandler(modname,"MOVE",function(player,mx,mz) if TheNet:GetClientTableForUser(player.userid).admin and DragObjects[player.userid]~=nil then local entity=DragObjects[player.userid].entity if not entity:IsValid() then return end local offset=DragObjects[player.userid].offset local x,y,z=entity.Transform:GetWorldPosition() entity.Transform:SetPosition(mx+offset.x,y,mz+offset.z) end end) local function IsHUDScreen() local screen=TheFrontEnd~=nil and TheFrontEnd:GetActiveScreen() or nil return screen and screen.name and type(screen.name) == "string" and screen.name == "HUD" end DragKeyHandler = Class(function(self) self.last_isdown=false self.mousemove_handler_active=false self.handler = TheInput:AddKeyHandler(function() local down=TheInput:IsKeyDown(306) and TheInput:IsKeyDown(308) if not (self.last_isdown and down) and IsHUDScreen() then self.last_isdown=down if down and not self.mousemove_handler_active then local ent=TheInput:GetWorldEntityUnderMouse() if ent~=nil and ent:IsValid() then local pos=TheInput:GetWorldPosition() self.mousemove_handler_active=true SendModRPCToServer(MOD_RPC[modname]["DRAG"],down,ent,pos.x,pos.z) end elseif not down and self.mousemove_handler_active then self.mousemove_handler_active=false SendModRPCToServer(MOD_RPC[modname]["DRAG"],down) end end end) self.mousemove_handler=TheInput:AddMoveHandler(function() if self.mousemove_handler_active then local pos=TheInput:GetWorldPosition() SendModRPCToServer(MOD_RPC[modname]["MOVE"],pos.x,pos.z) end end) end) if TheNet:GetIsServerAdmin() and not TheNet:IsDedicated() then DragKeyHandler() end This code works on server with caves. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now