Nice, unfortunately there already is a teleporting extension, look for E:tele(V)
Hey peoples, I decided I wanted an easy way to teleport with e2 so i pieced this together:
Place in "\garrysmod\addons\wire\lua\entities\gmod_wire_exp ression2\core\custom"Code:e2function void entity:warpStuff(vector DestVec) DestVec = Vector(DestVec[1], DestVec[2], DestVec[3]) if(!validEntity(this)) then return end if (!util.IsInWorld(DestVec)) then while (!util.IsInWorld(DestVec)) do DestVec = DestVec/1.05 end end if (this:IsPlayer()) then if (!self.player == this) then return end this:SetPos(DestVec) else if (!isOwner(self, this)) then return end ConstrainedEnts = constraint.GetAllConstrainedEntities(this) for _, v in pairs(ConstrainedEnts) do EntPhy = v:GetPhysicsObject() EntPhy:SetPos(DestVec + (EntPhy:GetPos() - v:GetPos())) EntPhy:Wake() end end end
Use "Entity:warpStuff(vector)" in E2 to move players and props wherever. If its welded to something, you can use E2 to listen for the owner's right-click or something and it will port everything it's welded to. I use aimPos() so it ports wherever I'm aiming.
I also tried it in conjunction with the find extension so it locates players and contraptions in a certain range and ports them to wherever, works great!
Lemmie know if you have any ideas or suggestions, its pretty basic right now.
Last edited by phreak314; 02-01-2010 at 07:25 PM.
Nice, unfortunately there already is a teleporting extension, look for E:tele(V)
Have you checked HERE first?
No, this is far more complex, as it teleports whole contraption. But, use toWorld next time for the positions, it will save much trouble.
edit: wouldn't work, you'd have to buffer up the toworld pos before the teleport, nevermind
New server IP: 89.238.160.17:27018
Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
Unsmart: I doubt the intelligence of some people.
Drunkie: Nobody could have said that any better than Unsmart.
Unsmart: Solece, I totally did your mom yesterday
Solece: Who hasnt
Divran: there are more retarded people than there are clever people in this world
A guy named DuneD already made a function like this, which teleports the entire contraption. Not sure if he has released it though.
Oh and you should use e2function instead of registerFunction. It's a lot easier.
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
I just noticed this. That's rather clever, forcing it to just find a position in the world instead of erroring out.Code:if (!util.IsInWorld(Vec)) then while (!util.IsInWorld(Vec)) do Vec = Vec/1.05 end end
I think you should add a check to only teleport an entity if it belongs to you, and only be able to teleport yourself. Then, add a console command (that defaults to owner-only) so individual servers can disable that check and allow anyone to teleport anyone else and their stuff. Best of both worlds.
Some sort of effect option might be nice too, like the Hoverdrive uses. With a separate function to toggle if it uses the effect or not.
Last edited by Rybec; 01-30-2010 at 08:37 AM.
Thanks for the input everyone. Rybec, i will look into your ideas, they would make the extension a bit more secure...
I made a couple slight modifications. For a bit of added security, the owner of the expression can only teleport themselves and stuff they own. I've not fully tested the changes, all i know is I can teleport my own stuff. I've not tried in multiplayer.
Still considering options for disabling this protection ingame. Was thinking of maybe implementing a way to allow specific players to have global rights to teleport anything. Not sure if that's really worth it. As it is, its simple and secure.Code:registerFunction("warpStuff", "e:v", "", function(self, args) local op1, op2 = args[2], args[3] local rv1, rv2 = op1[1](self, op1), op2[1](self, op2) if(!validEntity(rv1)) then print("Entity Not Valid") return end local Vec = Vector(rv2[1], rv2[2], rv2[3]) if (!util.IsInWorld(Vec)) then while (!util.IsInWorld(Vec)) do Vec = Vec/1.05 end end if (rv1:IsPlayer()) then if (!self.player == rv1) then return end rv1:SetPos(Vec) else if (!rv1:GetOwner() == self.player) then return end ConstrainedEnts = constraint.GetAllConstrainedEntities(rv1) for _, v in pairs(ConstrainedEnts) do phys = v:GetPhysicsObject() phys:SetPos(Vec + (phys:GetPos() - v:GetPos()) + Vector(0,0,10)) end end end)
Please change it to use e2function instead of registerFunction. It's both easier for you to code and nicer on the eyes.
Also, use "isOwner()" when checking ownership, not GetOwner(). I think GetOwner doesn't work correctly... not sure.
And remove the print saying that the entity is not valid for two reasons: It's only printed to the server's console, so the user won't even notice it. And the server will get spammed with that error message if the user does something wrong.
SVN Tutorial
My SVN:Get dropbox and get 250 MB extra space: DropboxCode:http://divranspack.googlecode.com/svn/trunk/%20divranspack/
Dang, the only problem with good extensions is that few servers have them. This would be perfect for spacebuild so you don't HAVE to use asgard.(it gets annoying)
Working on military pack.
Remember
amateurs build the ark....
Professionals build the titanic
Bookmarks