• Teleporting Players
    6 replies, posted
How would I teleport a player in glua? all I could think of is [code] ply:SetPos(Vector(5262.6, 6252.5, 62616.2)) << Not real made up! [/code] My script is: [code] DermaButton.DoClick = function ( ply ) newpos = ("-2721.942627, -1785.375122, -139.968750") ply = LocalPlayer() ply:SetPos(Vector( newpos )) end [/code] I obviously have changed it to have no newpos var and just put the position inside the SetPos but that didn't work either! There is no errors in my code and have no clue why its not working. Please help
So you are trying to teleport player clientside? Lol. You should really learn difference between serverside functions and clientside functions, because you are basically trying to teleport player without having such powers (ergo, you are not a server). Errors do not appear because you are testing it on singleplayer, try testing it on SRCDS or multiplayer. In other words, Entity:SetPos() is a serverside function and cannot be used clientside (unless it's something like a CLuaEmitter ofc), so do not run it in stuff like derma menus.
[QUOTE=Netheous;43334233]So you are trying to teleport player clientside? Lol. You should really learn difference between serverside functions and clientside functions, because you are basically trying to teleport player without having such powers (ergo, you are not a server). Errors do not appear because you are testing it on singleplayer, try testing it on SRCDS or multiplayer. In other words, Entity:SetPos() is a serverside function and cannot be used clientside (unless it's something like a CLuaEmitter ofc), so do not run it in stuff like derma menus.[/QUOTE] This is in multiplayer, 2. Thanks for saying that its server side but how would I put a button from clientside to server? So I put a usermessage hook? or what?
[QUOTE=PabloSky11400;43334251]This is in multiplayer, 2. Thanks for saying that its server side but how would I put a button from clientside to server? So I put a usermessage hook? or what?[/QUOTE] I would suggest using net library. Usermessages are net's predecessor.
Sorry, I'm on phone but client-side [LUA] net.Start ( "MyCoolMessage" ) net.SendToServer () [/LUA] server-side [LUA] util.AddNetworkString ( "MyCoolMessage" ) net.Receive ( "MyCoolMessage", function ( messageLength, ply ) print( "message received, sent by " .. ply:Nick() ) --set their pos and such end ) [/LUA]
Getting this error [code] Warning: Unhandled usermessage 'VendorOpen' [/code] This is my full code I have done: ServerSide: [code] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( 'shared.lua' ) local SPAWN_POS = Vector(-2410.784424, -598.148560, -131.968750) local SPAWN_ANG = Angle(0, 180, 0) local function SpawnNPC() timer.Simple(5,function() local npc = ents.Create("ammo_vendor") npc:SetPos(SPAWN_POS) npc:SetAngles(SPAWN_ANG) npc:Spawn() end) end hook.Add("InitPostEntity","SpawnVendorNPC", SpawnNPC) function ENT:Initialize( ) self:SetModel( "models/props_interiors/VendingMachineSoda01a.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetUseType( SIMPLE_USE ) self:SetHullSizeNormal( ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE || CAP_USE_SHOT_REGULATOR || CAP_TURN_HEAD || CAP_AIM_GUN ) self:SetMaxYawSpeed( 5000 ) local PhysAwake = self.Entity:GetPhysicsObject( ) if PhysAwake:IsValid( ) then PhysAwake:Wake( ) end end function ENT:OnTakeDamage( dmg ) return false end function ENT:AcceptInput( name, activator, caller ) if ( name == "Use" && IsValid( activator ) && activator:IsPlayer( ) ) then umsg.Start("VendorOpen",activator) umsg.End() end end util.AddNetworkString ( "Teleport" ) net.Receive ( "Teleport", function ( messageLength, ply ) print( "message received, sent by " .. ply:Nick() ) newpos = ("-2721.942627, -1785.375122, -139.968750") ply = LocalPlayer() ply:SetPos(Vector( newpos )) end ) [/code] ClientSide: [code] include( 'shared.lua' ) function OpenMenu( ply ) local base = vgui.Create( "DFrame" ) base:SetPos( 80,50 ) base:SetSize( 600, 400 ) base:SetTitle( "Ammo Vendor Created By - PabloSky11400" ) base:SetVisible( true ) base:SetDraggable( true ) function base:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 255, 100 ) ) surface.SetDrawColor( Color(0,150,255,255) ) surface.DrawRect( 0, 0, self:GetWide(), self:GetTall() ) surface.SetDrawColor( Color(0,0,0,255) ) surface.DrawRect( 2, 2, self:GetWide()-4, self:GetTall()-4 ) end base:ShowCloseButton( true ) // Buttons local DermaButton = vgui.Create( "DButton" ) DermaButton:SetParent( base ) -- Set parent to our "DermaPanel" DermaButton:SetText( "Change RP Name" ) DermaButton:SetPos( 10, 30 ) DermaButton:SetSize( 880, 20 ) function DermaButton:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 255, 100 ) ) surface.SetDrawColor( Color(0,150,255,255) ) surface.DrawRect( 0, 0, self:GetWide(), self:GetTall() ) surface.SetDrawColor( Color(0,0,0,255) ) surface.DrawRect( 2, 2, self:GetWide()-4, self:GetTall()-4 ) end DermaButton.OnCursorEntered = function () surface.PlaySound( "ui/buttonrollover.wav" ) function DermaButton:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 255, 255 ) ) surface.SetDrawColor( Color(0,150,255,255) ) surface.DrawRect( 0, 0, self:GetWide(), self:GetTall() ) surface.SetDrawColor( Color(0,0,255,255) ) surface.DrawRect( 2, 2, self:GetWide()-4, self:GetTall()-4 ) end end DermaButton.OnCursorExited = function () function DermaButton:Paint( w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 255, 255 ) ) surface.SetDrawColor( Color(0,150,255,255) ) surface.DrawRect( 0, 0, self:GetWide(), self:GetTall() ) surface.SetDrawColor( Color(0,0,0,255) ) surface.DrawRect( 2, 2, self:GetWide()-4, self:GetTall()-4 ) end end DermaButton.DoClick = function ( ply ) net.Start ( "Teleport" ) net.SendToServer () end end usermessage.Hook("VendorOpen",OpenMenu) [/code] [editline]28th December 2013[/editline] I know my script is messy and not polished or anything but don't shout at me please:P! Im new to this!
That's because you are using usermessage to open the menu and appearently you removed it from serverside code.
Sorry, you need to Log In to post a reply to this thread.