So I'm trying to make a script that gives the player money when he breaks a func_breakable, is this possible to do? I already have the giving money part figured out, just trying to figure out how to check what player broke the func_breakable when its broken.
Maybe use the [url=https://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] hook
[QUOTE=NeatNit;51248784]Maybe use the [url=https://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] hook[/QUOTE]
Thanks! I got it to work. Althought I have another problem, it gives me 1 dollar for every hit, I want it to only give me money if it breaks.
[code]function GM:EntityTakeDamage( target, dmginfo )
if ( target:IsSolid() ) then
dmginfo:GetAttacker():money_give(1) else return
end
end[/code]
First, isn't that going to give money to anyone who damages [I]any[/I] solid entity? Second, I think it'd be safe to check if the attacker is an actual player as well.
Also, it shouldn't be "when take damage -> give attacker money" but instead "if damage will destroy this entity -> give attacker money".
[QUOTE=Remixful;51250530]First, isn't that going to give money to anyone who damages [I]any[/I] solid entity? Second, I think it'd be safe to check if the attacker is an actual player as well.
Also, it shouldn't be "when take damage -> give attacker money" but instead "if damage will destroy this entity -> give attacker money".[/QUOTE]
In the gamemode im making there maps func_breakable are the only solid entities, also how do I make it so if damage destroys the entity it gives money?
[QUOTE=Thiefdroid;51250617]In the gamemode im making there maps func_breakable are the only solid entities, also how do I make it so if damage destroys the entity it gives money?[/QUOTE]
[url=http://wiki.garrysmod.com/page/CTakeDamageInfo/GetDamage]dmginfo:GetDamage()[/url] >= [url=http://wiki.garrysmod.com/page/Entity/Health]target:Health()[/url]
The easiest way to do it would be along the lines of:
[lua]hook.Add("EntityTakeDamage", "aaaa", function(ent, dmg)
if not ent:IsSolid() then return end
local ply = dmg:GetAttacker()
if not IsValid(ply) then return end
if not ply:IsPlayer() then return end
timer.Simple(0, function()
if not ent:IsValid() then
ply:GiveMoney(1)
end
end
end)[/lua]
Sorry, you need to Log In to post a reply to this thread.