new Spawntimer[MAX_PLAYERS]; // We will use this for killing the spawn timer, MAX_PLAYERS is used because it will be like a variable for a player not a global variable
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerSpawn(playerid)
{
new world[MAX_PLAYERS]; // If we wanna set the player's world, we will need to create a variable
called "world" to use it for setting the player's world.
world[playerid] = playerid; // this means that the value of player's variable "world" is equal to his id
SetPlayerVirtualWorld(playerid, world[playerid]); // we will set the player's world with the player's "world" variable
if(world[playerid] == 0) // This means if the player's "world" variable is equal to 0
{
SetPlayerVirtualWorld(playerid, 151); // We will the player's world to that number (since my max slots in my
server is 150, I add +1 and then I put the result in the function, example, if your max slots is 50, Set the player's world to 51.
}
SetPlayerHealth(playerid, 100000); // this will make the player's health unlimited (100000) on spawn protection
return 1;
}
public OnPlayerSpawn(playerid)
{
new world[MAX_PLAYERS];
world[playerid] = playerid;
SetPlayerVirtualWorld(playerid, world[playerid]);
if(world[playerid] == 0)
{
SetPlayerVirtualWorld(playerid, 151);
}
SetPlayerHealth(playerid, 100000);
Spawntimer[playerid] = SetTimerEx("Spawnprotect", 5000, false, "d", playerid); // 5000 = 5 Seconds, False = Timer doesn't get repeated, "d" is the format syntax, we use "d" if its for playerid, playerid is... you.
return 1;
}
public OnPlayerSpawn(playerid)
{
new world[MAX_PLAYERS];
world[playerid] = playerid;
SetPlayerVirtualWorld(playerid, world[playerid]);
if(world[playerid] == 0)
{
SetPlayerVirtualWorld(playerid, 151);
}
SetPlayerHealth(playerid, 100000);
Spawntimer[playerid] = SetTimerEx("Spawnprotect", 5000, false, "d", playerid);
SendClientMessage(playerid, -1, "You are under spawn protection for 5 seconds."); // This will send a white message to the player, saying "You are under spawn protection for 5 seconds."
return 1;
}
public OnPlayerSpawn(playerid)
{
new world[MAX_PLAYERS];
world[playerid] = playerid;
SetPlayerVirtualWorld(playerid, world[playerid]);
if(world[playerid] == 0)
{
SetPlayerVirtualWorld(playerid, 151);
}
SetPlayerHealth(playerid, 100000);
Spawntimer[playerid] = SetTimerEx("Spawnprotect", 5000, false, "d", playerid);
SendClientMessage(playerid, -1, "You are under spawn protection for 5 seconds.");
GameTextForPlayer(playerid, "~g~Spawn Protection On", 3000, 4); // this will send a green game text (because of the ~g~) to the player and it will only last 3000 miliseconds (3 seconds), with the game text type 4
return 1;
}
forward Spawnprotect(playerid);
forward Spawnprotect(playerid);
public Spawnprotect(playerid)
{
return 1;
}
foward Spawnprotect(playerid);
public Spawnprotect(playerid)
{
SetPlayerVirtualWorld(playerid, 0); // This will set the player's world to the default (0)
SendClientMessage(playerid, -1, "You are now no longer under spawn protection."); // This will send the player a white message.
GameTextForPlayer(playerid, "~r~Spawn Protection Off", 3000, 4); // This will send the player a red game text (because of ~r~) and it will last 3000 miliseconds (3 seconds) with game text type 4.
SetPlayerHealth(playerid, 100); // We will give back the player's normal health (100)
return 1;
}
KillTimer(Spawntimer[playerid]);
I don't particularly agree with the method of spawn protection (spawning them in a virtual world), but that's just up to preferences.
What I do deem wrong, however, is that you use a random number generator to decide which virtual world the player is sent off to. Random numbers are not guaranteed unique, meaning multiple players could end up in the same virtual world, which is obviously not what you want. A simpler and guaranteed unique number would be to simply use the player's ID. |
world = playerid
@Infinity, @Sellize, you mean Like this?:
pawn Code:
|
public OnPlayerSpawn(playerid)
{
SetPlayerVirtualWorld(playerid, playerid); // Set his VW to his own playerid
Spawntimer[playerid] = SetTimerEx("Spawnprotect", 5000, false, "d", playerid);
SendClientMessage(playerid, -1, "You are under spawn protection for 5 seconds.");
GameTextForPlayer(playerid, "~g~Spawn Protection On", 3000, 4); // this will send a green game text (because of the ~g~) to the player and it will only last 3000 miliseconds (3 seconds), with the game text type 4
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerVirtualWorld(playerid, random(39)+1); // Add 1 to the random number to prevent it from being 0
Spawntimer[playerid] = SetTimerEx("Spawnprotect", 5000, false, "d", playerid);
SendClientMessage(playerid, -1, "You are under spawn protection for 5 seconds.");
GameTextForPlayer(playerid, "~g~Spawn Protection On", 3000, 4); // this will send a green game text (because of the ~g~) to the player and it will only last 3000 miliseconds (3 seconds), with the game text type 4
return 1;
}
SetPlayerVirtualWorld(playerid, random(39)+1);
I agree, eventhough it's a 1/40 chance you will end up in the same VW, you shouldn't take the risk. You could like Infinity said use the player's ID. Also, you should use a more general type of spawn protection, i.e. setting their health to a high value at each update or use a timer to save resources.
Other than that, good tutorial and nice effort ![]() |
Because the default world is 0, and still:
pawn Code:
so I am checking if the player's world has gone to 0, it will reset his world.. instead of using random generator like you and infinity said. |
SetPlayerVirtualWorld(playerid, random(39)+1);