• EntityTakeDamage in vehicle
    10 replies, posted
Hello. Excuse me for any grammatical errors. I'm having some problem with this code: [CODE] hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function() if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then dmginfo:SetDamage( dmginfo:GetDamage() / 2 ) ply:TakeDamageInfo( dmginfo ) dmginfo:SetDamage( 0 ) end end end) [/CODE] I didn't create it, I copied it by wiki.garrysmod.org: [URL="http://wiki.garrysmod.com/page/GM/EntityTakeDamage"]http://wiki.garrysmod.com/page/GM/EntityTakeDamage[/URL] When I shoot a car with a player inside, if the player has the armor then only the armor will damage, but If the player hasn't the armor, anything happens. I already tried to edit the code using ply:SetHealth() But anything changes... Someone can help me?
That's just how TakeDamageInfo works. You can always set the Health yourself. If it isn't working, post what you tried
Something like this hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function( target, dmginfo ) if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then damage = dmginfo:GetDamage() ply:SetHealth( ply:Health() - damage ) ply:SetArmor( ply:Armor() - damage ) end end end)
That won't work because neither target nor dmginfo are parameters you specified. Also, you defined damage as global.
Sorry Posted on wrong thread :D
[QUOTE=code_gs;50843226]That won't work because neither target nor dmginfo are parameters you specified. Also, you defined damage as global.[/QUOTE] I'm sorry, I wrote it here, the original code, hasn't this error. I edited the post.
Anyone else?
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] As the wiki says, try returning true
[QUOTE=geferon;50847887][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url] As the wiki says, try returning true[/QUOTE] Excuse me for the delay. Have I to do something like that?: [CODE] hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function( target, dmginfo ) return true if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then damage = dmginfo:GetDamage() ply:SetHealth( ply:Health() - damage ) ply:SetArmor( ply:Armor() - damage ) end end end) [/CODE]
[QUOTE=Predda;50865757]Excuse me for the delay. Have I to do something like that?: [CODE] hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function( target, dmginfo ) return true if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then damage = dmginfo:GetDamage() ply:SetHealth( ply:Health() - damage ) ply:SetArmor( ply:Armor() - damage ) end end end) [/CODE][/QUOTE] Do you even know how return works? That wont work. Do you even read? [CODE] hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function() if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then return true end end end) [/CODE] try that.
[QUOTE=geferon;50867685]Do you even know how return works? That wont work. Do you even read? [CODE] hook.Add("EntityTakeDamage", "PlayerInVehicleDamaged", function() if ( target:IsVehicle() ) then local ply = target:GetDriver() if ( IsValid( ply ) && dmginfo:GetDamage() > 1 ) then return true end end end) [/CODE] try that.[/QUOTE] re-excuse me for the delay. No, it doesn't work.. I don't know how can I make it, can someone help me?
Sorry, you need to Log In to post a reply to this thread.