get the carrier of an entity

Hi, I would like to know if it’s possible to know who is the carrier of an entity (the carrier is the guy who grav the entity).

THX for help :stuck_out_tongue:

Might be of help

Thank you ! I go trying this.

I have tried that code


local function gravpickup( ply, ent )	
	ent.picker = ply
end
hook.Add("GravGunOnPickedUp", "setpicker", gravpickup)

local function gravdrop(ply,ent)
	if ent.picker then
		ent.picker = nil
	end
end
hook.Add( "GravGunOnDropped", "removepicker", gravdrop)


For an entity (here a small part of the code):


	if ent.picker == nil then print(ent.picker)
		return
	end

But it’s always return “nil”.
Anyone has a solution?

Is this after you set it to nil in the Grav Gun Drop function?

I don’t really understand ;_;

In your gravdrop function you set ent.picker to nil

No, when the player Grav the entity “ent.picker” is set to ply.

You are only printing if ent.picker is nil, so of course it’s always going to print “nil”

if ent.picker ~= nil then print(ent.picker:Name()) else print “nil” end

So, I wrote that


	print(ent.picker)
	if ent.picker == nil then 
		return
	end

And… it’s printing “nil”

Can you put some prints inside the GravGun hooks and make sure they’re running correctly?

I have done that and it’s printing nothing


local function gravpickup( ply, ent )
	ent.picker = ply
	print(ply)
end
hook.Add("GravGunOnPickedUp", "setpicker", gravpickup)

ply is the player entity. Thats your problem. Try printing ply:Name() or ent:GetClass()

The hook GravGunOnPickedUp isn’t working.
I do:


local function gravpickup( ply, ent )
	ent.picker = ply
	print(ply:Name())
end
hook.Add("GravGunOnPickedUp", "setpicker", gravpickup)

and also:


local function gravpickup( ply, ent )
	ent.picker = ply
	print("something")
end
hook.Add("GravGunOnPickedUp", "setpicker", gravpickup)

But it’s never printing anything.

That’s your problem then; the hook isn’t being called. There could be three reasons I can think of for this:

  1. You’ve added a hook for GravGunOnPickedUp somewhere else and are returning a value there - preventing all other GravGunOnPickedUp hooks from running.
  2. GravGunOnPickedUp is broken or isn’t actually a hook and the wiki has a mistake.
  3. GravGunOnPickedUp is only added in the next update.

Frankly, I’m kinda lost on this one now…

[editline]7th March 2015[/editline]

Or you’re doing this clientside instead of serverside. That could be it.

the hook “gravgunondropped” work, so there is no reason that the hook “gravgunonpickedup” doesn’t work ;(

Are you by chance using FPP?