Yo.
Before I say anything else - I have been searching for hours both here and in the wiki, and I've found some code that works somewhat, but I cant put it all together.
What I need is a way to spawn a prop (i've been using a fridge, but whatever) that has a certain hp and is breakable.
I've found something like ent.SetHealth() among other things, but first of all, I dont know which file to put it in (i was assuming init.lua) and I don't know where in the code to put it.
Also, is the ent-part of the function supposed to be replaced by whatever I call the prop? Like, if I call the prop fridge, should it be fridge.SetHealth()?
If someone could just feed me with teaspoons here that would be great, I'm really new to this.
Sorry, but I didn't understand most of that :(
However, I removed pretty much all of my code and started all over again.
This is the code I stole from floodmod to make props breakable:
[code]
function GM:EntityTakeDamage( ent, inflictor, attacker, amount )
if ent:IsPlayer() then
else
if attacker:IsPlayer() then
if attacker:GetActiveWeapon() != NULL then
ent:SetNWInt("PropHealth", ent:GetNWInt("PropHealth") - 5)
end
end
if ent:GetNWInt("PropHealth") <= 0 and ent:IsValid() then
ent:Remove()
end
end
end
[/code]
It works. My props are now removed when I hit them with something, but I still haven't figured out how to add health.
[code]
function GM:ShowHelp( ply )
local propdrop = ents.Create("prop_physics")
if ( !propdrop:IsValid() ) then return end
propdrop:SetPos( ply:GetShootPos() )
propdrop:SetModel( "models/props_c17/FurnitureFridge001a.mdl" )
propdrop:SetHealth( 25 )
propdrop:Spawn()
propdrop:Activate()
end
[/code]
I used the GM:ShowHelp function for easy access while Im testing it.
Both pieces of code are in the init.lua
[code]
DeriveGamemode( "sandbox" )
function GM:Initialize()
self.BaseClass.Initialize( self )
end
propdrop:SetHealth( 25 ) -- Set's "MyEntity"'s health to 1.
[/code]
That's my shared.lua
Last line was something I found in the wiki, but it didn't work either.
THANK YOU! You made my day!
Sorry for bump, but I just realized that this pretty much kills all entities instantly unless I set health.
Is it possible to use regular damaging on NPC's for instance while still keeping this?
Never mind!
To anyone searching later:
[code]
if ent:IsPlayer() or ent:IsNPC() then
else
--DamageCode
end
[/code]
Thanks Dave, I'll try that out too, although I'm certain I already tried that and failed horribly. But of course, I suck.
Sorry, you need to Log In to post a reply to this thread.