Anti-Spawnkill

Started by DizzasTeR, Nov 29, 2015, 07:05 AM

Previous topic - Next topic

DizzasTeR

- This was coded just to give an idea of how some things can be implemented without timers ( @here ).
- This is not supposed to be a perfect anti-spwankill as said before.
- I tested this code alone, if you find anything unusual, feel free to post.


#***************************************************************************************************
const PROTECTION_TIME = 5000; // The time for how long the protection will last.
#***************************************************************************************************

function onScriptLoad()
{
g_Spawnkill <- array( GetMaxPlayers(), null ) // Creating a global array to hold data.
}

function onPlayerJoin( player )
{
g_Spawnkill[ player.ID ] = array( 2, null );
g_Spawnkill[ player.ID ][0] = false;
}

function onPlayerPart( player, reason )
{
g_Spawnkill[ player.ID ] = null;
}

function onPlayerSpawn( player )
{
g_Spawnkill[ player.ID ][0] = true;
g_Spawnkill[ player.ID ][1] = GetTickCount();
}

function onPlayerDeath( player, reason )
{
g_Spawnkill[ player.ID ][0] = false;
}

function onPlayerKill( killer, player, reason, bodypart )
{
if( g_Spawnkill[ player.ID ][0] == true && ( GetTickCount() - g_Spawnkill[ player.ID ][1] ) < PROTECTION_TIME )
{
Message( format( "[#FF0000][Spawnkill]: [#FFFFFF]%s was kicked for spawn-killing!", killer.Name ) );
KickPlayer( killer );
}
else
{
g_Spawnkill[ player.ID ][0] = false;
}
}

KAKAN

1st of all Nice work!
2nd A suggestion:-
Why don't you use time() instead of GetTickCount() ?
oh no

DizzasTeR

I like to use GetTickCount because I consider it more better, view these results:
function onScriptLoad()
{
print( GetTickCount() );
print( time() );
}

Output:
[SCRIPT] 13134
[SCRIPT] 1448800956

time() is something different, while GetTickCount() is something different.

KAKAN

Quote from: Doom_Kill3R on Nov 29, 2015, 12:44 PMI like to use GetTickCount because I consider it more better, view these results:
function onScriptLoad()
{
print( GetTickCount() );
print( time() );
}

Output:
[SCRIPT] 13134
[SCRIPT] 1448800956

time() is something different, while GetTickCount() is something different.
Well, you're decreasing the time using the minus( - ) sign, so there'll be no difference I guess.

function onServerStart(){
print( time() - ( time() -5 ) );
print( GetTickCount - ( GetTickCount - 5 ) );
} //Untested code
The result will be 5.
oh no

DizzasTeR

Why do you love making your life complex? Make it simple, make it efficient.

Thijn

Quote from: Doom_Kill3R on Nov 29, 2015, 02:24 PMWhy do you love making your life complex? Make it simple, make it efficient.
Because time() will always work, and GetTickCount will stop working after your server is online for a few weeks (It will overflow a 32bit integer).
Always use time() if you can, like here.

wilber32

No such as installing spawnkill D:

.

#7
I suppose one could also use the `onPlayerHealthChange()` event and simply restore the health if the damaged player is still protected.

#***************************************************************************************************
const PROTECTION_TIME = 5; // The time for how long the protection will last.
#***************************************************************************************************

function onScriptLoad()
{
g_Spawnkill <- array( GetMaxPlayers(), null ); // Creating a global array to hold data.
}

function onPlayerPart( player, reason )
{
g_Spawnkill[ player.ID ] = null;
}

function onPlayerSpawn( player )
{
g_Spawnkill[ player.ID ] = (time() + PROTECTION_TIME);
}

function onPlayerHealthChange(player, previous, current)
{
if (g_Spawnkill[ player.ID ] > time())
{
player.Health = previous;
}
}

And implement the kick thing as a last resort for times when the player is killed with one hit. To let people know that someone is under the spawn-protection you could make them a little transparent by changing the alpha.

So that people don't freak out when they shoot someone and their life doesn't decrease. Or they get suddenly kicked out of the server. Simply because they had no idea that the player they were shooting was recently spawned.

The spawn protection could also have a reverse effect. The recently spawned player should not be able to inflict damage. To prevent abuse.

Most of these things are common sense for a system such as this and yet no one takes these issues into consideration.
.

DizzasTeR

Maybe you forgot what I wrote on the start of the topic.

Thijn

Quote from: Doom_Kill3R on Nov 30, 2015, 10:00 AMMaybe you forgot what I wrote on the start of the topic.
What's the point in releasing something that isn't meant to be a good system?

KAKAN

Quote from: Thijn on Nov 30, 2015, 04:37 PM
Quote from: Doom_Kill3R on Nov 30, 2015, 10:00 AMMaybe you forgot what I wrote on the start of the topic.
What's the point in releasing something that isn't meant to be a good system?
Doom rekt. xD
oh no

DizzasTeR

#11
Quote from: Thijn on Nov 30, 2015, 04:37 PMWhat's the point in releasing something that isn't meant to be a good system?

Why didn't you came up with that in the first place?

One more thing, those who want to learn and enhance their coding skills probably try to question just like KAKAN did, I am not going to release a perfect snippet since I have experienced the things which occur. The snipet is partially broken but I doubt those who will use this can keep their server on till weeks.

dEaN

thats good! And i am mini edit in this function!!
I think first impressions are important when i pick up a Main.nut script and I'm sticking to the script, I'm putting that organic feeling back in the game.
-Since 2012-