Author Topic: *Solved* Need help with stopping player damage.  (Read 3430 times)

0 Members and 2 Guests are viewing this topic.

Offline Linkis20

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
*Solved* Need help with stopping player damage.
« on: January 28, 2014, 04:23:23 AM »
Hey I'm linkis20 an Developer/Co-Owner for the Blade Server.
Sometimes i code custom things for the TTT server for fun.
Now what I'm trying to make is an dual system where 2 players can fight it out.
It is far from done but this part is where I'm stuck.
All I'm trying to do is if someone attacks one of the players that are in an dual they can't hurt them.
They can only hurt each other but others can't hurt them.
If i can get this to work i may can make it so that they can't hurt others as well.

So what i have now is this.
Code: [Select]
function GM:PlayerShouldTakeDamage(victim, attacker)
//dualactive = True or False.
//dualchallenger = calling_ply
//dualplayer = target_ply
if dualactive == true then
if (victim:SteamID() == dualplayer:SteamID()) then
if attacker:IsPlayer() then
if (attacker:SteamID() == dualchallenger:SteamID()) then
return true;
else
return false;
end
else
return false;
end
elseif (victim:SteamID() == dualchallenger:SteamID()) then
if attacker:IsPlayer() then
if (attacker:SteamID() == dualplayer:SteamID()) then
return true;
else
return false;
end
else
return false;
end
else
return true;
end
else
return true;
end
end

But this is not working.
When i activate an dual others can hurt me and the other player.

I tested it with an bot and 1 other player. he could hurt me and the bot so i don't know what I'm doing wrong here.
Is it not working because i use SteamID to check if it works?
What is an better way to do this?

Can you help me with this?
Thanks for reading.
« Last Edit: January 28, 2014, 02:23:19 PM by Linkis20 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Need help with stopping player damage.
« Reply #1 on: January 28, 2014, 05:09:50 AM »
Your code doesn't even parse without errors. Look for errors in your console in startup and fix those first.
Experiencing God's grace one day at a time.

Offline Linkis20

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: Need help with stopping player damage.
« Reply #2 on: January 28, 2014, 06:25:29 AM »
Did not see that error. I fixed it and it shows no errors now but it is not working.
I updated the code in the post.

After some testing i did get this error:
attempt to index global 'GAMEMODE' (a nil value)

So am i calling it wrong?
« Last Edit: January 28, 2014, 07:15:37 AM by Linkis20 »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Need help with stopping player damage.
« Reply #3 on: January 28, 2014, 08:22:04 AM »
Yep. As a global it is GM not GAMEMODE.

You only use GAMEMODE when using it inside of a function. Confusing, I know..

Your function should be GM:PlayerShouldTakeDamage( victim, attacker )


This is something you really should be hooking and not overriding though. I think you might find you'll break a lot of things by overriding that particular function unless you do it correctly.
« Last Edit: January 28, 2014, 08:24:09 AM by MrPresident »

Offline Linkis20

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: Need help with stopping player damage.
« Reply #4 on: January 28, 2014, 08:52:46 AM »
So i changed it to GM and tried it and it did not work then put it in an hook and i got the same error:

[ERROR] addons/ulx/lua/ulx/modules/sh/test.lua:133: attempt to index global 'GM' (a nil value)
1. unknown - addons/ulx/lua/ulx/modules/sh/test.lua:133
2. include - [C]:-1
3. unknown - addons/ulx/lua/ulx/cl_init.lua:17
4. include - [C]:-1
5. unknown - addons/ulx/lua/ulib/modules/ulx_init.lua:4
6. include - [C]:-1
7. unknown - addons/ulib/lua/ulib/cl_init.lua:23
8. include - [C]:-1
9. unknown - addons/ulib/lua/autorun/ulib_init.lua:5

So is it not working because it is an ttt server?
This is the hook that i used is:
hook.Add( "GM:PlayerShouldTakeDamage", "PlayerShouldTakeDamageDual", PlayerShouldTakeDamageDual)
i also tryed hook.Add( "PlayerShouldTakeDamage", "PlayerShouldTakeDamageDual", PlayerShouldTakeDamageDual)
But no result.

I don't know why it is not working............
« Last Edit: January 28, 2014, 08:56:46 AM by Linkis20 »

Offline Cobalt

  • Full Member
  • ***
  • Posts: 216
  • Karma: 44
  • http://steamcommunity.com/id/__yvl/
Re: Need help with stopping player damage.
« Reply #5 on: January 28, 2014, 09:13:40 AM »
You need to put it in the gamemode's files, not using hook.Add. At least that's how I've gotten those types of things to work.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Need help with stopping player damage.
« Reply #6 on: January 28, 2014, 12:03:49 PM »
How exactly are you trying to stop the player from taking damage, I see a few variables commented out...

Code: [Select]
dualactive = True or False. -- This should be either true, or false. Not both.
dualchallenger = calling_ply -- How are you getting the calling_ply here?
dualplayer = target_ply -- How are you getting the target_ply here?
« Last Edit: January 28, 2014, 12:08:39 PM by LuaTenshi »
I cry every time I see that I am not a respected member of this community.

Offline Linkis20

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: Need help with stopping player damage.
« Reply #7 on: January 28, 2014, 12:59:47 PM »
Never mind i finaly found what the problem was.

The hook worked but i forgot to put dualactive to true.  :-\

Well it is working that is all that matters.
Thanks for the tips and helping me.
« Last Edit: January 28, 2014, 02:21:35 PM by Linkis20 »