Hi Everybody,
I'm working on a script right now, and as a beginner I have modest knowledges.
What should I use to force a player to USE ( or force to" press e " ) on a defined scripted & usable entity ? I ran out of idea for this one, may be some of you can help
Thanks for your time
The wiki is a great place to start looking, Entity/Use
Hello, actually this is called on the entity when the player uses it.
I want to do the opposit and force the player to use the entity he is looking at without having to press "e"
Add IN_USE as a pressed button in GM/CreateMove or GM/StartCommand
What he linked ( http://wiki.garrysmod.com/page/Entity/Use ) is not a hook/callback, it is a function that imitates pressing E on an entity, exactly what you want.
Thanks for the quick answers guys !
N 2 seemed a bit complicated for me, as a totally beginner I'm going to stick with the simplest things.
Still the simple is too complicated I guess, could someone explain to me the logic behind integrating the function to the code please ?
It seems to me that what I try to do has no sense, but basically I want to create a quick way to test the script using "R" , which works great, and spawns the bball to the wanted position, still I wonder how I could call the second function in the first.
hook.Add("KeyPress", "Eatingtest", function(ply, key)
if (key == IN_RELOAD) then
local SpawningPos = ply:EyePos()
local ent = ents.Create( "sent_ball" )
ent:SetPos( SpawningPos )
ent:Spawn()
ent:Activate()
local function eat(ply,ent,number)
ply:Use( ent)
end
end
end)
I don't think you should call the function on the player, rather try calling it on the entity itself and supply the argument of Player Activator.
So something along the lines of:
ent:Use(ply, 1)
I'm not sure though, you'd have to play around with it. What you did is called a function on the player without supplying the correct arguments, I know you're a beginner but read the wiki, it's your best friend. Also, if you're wondering why I put an int in the function, i'm defining the UseType argument.
Thanks a lot for your help man, I played around your example and it works great ! Now I understand more about using a function inside a hook
Sorry, you need to Log In to post a reply to this thread.