meta tables, player.

Basically I have a player_extension lua file in my gamemode folder that is the following




local meta = FindMetaTable( "Player" )
if (!meta) then return end 

function meta:GivePower( weaponstring )

	print("Powers!")
	self:Give(weaponstring)

end


and then I try to Access the function in an entity’s init file with the following



-- ENT:DoPowers - This is the function that do the actual powerup code, there is also code in sent_melon_base --
function ENT:DoPowers(Ent)
	--Ent is the ball...
	local ply

	-- We Want to do stuff to the Player/Ball here
	if (Ent:GetOwner():IsValid()) then
		ply = Ent:GetOwner()
		print("player valid")
	end
	-- Balloon(1) --
	if (self.PowerupType == 1) then
		ply:PrintMessage(4, "Shoot At Other Players to attach balloons to them.")
        
        Ent:GetOwner():GivePower("weapon_crowbar")
	end
	
end


Problem is that the function GivePowers returns nil in the console, Am i doing something wrong here?

Are you including your player_extension.lua file?

  1. Are you doing

include( "player_extension.lua" )

in your init.lua file?

  1. Does it actually print “player valid”? If you didn’t manually set the entity’s owner, it doesn’t do it for you. It could error if Ent:GetOwner() isn’t valid.

  2. Also, did you define “Ent” anywhere? The correct syntax would be “self.Entity:GetOwner()”.

edit 1/3 ninja :ninja:

Remove the local infront of your meta!

I don’t think that’s the problem.

Why would you want him to do that?

To get me mad. :smile:

Ah Silly me, I used AddCSLuaFile instead of include, thanks much.

But another problem is that the actual player:Give(“weapon_crowbar”) only works a quarter of the time. to recap I have this:



function ENT:StartTouch(Ent)
	
	-- Only Balls are allowed to Touch!
	if (!Ent:GetClass() == "sent_ball_base") then
		return
	end
	
	-- Do the powerup stuff
	self:DoPowers(Ent)
	
	-- Remove the powerup 
	self.Entity:Remove()
	
	-- Debug
	print("Powerup Touched")
end


function ENT:DoPowers(Ent)
	--Ent is the ball...
	local ply

	-- We Want to do stuff to the Player/Ball here
	if (Ent:GetOwner():IsValid()) then
		ply = Ent:GetOwner()
		print("player valid")
	end
	-- Balloon(1) --
	if (self.PowerupType == 1) then
		ply:PrintMessage(4, "Shoot At Other Players to attach balloons to them.")
        
        ply:GivePower("weapon_crowbar")
	-- Haste --
	elseif (self.PowerupType == "Haste") then
		Ent.HasteTimer = CurTime() + GAMEMODE.Powerups.Haste.Duration
	end	
	
end



and then the meta function:



function meta:GivePower( weaponstring )


	print("Powers!")
	self:Give(weaponstring)

end


Ive tried putting the



  self:Give(weaponstring)



in different places including directly in the Ent:starttouch() function.

the results are only picking up the weapon sometimes.

Does the weapon spawn at all?

yeah, thats whats wierd, only sometimes. I basically have to run over at least 10 powerups for it to give me a weapon. And Im very sure it comes down to ply:Give().

Get an ESP, set it to display “weapon_crowbar” and see if it’s under the map.
Or just do:
[lua]
lua_run for k,v in pairs(ents.FindByClass"weapon_crowbar")do player.GetAll()[1]:SetPos(v:GetPos())end
[/lua]

If you teleport under the map (and/or get a crowbar), then the crowbar is being made… just in the wrong place.

(I swear Garry fixed the Give function… but who knows)

Make sure you don’t have a PlayerCanPickupWeapon hook that’s stopping it from being given.

And, are you using a non-default hull size for the players?

He raised the height the weapon gets created at (rather than it being at your feet)

If you’re completely stuck, it won’t work (Unless he improved it again without putting it in the changelog)

Ahh, This Would Explain it. My player is controlling a rolling physics entity, the invisible player is constantly being repositioned to the entity. So the chances of the player actually picking up the weapon is rather low. How would you suggest getting around this?

Other than that the hull is normal.

Does the player always need to be positioned inside the rolling physics entity? Maybe just use the CalcView hook clientside to position the camera at the physics entity and leave the player somewhere in the map, invisible frozen and nocollided.