I have an NPC unit and I want it to have health equivalent to a Hunter.
I set the health to about 55,000 is the LUA Script, and it doesn't seem to be effected.
Help.
NPC:SetHealth( int ) where "NPC" is the NPC object you want to modify.
[QUOTE=andrewmcwatters;18514332]NPC:SetHealth( int ) where "NPC" is the NPC object you want to modify.[/QUOTE]
So like:
NPC:SetHealth( int ) Health = "100",
?
NPC:SetHealth( 100 )
[QUOTE=Jamie932;18515616]NPC:SetHealth( 100 )[/QUOTE]
Where do I put it?
Under "list.set"
Or where??
[editline]11:26PM[/editline]
It looks like this:
local Category = "Combine"
local NPC = { Name = "Neo Heavy - Hostile",
Class = "npc_combine_s",
Model = "models/player/Neo_heavy.mdl",
Squadname = "Neo",
Numgrenades = "0",
Health = "100",
Category = Category }
list.Set( "NPC", "npc_combine_NeoH", NPC )
__
Where do I put "NPC:SetHealth( 100 )"?
Thats not the lua script, that the npc script.
[QUOTE=Jamie932;18527371]Thats not the lua script, that the npc script.[/QUOTE]
Well this IS the newbie questions.
Ok well, I'll pull up the LUA once I find it, I guess.
It's just what I posted was in the lua folder and in the lua format. So where in the heck do I find the lua script?
There isn't. :clint:
What you have there is a small script that adds an existing NPC to the list of NPCs spawnable in the NPC menu and sets some of their properties such as model and keyvalues when they are spawned. Normally the actual NPC's script would be in a folder named by it's class name, in entities. In this case this NPC is simply a combine soldier (Not defined in lua) with a different model so you can't simply edit it.
So to answer your previous question : [QUOTE=TizzYcho;18515648]Where do I put "NPC:SetHealth( 100 )"?[/QUOTE]
You would place it inside of a hook that is called each time a NPC is created. There you would check if the NPC is the right one and then actually change it's health. It could look like this :
[lua]hook.Add("PlayerSpawnedNPC", "SetNPCHealth", function(ply, npc)
if npc:GetClass() == "npc_combine_NeoH" then --if it has the right class name
npc:SetHealth(100) -- Set it's health
end
end)[/lua]
[url=http://wiki.garrysmod.com/?search=Gamemode.PlayerSpawnedNPC][I]Gamemode.PlayerSpawnedNPC[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
This would work assuming the NPC is spawned by a player in the sandbox gamemode and that the npc's class name is really "npc_combine_NeoH".
[QUOTE=Crazy Quebec;18537541]There isn't. :clint:
What you have there is a small script that adds an existing NPC to the list of NPCs spawnable in the NPC menu and sets some of their properties such as model and keyvalues when they are spawned. Normally the actual NPC's script would be in a folder named by it's class name, in entities. In this case this NPC is simply a combine soldier (Not defined in lua) with a different model so you can't simply edit it.
So to answer your previous question :
You would place it inside of a hook that is called each time a NPC is created. There you would check if the NPC is the right one and then actually change it's health. It could look like this :
[lua]hook.Add("PlayerSpawnedNPC", "SetNPCHealth", function(ply, npc)
if npc:GetClass() == "npc_combine_NeoH" then --if it has the right class name
npc:SetHealth(100) -- Set it's health
end
end)[/lua]
[url=http://wiki.garrysmod.com/?search=Gamemode.PlayerSpawnedNPC][I]Gamemode.PlayerSpawnedNPC[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
This would work assuming the NPC is spawned by a player in the sandbox gamemode and that the npc's class name is really "npc_combine_NeoH".[/QUOTE]
Where is the hook located exactly? In the file?
Or do I have to add the "hook" to the NPC script?
Oh right. The hook has nothing to do with the NPC script, it has to be included in a file that will be ran serverside. The best way to do this is to place it in a lua file in garrysmod/lua/autorun/
[QUOTE=Crazy Quebec;18538069]Oh right. The hook has nothing to do with the NPC script, it has to be included in a file that will be ran serverside. The best way to do this is to place it in a lua file in garrysmod/lua/autorun/[/QUOTE]
I create an entirely new lua file?
Or add it to another?
Both are fine, it'll just be tidier if you make your own file for it. To create the file just place the script in notepad and save as nameofyourscript.lua. (Make sure to select all files as the file type when you save)
[QUOTE=Crazy Quebec;18538129]Both are fine, it'll just be tidier if you make your own file for it. To create the file just place the script in notepad and save as nameofyourscript.lua. (Make sure to select all files as the file type when you save)[/QUOTE]
Ok I make the file put and put
# hook.Add("PlayerSpawnedNPC", "SetNPCHealth", function(ply, npc)
# if npc:GetClass() == "npc_combine_NeoH" then --if it has the right class name
# npc:SetHealth(300) -- Set it's health
# end
# end)
Inside of it it. Save it. And then place it om autorun?
What do I name the script/lua?
Actually the code would be :
[code]hook.Add("PlayerSpawnedNPC", "SetNPCHealth", function(ply, npc)
if npc:GetClass() == "npc_combine_NeoH" then --if it has the right class name
npc:SetHealth(100)
end
end)[/code]
And the name of the script does not matter, it only has to end with .lua
[QUOTE=Crazy Quebec;18538291]Actually the code would be :
[code]hook.Add("PlayerSpawnedNPC", "SetNPCHealth", function(ply, npc)
if npc:GetClass() == "npc_combine_NeoH" then --if it has the right class name
npc:SetHealth(100)
end
end)[/code]
And the name of the script does not matter, it only has to end with .lua[/QUOTE]
And is run serverside i.e. lua/autorun/server :smile:
Sorry, you need to Log In to post a reply to this thread.