• Player.GetPos() Modifying
    3 replies, posted
HOW can i make something call Player.GetPos() but also add 50 Y units to that? My reason: i am working on a gamemode where players are almost never on the ground. i also have a homing missile weapon that trys to hit them using ply:GetPos(). but since ply:Getpos is actually aiming at where they are standing, and not them, it doesnt hit them. for when players are in the air, the ply.GetPos isnt actually ON the body, so it goes straight under them and then it turns around and does the same thing. i am trying to add 50 Y units to that so that it will hit their body and not the space under the player. Here is my code: taken from the actual missile init.lua [lua] /*------------------------------------------------------ Func: Entity:VisibleTarget( variable ) Desc: This is a custom function, thus it is not normally available in the Glua functions. Basically what it does is create a tracer from our entity to another entity and sees if it is visible by checking if it actually hits the entity ( target ). ------------------------------------------------------*/ function ENT:VisibleTarget( enemy ) --If its not valid then its no good if ( !ValidEntity( enemy ) ) then return false end -- Creating a tracer table local BulletSensor = {} BulletSensor.start = self.Entity:GetPos() BulletSensor.endpos = enemy:GetPos() BulletSensor.filter = { self.Entity.Entity } -- Return the trace line of our tracer created to the selected enemy return ( util.TraceLine( BulletSensor ).Entity == enemy ) end /*------------------------------------------------------ Func: Entity:Think() Desc: This is the part where our entity gets to think for itself. In this part, the entity will try to see which target is the closest and will actually go towards it as it is intended to do. ------------------------------------------------------*/ function ENT:Think() -- If it touches the water it will explode if ( self.Entity:WaterLevel() > 0 ) then self.Entity:CreateImpact() -- Water Explosion effect local effectdata = EffectData() effectdata:SetStart( self.Entity:GetPos() ) effectdata:SetOrigin( self.Entity:GetPos() ) effectdata:SetScale( 1 ) util.Effect( "gunshotsplash", effectdata ) end -- If our Enemy is not Valid, then Enemy is nil, and distance is reset if ( !ValidEntity( Enemy ) || Enemy == self.Entity:GetOwner() ) then Enemy = nil NilDistance = math.huge end -- Getting all of the entities on the Map for k,v in pairs( ents.GetAll() ) do -- If the entity found is an NPC or a Player its good to continue if ( v:IsPlayer() || v:IsNPC() ) then -- If the Player in question is us, then its not a good enemy if !( v == self.Entity:GetOwner() ) then -- Just getting the distance between us and the enemy local EnemyDistance = self.Entity:GetPos():Distance( v:GetPos() ) -- If an enemy is closer than the other, we target him if ( EnemyDistance < NilDistance ) then NilDistance = EnemyDistance Enemy = v end end end end [/lua] i added in comments to help you see what function usually does what. Extra help if you can: 1-Dont Target Players on the Same Team function 2-Set The "enemy" to nobody if the player is dead.(only homes in on one player currently) Thanks for the help!
[QUOTE=iRzilla;24922423]ply:GetPos()+Vector(0, 0, 50)[/QUOTE] isnt the third depth? i thought it went X,Y,Z with Z being depth
Sorry, you need to Log In to post a reply to this thread.