error in spawnkill

Started by wilber32, Nov 27, 2015, 11:09 PM

Previous topic - Next topic

wilber32

when I spawn and spend time spawnkill inserted console "stopped working and closes automatically"

function onScriptLoad()
{
AntiSP <- array( GetMaxPlayers(), null );
}

function onPlayerSpawn( player )
{

SP( player );

}

function onPlayerHealthChange( player, oldhp, newhp )
{

if ( AntiSP[ player.ID ] == true )
{
player.Health = 100;
}

}

function onPlayerKill( killer, player, reason, bodypart )
{

if ( AntiSP[ player.ID ] == true )
{
killer.Health = 0;
PrivMessage( "Spawn-Kill not allowed!", killer );
MessageAllExcept( "** Auto-kill:[ " + killer.Name + " ]. Reason:[ Spawn-Kill ]", killer );
}

}

function SP( player )
{
AntiSP[ player.ID ] = true;
NewTimer( "SPoff", 5000, 1, player );
PrivMessage( "Anti Spawn-Kill:[ ON ]", player );
}

function SPoff( player )
{
AntiSP[ player.ID ] = false;
PrivMessage( "Anti Spawn-Kill:[ OFF ]", player );
}

MacTavish

Change

function SP( player )
{
 AntiSP[ player.ID ] = true;
 NewTimer( "SPoff", 5000, 1, player );
 PrivMessage( "Anti Spawn-Kill:[ ON ]", player );
}

function SPoff( player )
{
 AntiSP[ player.ID ] = false;
 PrivMessage( "Anti Spawn-Kill:[ OFF ]", player );
}

to

function SP( player )
{
 AntiSP[ player.ID ] = true;
 NewTimer( "SPoff", 5000, 1, player.ID );
 PrivMessage( "Anti Spawn-Kill:[ ON ]", player );
}

function SPoff( p )
{
local player = FindPlayer(p);
if(player){
 AntiSP[ player.ID ] = false;
 PrivMessage( "Anti Spawn-Kill:[ OFF ]", player );
}
}

this has been already discussed that we can not pass player INSTANCE through Timer thats why your server crashes

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

wilber32


hotdogcat

You can do an anti spawnkill system without timers too, which is better


Credits to Bart.

KAKAN

Quote from: hotdogcat on Nov 28, 2015, 03:51 PMYou can do an anti spawnkill system without timers too, which is better
How? I only had this way to do my spawn-kill system.
Can you tell me an example on "How to do SP thing without timer"?
oh no

wilber32


MacTavish

There is an Example of antispawn without timer in old forum that is made by @Gudio

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Don't copy paste that script since it wouldn't work for 0.4: IDs start with 0, not 1.

KAKAN

#8
Quote from: Kusanagi on Nov 28, 2015, 08:35 PMThere is an Example of antispawn without timer in old forum that is made by @Gudio
Yet, Timers are not bad unless they are used badly.
But thanks for giving that, you gave me a new idea.
And also, I use many extra things like alpha, immunity etc

Quote from: Thijn on Nov 28, 2015, 09:07 PMDon't copy paste that script since it wouldn't work for 0.4: IDs start with 0, not 1.
Yea
oh no

Diego^

You can use this:

function onScriptLoad()
{
AntiSP <- array( GetMaxPlayers(), 0 );
NewTimer( "Timers", 1000, 0 );
}

function Timers()//You can avail this timer. Example: mute, heal, goto, gotoloc.
{
for( local i = 0, player; i < GetMaxPlayers(); i++ )
{
player = FindPlayer( i );
if ( player )
{
if ( AntiSP[ player.ID ] >= 1 )
{
AntiSP[ player.ID ] --;
if ( AntiSP[ player.ID ] == 0 ) PrivMessage( player, "Anti Spawn-Kill:[ OFF ]" );
}
}
}
}

function onPlayerHealthChange( player, lastHP, newHP )
{
if ( newHP < 100 && AntiSP[ player.ID ] >= 1 ) player.Health = 100;
}

function onPlayerSpawn( player )
{
AntiSP[ player.ID ] = 5;
PrivMessage( player, "Anti Spawn-Kill:[ ON ]" );
}

function onPlayerKill( killer, player, reason, bodypart )
{
if ( AntiSP[ player.ID ] >= 1 )
{
if ( killer.Vehicle ) killer.Eject();
killer.Health = 0;
PrivMessage( killer, "Spawn-Kill not allowed!" );
MessageAllExcept( "** Auto-kill:[ " + killer.Name + " ]. Reason:[ Spawn-Kill ]", killer );
}
}



BRL's Developer.

wilber32

#10
Thanks Diego but there is an error

Diego^

Here works correctly, it must be something wrong in your script.
BRL's Developer.

Thijn

The error is pretty clear, you forgot to add the Timers function.

wilber32


KAKAN

Quote from: wilber32 on Dec 01, 2015, 01:24 PMAs I add?
As I care?

You mean you didn't add the function, then how the F*ck are you expecting it to work?
Kindly, add the function or ....
oh no