How do i add a hook to an entity from an external script?
For example, i got an Entity that doesnt have ENT:Use() defined in its code, now i want to check if someone/something is pressing Use on the entity.
i tried things like:
[CODE]Entity.Use = function(self, activator, caller, useType, value ) end[/CODE]
[CODE]E
Entity.oldUse = Entity.Use
Entity.Use = function(self, a,c,u,v)
...
self.oldUse(self,a,c,u,v)
end
[/CODE]
i cant figure it out.
[QUOTE=gamerpaddy;48602980]How do i add a hook to an entity from an external script?
For example, i got an Entity that doesnt have ENT:Use() defined in its code, now i want to check if someone/something is pressing Use on the entity.
i tried things like:
[CODE]
Entity.Use = function(self, activator, caller, useType, value ) end
[/CODE][CODE]
Entity.oldUse = Entity.Use
Entity.Use = function(self, a,c,u,v)
...
self.oldUse(self,a,c,u,v)
end
[/CODE]
i cant figure it out.[/QUOTE]
Where are you calling the code? Are you just calling it on one entity every time, or do you want to actually change how that entity behaves, every time it spawns?
If you only want to run the code once, try
[code]
local ENT = scripted_ents.GetStored("class_name_here")
ENT.OldUse = ENT.Use
function ENT:Use(activator, caller, type, val)
print("YES HELLO, IS IT WORKING?")
self.OldUse(self, activator, caller, type, val)
end
[/code]
And that will overwrite every entity of class type ''class_name_here'' 's use function, and every entity of its kind thereafter will spawn with the changes.
[QUOTE=gamerpaddy;48602980]How do i add a hook to an entity from an external script?
For example, i got an Entity that doesnt have ENT:Use() defined in its code, now i want to check if someone/something is pressing Use on the entity.
i tried things like:
[CODE]
Entity.Use = function(self, activator, caller, useType, value ) end
[/CODE][CODE]
Entity.oldUse = Entity.Use
Entity.Use = function(self, a,c,u,v)
...
self.oldUse(self,a,c,u,v)
end
[/CODE]
i cant figure it out.[/QUOTE]
Is your target entity a SENT? If it's not then :Use() won't get called on it as far as I know. If that's the case you can try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerUse]GM/PlayerUse[/url] hook.
Thanks Z0mb1n3, i will try that. I want to run the code only once. EDIT: first method worked, second using local ENT = scripted_ents.GetStored("acf_engine") didnt.
Also:
How do i overwrite ENT:Initialize from an external script? or how do i call a second hook right after initialize is being called?
What i want to do:
[url]https://github.com/nrlulz/ACF/blob/master/lua/entities/acf_engine.lua[/url] Line 111
I want to add wire input from an external script (works)
but when i duplicate the entity, the added wire inputs unwire itself, because the initially doesnt exist. the duplicator is looking for them, but they arent there.
I need to overwrite Initialize, so my inputs get added before the duplicator stuff is being called.
Well, when i overwrite it using OnEntityCreated hook, it doesnt work.
Theres no other hook being called when this is getting spawned.
I want to add M9K to FastDL, but I only have a few weapons from the pack and so I want to avoid missing out models/textures as well as accidentally adding others in.
Is there any way to officially find out what textures a model uses?
[QUOTE=PigeonTroll;48603079]I want to add M9K to FastDL, but I only have a few weapons from the pack and so I want to avoid missing out models/textures as well as accidentally adding others in.
Is there any way to officially find out what textures a model uses?[/QUOTE]
You can use
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetMaterials]Entity:GetMaterials()[/url]
you also could try [url]http://www.wunderboy.org/apps/jhlmv.php[/url] which also show raw textures (before compile, same name, but different file extension)
-snip-
Scratch this
-snip-
Forget it... I shouldn't have posted.
Does anyone know where the particle effects for the [url=https://developer.valvesoftware.com/wiki/Env_entity_dissolver]env_entity_dissolver[/url] are stored? I wanted to replace them with Portal 2's updated ones.
[QUOTE=Z0mb1n3;48604042]Does anyone know where the particle effects for the [url=https://developer.valvesoftware.com/wiki/Env_entity_dissolver]env_entity_dissolver[/url] are stored? I wanted to replace them with Portal 2's updated ones.[/QUOTE]
I'm pretty sure they're hard-coded, not stored in .pcf files or anything.
[QUOTE=TwoYearLurker;48604199]I'm pretty sure they're hard-coded, not stored in .pcf files or anything.[/QUOTE]
I figured as much, and apparently I can't load the .pcf file that actually stores the new effect into GMod, or its particle editor.
grossssss
I'm needing to open a menu for a gamemode i'm developing, and i want the key to open it to be "B". They wiki shows keys such as KEY_USE which are already defined, how do i use a key that is not set to use or walk?
[QUOTE=Lawlypops;48604356]I'm needing to open a menu for a gamemode i'm developing, and i want the key to open it to be "B". They wiki shows keys such as KEY_USE which are already defined, how do i use a key that is not set to use or walk?[/QUOTE]
Try using [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url]
Keys:[url]http://wiki.garrysmod.com/page/Enums/KEY[/url]
[QUOTE=Shadowrune;48604490]Try using [url=http://wiki.garrysmod.com/page/input/IsKeyDown]input.IsKeyDown[/url]
Keys:[url]http://wiki.garrysmod.com/page/Enums/KEY[/url][/QUOTE]
I tried that, but to test it i used Print() to print hi into console but it didnt do anything
hook.Add( "Think", "BM_Clients_Key", function()
If input.IsKeyDown( KEY_LALT ) ) then print( " hi" )
end )
But there were not any lua errors either.
[QUOTE=Lawlypops;48604554]But there were not any lua errors either.[/QUOTE]
That isn't possible, considering the fact that the code you posted has syntax errors. The only explanation is that your file isn't being ran.
[QUOTE=man with hat;48604570]That isn't possible, considering the fact that the code you posted has syntax errors. The only explanation is that your file isn't being ran.[/QUOTE]
Sorry, im typing this off my phone and didnt try to get the syntax correct. The file is being ran because it also contains the code do give the player a physgun when they spawn, which works. The version i have typed doesnt have syntax errors because i fixed them but nothing happens. Id do it now but its too late at night and i need to get some sleep. Ill post it tomorrow if you need me to
Hey guys, seeing how I recently got a new logitech keyboard, I wanted to create an applet for Arx Control that would display chat in-game, or could be used to execute console commands without opening the console. I understand I'd need to do this with a module, and I have documentation from Logitech to provide support for it, but where would I begin for creating it? Should I even try, given I only have knowledge with LUA and PHP?
[QUOTE=Mrkrabz;48600160]Ill keep an eye on the entity limit next time, the only thing I could think of is Pointshop which I'm removing soon as I'm almost done with my own. Thanks[/QUOTE]
caused by too many particle effects
A bit of a rest helped me figure out what i was doing wrong, but now that i have what i believe to be correct, im now getting this error: /gamemode/player.lua:7: attempt to index global 'input' (a nil value)
hook.Add( "Think", "BM_Clients_Key", function()
if input.IsKeyDown( KEY_B ) == true then Print( "Buy key works" )
end
end
)
I don't see how to fix this, and entering "local input = input" gives "attempt to index upvalue 'input' (a nil value)"
I'm new to programming (if you couldn't tell)
so i'm not quite sure how to fix it. (Yes i tried looking up online for solutions)
EDIT: Also, how do i write the code in a code box?
Make sure you are running this code client side.
[QUOTE=Author.;48607834]Make sure you are running this code client side.[/QUOTE]
Thank you, i forgot that i ran that file on server side (i should check that more often)
I also realized that i had Print() instead of print(). It works now!
[QUOTE=Lawlypops;48607826]A bit of a rest helped me figure out what i was doing wrong, but now that i have what i believe to be correct, im now getting this error: /gamemode/player.lua:7: attempt to index global 'input' (a nil value)
hook.Add( "Think", "BM_Clients_Key", function()
if input.IsKeyDown( KEY_B ) == true then Print( "Buy key works" )
end
end
)
I don't see how to fix this, and entering "local input = input" gives "attempt to index upvalue 'input' (a nil value)"
I'm new to programming (if you couldn't tell)
so i'm not quite sure how to fix it. (Yes i tried looking up online for solutions)
EDIT: Also, how do i write the code in a code box?[/QUOTE]
either use [.CODE] [./CODE] without the dots, or else when you go advanced you should have a button which looks like this: [IMG]http://puu.sh/jYNPq/a61950d56c.png[/IMG]
[QUOTE=Lawlypops;48607826]A bit of a rest helped me figure out what i was doing wrong, but now that i have what i believe to be correct, im now getting this error: /gamemode/player.lua:7: attempt to index global 'input' (a nil value)
hook.Add( "Think", "BM_Clients_Key", function()
if input.IsKeyDown( KEY_B ) == true then Print( "Buy key works" )
end
end
)
I don't see how to fix this, and entering "local input = input" gives "attempt to index upvalue 'input' (a nil value)"
I'm new to programming (if you couldn't tell)
so i'm not quite sure how to fix it. (Yes i tried looking up online for solutions)
EDIT: Also, how do i write the code in a code box?[/QUOTE]
I know this is fixed, but "== true" is not required as input.IsKeyDown returns a boolean, so it's the equivalent of stating "if true then"
How can I fade from one Angle to an other Angle? (EyeAngle)
Is there anyway to have beams fade out like [url=https://dl.dropboxusercontent.com/u/67402346/ShareX/2015/09/2015-09-03_13-10-19.webm]this[/url] (Sorry for bad FPS, ShareX's recording feature sucks)
[editline]3rd September 2015[/editline]
[QUOTE=KingCentKing;48608293]How can I fade from one Angle to an other Angle? (EyeAngle)[/QUOTE]
[url]http://wiki.garrysmod.com/page/Global/LerpAngle[/url]
[QUOTE=mib999;48608163]I know this is fixed, but "== true" is not required as input.IsKeyDown returns a boolean, so it's the equivalent of stating "if true then"[/QUOTE]
Good to know, thanks, and i was thinking " if true equals true" was a bit repetitive
-snip-
When creating new entities, should I load them using the include() function or drop them in the lua/entities folder?
I know that ENT is a metatable however, I've got multiple entities and I'm loading them using a for loop currently.
Here's my currently method:
[CODE]
Files, Directories = file.Find( "entities/*.lua" )
for _, ent in pairs(Files) do
include( "entities/" .. ent )
end
[/CODE]
[QUOTE=Potatofactory;48609746]When creating new entities, should I load them using the include() function or drop them in the lua/entities folder?
I know that ENT is a metatable however, I've got multiple entities and I'm loading them using a for loop currently.
Here's my currently method:
[CODE]
Files, Directories = file.Find( "entities/*.lua" )
for _, ent in pairs(Files) do
include( "entities/" .. ent )
end
[/CODE][/QUOTE]
Drop them into lua/entities as long as you have the init file in there have a line called include("shared.lua") include("cl_init.lua") and AddCSLuaFile() in both cl_init and shared. If you're using only one file, you just need AddCSLuaFile() at the top
[QUOTE=LUModder;48608433]Is there anyway to have beams fade out like [url=https://dl.dropboxusercontent.com/u/67402346/ShareX/2015/09/2015-09-03_13-10-19.webm]this[/url] (Sorry for bad FPS, ShareX's recording feature sucks)
[editline]3rd September 2015[/editline]
Ok but how can I use it that it fades from the first Angle to the second angle.
The function itself just returns a percentage. (?)
[url]http://wiki.garrysmod.com/page/Global/LerpAngle[/url][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.