I have this code to teleport a player:
[lua]function Teleport_x(ply, command, args)
ply:SetPos(Vector(args[1], ply:GetPos().y, ply:GetPos().z))
print(ply:GetPos().x)
local vPoint = ply:GetShootPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetOrigin( vPoint )
effectdata:SetScale( 1000 )
util.Effect( "BloodImret", effectdata )
util.Effect( "cball_explode", effectdata )
util.Effect( "RPGShotDown", effectdata)
end
concommand.Add("Teleport_x", Teleport_x)[/lua]
Now it works if I use it (whilst I am running the server) but as soon as someone else tries to use the command nothing happens, it prints the place where the player should be just fine, as well as showing the effect, but the actual player does not move to that position.
Is there something obvious I am missing?
sure thats it server side?
and why only moving the X?
maybe add more debuging msg's, like put a print before and after when using ply:SetPos()
andddddddd, lissen servers fail in lua testing, try on an dedi instead
since your luacode wil be shared between the server-client becouse your BOTH at lissen
while an dedi is REALY the server, and then your REALY the client
Is that only in the init.lua? or shared.lua? OR cl_init.lua, i get them all a bit confused once in a while when i dont have the code right in front of me :downs:
I have Teleport_x in init.lua and Teleport_y in shared.lua, to see if any of them work. Neither do. :D
also I tried using print statements to see what was going on, and well they say my player is at that position but I am pretty sure it has not moved!!
also thanks for the advice for testing on dedicated servers I shall try that from now on. :)
Theres your problem. Put all the Teleport information in the init.lua, the teleport FUNCTIONS in the cl_init.lua, and the swep information in the shared.lua.
[QUOTE=bromvlieg;18080325]sure thats it server side?
and why only moving the X?
maybe add more debuging msg's, like put a print before and after when using ply:SetPos()
andddddddd, lissen servers fail in lua testing, try on an dedi instead
since your luacode wil be shared between the server-client becouse your BOTH at lissen
while an dedi is REALY the server, and then your REALY the client[/QUOTE]
Everything you after ply:SetPos() is completely wrong.
Agree'd. People need to think before they post :siren:
[QUOTE=Magnificor;18118037]Agree'd. People need to think before they post :siren:[/QUOTE]
And you're saying he should do the teleporting clientside? That makes sense.
[QUOTE=Sippeangelo;18118339]And you're saying he should do the teleporting clientside? That makes sense.[/QUOTE]
If we could teleport clientside, no one would play gmod because of all the stupid 10 second hacks.
[QUOTE=Sippeangelo;18118339]And you're saying he should do the teleporting clientside? That makes sense.[/QUOTE]
Sipp's sarcasm is correct.
[QUOTE=Magnificor]Put all the Teleport information in the init.lua, the teleport FUNCTIONS in the cl_init.lua,[/quote]
Which would mean you were teleporting them in cl_init which is wrong. Teleport functions go in init, not cl_init.
what I am confused by is this:
If I just have this as a console command you call up from the console
[lua]function Teleport_x(ply, command, args)
ply:SetPos(Vector(100, ply:GetPos().y, ply:GetPos().z))
print(ply:GetPos().x)
end
concommand.Add("Teleport_x", Teleport_x) [/lua]
It does not work, when the player enters Teleport_x in the console
but if I use this:
[lua]function GM:KeyPress(p, key)
if ( key == IN_SPEED ) then
p:SetPos(Vector(200, p:GetPos().y, p:GetPos().z))
end
self.BaseClass:KeyPress(p, key)
end[/lua]
It works fine, when the player presses shift, both in init.lua.
Lua sometimes doesn't like it when the name of the concommand and the name of the function that you are calling are the same. Change either the name of the function or the name of the concommand and try again.
Tried both and I am still getting the same problem.. :(
[editline]02:31PM[/editline]
Okay, I think I have fucked up somewhere because I just created a new game mode and used the exact same function and it worked perfectly, I think I shall just start all over again.
There's nothing wrong with your code.
The error is somewhere else.
[QUOTE=Sippeangelo;18165506]There's nothing wrong with your code.
The error is somewhere else.[/QUOTE]
I agree, because doing this:
lua_run function Telex(ply, cmd, args) ply:SetPos(Vector(100, ply:GetPos().y, ply:GetPos().z)) end
lua_run concommand.Add("teleportx", Telex)
in the console in gmod, and typing teleportx in the console works. It sets my position in the x 'dimension' or whatever, to 100.
Yar, I guess there is and there is way too much to look through to see where it has gone wrong.. so I think it is easier if I start again.
Thanks anyway guys :)
[editline]03:01PM[/editline]
Okay last question about this I swear..
I started a new game mode added this:
[lua]function Transform(pl, cmd, args)
local model = args[1]
pl:SetModel("models/props_c17/fountain_01.mdl")
print(pl:GetModel())
end
concommand.Add("trans", Transform)
function Tele(pl, cmd, args)
pl:SetPos(Vector(100, 200, 300))
print(pl:SetPos())
end
concommand.Add("moveme", Tele)[/lua]
they were working, but now when I try them as Client all I get is "Unknown Command" :s
You probably got an error somewhere above it so that part is not loading. Check your entire console for errors, they may be very hard to see.
Odd, I restarted Gmod and it started working fine again.
Sorry, you need to Log In to post a reply to this thread.