I am currently working on this new gamemode for GMod and I have run into a problem. There is a map with poison water that is creating errors for my GM:ShouldTakeDamage event. I know its something stupid but I can't find out what it is. Here is the code
[CODE]function GM:PlayerShouldTakeDamage( victim, attacker )
if attacker:IsWorld() then return true end
if attacker:IsNPC() then return true end
if (attacker:GetUserGroup() == victim:GetUserGroup()) then return false end
if (attacker:GetUserGroup() ~= victim:GetUserGroup()) then return true end
end[/CODE]
Error created: attempt to call method 'GetUserGroup' (a nil value)
Keep in mind this code does work with players, zombies, and the world, but it creates errors only with the poison water thing.
[QUOTE=thejjokerr;49739138]Probably because it's an entity hurting it, not the world and it's no NPC, also it's not a player so it doesn't hold the GetUserGroup method. You need to add another if statement to check if the attacker is a player.[/QUOTE]
Thanks man it worked! It was so simple but thanks for the help :)
Code is
[Code]function GM:PlayerShouldTakeDamage( victim, attacker )
if attacker:IsWorld() then return true
elseif attacker:IsNPC() then return true
elseif attacker:IsPlayer() then
if (attacker:GetUserGroup() == victim:GetUserGroup()) then return false end
elseif attacker:IsPlayer() then
if (attacker:GetUserGroup() ~= victim:GetUserGroup()) then return true end
else return true
end
end
[/code]
Sorry, you need to Log In to post a reply to this thread.