Hi, everybody.
I wrote a script that the attacker caused a big loss dmg
But also attacker cause a big loss dmg
What to do? What did I make incorrectly?
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() and attacker:Team() == TEAM_HUMAN and not attacker:Team() == TEAM_UNDEAD then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
I'm still not sure what you are asking for, or why you created a new thread instead of [URL="http://facepunch.com/showthread.php?t=1458038"]posting in this one[/URL]. Do you know anyone who you can speak to to translate for us?
[QUOTE=James xX;47418540]I'm still not sure what you are asking for, or why you created a new thread instead of [URL="http://facepunch.com/showthread.php?t=1458038"]posting in this one[/URL]. Do you know anyone who you can speak to to translate for us?[/QUOTE]
I want that I didn't receive a big loss.
When I activate this script.
I shoot at the person and he receives a big loss
Here is how I want
[QUOTE=godred2;47418654]I want that I didn't receive a big loss.
When I activate this script.
I shoot at the person and he receives a big loss
Here is how I want[/QUOTE]
Oh you mean, everyone else get's effected by the damage coefficient except you?
[QUOTE=James xX;47418796]Oh you mean, everyone else get's effected by the damage coefficient except you?[/QUOTE]
And I receive - ScaleDamage(100.00), and they receive - ScaleDamage(100.00).
And it is necessary to me that I didn't receive - ScaleDamage(100.00)
[lua]
local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:SteamID() == "Your Steam ID") then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() and attacker:Team() == TEAM_HUMAN and not attacker:Team() == TEAM_UNDEAD then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/lua]
Your script works. Thanks!
But I wrote a script again for team, and it doesn't work.
My script
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == "TEAM_HUMAN") then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
Error: attempt to call method 'Team' <a nil value>
[QUOTE=godred2;47419009]Your script works. Thanks!
But I wrote a script again for team, and it doesn't work.
My script
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == "TEAM_HUMAN") then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
Error: attempt to call method 'Team' <a nil value>[/QUOTE]
You need to check if the victim is a player before you check the team, I overlooked it in my original code.
[editline]29th March 2015[/editline]
[lua]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == "TEAM_HUMAN") then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/lua]
[QUOTE=James xX;47419148]You need to check if the victim is a player before you check the team, I overlooked it in my original code.
[editline]29th March 2015[/editline]
[lua]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == "TEAM_HUMAN") then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/lua][/QUOTE]
[CODE]local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if ( victim:IsPlayer() and victim:team() == TEAM_HUMAN ) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );[/CODE]
Everything works. But it is a error appears when I receive a loss. How to clean this error?
[QUOTE=godred2;47419218][CODE]local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if ( victim:IsPlayer() and victim:team() == TEAM_HUMAN ) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );[/CODE]
Everything works. But it is a error appears when I receive a loss. How to clean this error?[/QUOTE]
try the code I posted.
[QUOTE=James xX;47419236]try the code I posted.[/QUOTE]
Your code doesn't work.
Also there are no error
[QUOTE=godred2;47419250]Your code doesn't work.
Also there are no error[/QUOTE]
I'm guessing everyone is in TEAM_HUMAN.
[QUOTE=James xX;47419288]I'm guessing everyone is in TEAM_HUMAN.[/QUOTE]
No, not all in the HUMAN team
What's the error and how do you know it isn't working?
[QUOTE=James xX;47419431]What's the error and how do you know it isn't working?[/QUOTE]
I connect this script for the player. Also I shoot at other player for check
[editline]29th March 2015[/editline]
[QUOTE=James xX;47419431]What's the error and how do you know it isn't working?[/QUOTE]
Error: attempt to call method 'Team' <a nil value>
[editline]29th March 2015[/editline]
[QUOTE=godred2;47419455]I connect this script for the player. Also I shoot at other player for check
[editline]29th March 2015[/editline]
Error: attempt to call method 'Team' <a nil value>[/QUOTE]
This script works, but gives a error in the console
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
-- Check if you are the victim
-- If you are, then do not scale damage
if ( victim:IsPlayer() and victim:team() == TEAM_HUMAN ) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
[editline]29th March 2015[/editline]
[IMG]http://gmod.cocraft.ru/error.jpg[/IMG]
[lua]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/lua]
The problem you are having above is you are calling player:team(), which doesn't exist. you want to called player:Team() instead. Lua needs proper capitalization. The reason the code I posted previously didn't work was because I overlooked the team if statement you added. player:Team() returns a team ID, not a string.
How then it is necessary to change a code that the script worked?
This code doesn't work:
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:player:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
How do you fail to copy and paste code, your check has victim:player:Team(), it should be victim:Team(), like James posted.
All you had to do was copy and paste the code.
[QUOTE=godred2;47421711]How then it is necessary to change a code that the script worked?
This code doesn't work:
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:player:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE][/QUOTE]
Remove "player:" from "victim:player:Team()"
[QUOTE=James xX;47419586][lua]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/lua]
The problem you are having above is you are calling player:team(), which doesn't exist. you want to called player:Team() instead. Lua needs proper capitalization. The reason the code I posted previously didn't work was because I overlooked the team if statement you added. player:Team() returns a team ID, not a string.[/QUOTE]
How then it is necessary to change a code that the script worked?
This code doesn't work:
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
[QUOTE=godred2;47421828]How then it is necessary to change a code that the script worked?
This code doesn't work:
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:player:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE][/QUOTE]
[code]local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );[/code]
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage );
[/CODE]
- Don't work.
An error would be nice.
[QUOTE=James xX;47421895]An error would be nice.[/QUOTE]
In general there are no error. Simply doesn't work.
Is the victim a player? Is the victim on a team other than TEAM_HUMAN? Is the attacker a player?
Run a debug script to locate the problem. We don't know if the script in the background works or if everyone is TEAM_HUMAN.
[code]local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then print("Im team human. No dmg scale") return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
print("I scaled the dmg fine")
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage )[/code]
[QUOTE=James xX;47421956]Is the victim a player? Is the victim on a team other than TEAM_HUMAN? Is the attacker a player?[/QUOTE]
The attacking not player
[editline]30th March 2015[/editline]
[QUOTE=Nak;47422086]Run a debug script to locate the problem. We don't know if the script in the background works or if everyone is TEAM_HUMAN.
[code]local function HookEntityTakeDamage( victim, dmginfo )
if (victim:IsPlayer()) then
-- Check if you are the victim
-- If you are, then do not scale damage
if (victim:Team() == TEAM_HUMAN) then print("Im team human. No dmg scale") return end
local attacker = dmginfo:GetAttacker()
if attacker:IsValid() and attacker:IsPlayer() then
print("I scaled the dmg fine")
dmginfo:ScaleDamage( 100.00 )
end
end
end
hook.Add( "EntityTakeDamage", "hook_name", HookEntityTakeDamage )[/code][/QUOTE]
printed - "Im team human. No dmg scale".
But I want the team HUMAN to do more damage, but did not receive it
[QUOTE=godred2;47422119]The attacking not player
[editline]30th March 2015[/editline]
printed - "Im team human. No dmg scale".
But I want the team HUMAN to do more damage, but did not receive it[/QUOTE]
[url]http://lua-users.org/wiki/OperatorsTutorial[/url] see Relational expressions
[QUOTE=James xX;47422258][url]http://lua-users.org/wiki/OperatorsTutorial[/url] see Relational expressions[/QUOTE]
Thanks. Here I wrote the script. How to make that the victim was a subject(prop)?
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
local attacker = dmginfo:GetAttacker()
if ( victim:IsPlayer() and attacker:IsValid() and attacker:IsPlayer() and victim:Team() == TEAM_UNDEAD ) then
dmginfo:ScaleDamage( 100.75 )
end
end
hook.Add( "EntityTakeDamage", "dmg11", HookEntityTakeDamage )
[/CODE]
[QUOTE=godred2;47422307]Thanks. Here I wrote the script. How to make that the victim was a subject(prop)?
[CODE]
local function HookEntityTakeDamage( victim, dmginfo )
local attacker = dmginfo:GetAttacker()
if ( victim:IsPlayer() and attacker:IsValid() and attacker:IsPlayer() and victim:Team() == TEAM_UNDEAD ) then
dmginfo:ScaleDamage( 100.75 )
end
end
hook.Add( "EntityTakeDamage", "dmg11", HookEntityTakeDamage )
[/CODE][/QUOTE]
You forgot to check if the attacker is a Human:
[lua]
local function HookEntityTakeDamage( victim, dmginfo )
local attacker = dmginfo:GetAttacker()
-- Check entities are valid
if not IsValid( victim ) or not IsValid( attacker ) then return end
-- Check they're both players
if not victim:IsPlayer() or not attacker:IsPlayer() then return end
-- Check the attacker is a human, and the target is undead
if victim:Team() ~= TEAM_UNDEAD or attacker:Team() ~= TEAM_HUMAN then return end
-- Massive Damage!
dmginfo:ScaleDamage( 100.75 )
end
hook.Add( "EntityTakeDamage", "dmg11", HookEntityTakeDamage )
[/lua]
Sorry, you need to Log In to post a reply to this thread.