Ulysses
General => Developers Corner => Topic started by: Linkis20 on January 28, 2014, 04:23:23 AM
-
Hey I'm linkis20 an Developer/Co-Owner for the Blade Server (http://steamcommunity.com/groups/S-Blade).
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.
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.
-
Your code doesn't even parse without errors. Look for errors in your console in startup and fix those first.
-
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?
-
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.
-
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............
-
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.
-
How exactly are you trying to stop the player from taking damage, I see a few variables commented out...
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?
-
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.