Not to mention it would allow you to make your own stargates/warp holes/portals of any size and shape.
Wait, no, that'd require rotation support. So it'd work, but only if the gates are facing the same way. ..Unless you add the ability to set the object's rotation on arrival, but that would be a huuuuuge change in your code. Like, total rewrite.
Also, if you do implement a console command to toggle the ownership protection, you may want to put in a check to insure the entity that's being warped isn't something you shouldn't be moving, like the world, or map entities. Best I can think of is just to insure the object's owner is a player.
Something like this maybe? I don't have much LUA experience.
Code:if ((!rv1:GetOwner() == self.player && <CONVAR>) || (!rv1:GetOwner():IsPlayer())) then return end
I considered including rotational support, but your concerns with that type of functionality are valid. I have no idea what will be involved but it's something I will look into.
Edit: Now that I think about it, the owner will always be a player. Who ever is running the expression will be self.player. Checking to ensure that self.player is equal to the owner of a prop should never result in the world being effected, unless the player owns the world (not sure if thats possible, unless your Scarface). Correct me if I'm wrong.
But what about Hoverdrive controller?
Well, what I said there only applies if you allow people to turn the owner-only functionality off. My concern there was of the same sort that the "teleport everything" option on the Asguard transporter can, will, and has dislocated planet atmospheres in spacebuild, as well as func_doors, func_buttons, I think a spawnpoint may have got moved once....
I don't really know how GetOwner works, it might just return nil if it's an entity that's built into the map. If that's the case, just checking that there IS an owner would work.
But again, only applies if you make the owner-only protection an optional thing.
EDIT: I just looked it up, rv1:GetOwner():IsValid() will return true if an entity has an owner, which should filter out map props, I think.
Last edited by Rybec; 01-31-2010 at 12:46 PM.
Ok, so it now uses e2function. I changed to isOwner because i verified that getOwner is returning Null (don't know why it works when comparing null to self.player should result false). Again i haven't fully tested in multiplayer yet, but plan to later today.
I tested how the teleportation effects the direction your facing, it doesn't change. If your facing east, after teleport your still facing east. I'm not sure if this is what you meant Rybec. Were you referring to direction or angular velocity. I think it keeps all velocities after port.
Also added wake to the entities that port. If no physics are applied to them during port, they won't move until woken by a phygun, or a wake function.
Edit: Changed some stuff, player teleporting wasn't workin, is now.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
Last edited by phreak314; 02-01-2010 at 07:25 PM.
Examples of usage:
Port contraptions:
Port player:Code:@name PortContrap @persist E:entity TeleOK interval(100) runOnChat(1) if (first()) {E = entity()} Said = owner():lastSaid():explode(" ") if (chatClk(owner()) & Said:string(1) == "/tele") {TeleOK = 1} elseif (chatClk(owner()) & Said:string(1) == "/notele") {TeleOK = 0} if (TeleOK & E:owner():keyAttack2()) { E:warpStuff(E:owner():aimPos()) }
Code:@name PortSelf @persist Own:entity TeleOK interval(100) runOnChat(1) if (first()) {Own = entity():owner()} Said = owner():lastSaid():explode(" ") if (chatClk(owner()) & Said:string(1) == "/tele") {TeleOK = 1} elseif (chatClk(owner()) & Said:string(1) == "/notele") {TeleOK = 0} if (TeleOK & Own:keyAttack2()) { Own:warpStuff(Own:aimPos()) }
I was saying direction, like make a duplicate of the function with an angle argument in addition to the vector position. It repositions the entity to the position, and sets its angles to the new orientation, while moving all constrained ents accordingly.
But that'd be really really complicated to put together. You have to calculate the new relative positions, orientations, and velocities for all the props. It'd be a wicked awesome thing, but quite frankly how often would it really get used.
Direction is already covered. It keeps the direction your facing after teleport. Try it out.
I mean CHANGE the direction when it teleports. Like, prior to teleporting it's angles are (10,15,0), but you use E:warpStuff(Pos,ang(30,50,0)) and that becomes the new angles after it teleports, with all velocities and orientations etc. changed to match.
As though it went through a portal.
As I've said though, it's another project entirely.
Bookmarks