Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: umar4911 on Oct 16, 2017, 11:17 AM

Title: Player Immunity/Spawn Protection
Post by: umar4911 on Oct 16, 2017, 11:17 AM
I was making spawn protection.
I added this onplayerspawn

player.Immunity = 31;
MessagePlayer("Spawn Protection Enabled", player);
NewTimer("visibility", 5000, 1, player.ID);


Function
function visibility(player)
{
player.Immunity = 0;
MessagePlayer("Spawn Protection Disabled", player);
}

Error
An error has occured[trying to set in integer]
Title: Re: Player Immunity/Spawn Protection
Post by: KAKAN on Oct 16, 2017, 11:46 AM
NewTimer("visibility", 5000, 1, player.ID);
You're passing player.ID and automagically expecting it to become 'player' instance.
function visibility(player)
{
 player.Immunity = 0;
 MessagePlayer("Spawn Protection Disabled", player);
}
They all are player's IDs, not instances. So, your code is doing: 0.Immunity = 0; MsgPlr( "", 0 );
Title: Re: Player Immunity/Spawn Protection
Post by: umar4911 on Oct 16, 2017, 12:07 PM
Quote from: KAKAN on Oct 16, 2017, 11:46 AMNewTimer("visibility", 5000, 1, player.ID);
You're passing player.ID and automagically expecting it to become 'player' instance.
function visibility(player)
{
 player.Immunity = 0;
 MessagePlayer("Spawn Protection Disabled", player);
}
They all are player's IDs, not instances. So, your code is doing: 0.Immunity = 0; MsgPlr( "", 0 );
Oh yeah..
I used
NewTimer("visibility", 5000, 1, player);
but now it shuts my server "Server.exe has stopped working"
Title: Re: Player Immunity/Spawn Protection
Post by: ! on Oct 16, 2017, 01:31 PM
Timer doesn't send instance use player.ID(integer) instead of player(instance).
NewTimer("visibility", 5000, 1, player.ID);

and this in function.
local player = FindPlayer(playerID);

Like this
function visibility(playerID)
{
   local player = FindPlayer(playerID);
   if ( !player ) return;
   player.Immunity = 0;
   MessagePlayer("Spawn Protection Disabled", player);
}
Title: Re: Player Immunity/Spawn Protection
Post by: umar4911 on Oct 16, 2017, 01:57 PM
Worked Thanks