All pastes #373083 Raw Edit

SpawnProtection

public text v1 · immutable
#373083 ·published 2007-02-26 15:16 UTC
rendered paste body
#pragma tabsize 4
#include <a_samp>

//Change this, it's the seconds you are protected for
#define SPAWN_PROTECTION_TIME  8

new bool:JustSpawned[MAX_PLAYERS];
new SpawnCounter[MAX_PLAYERS];
new gPlayerCount;
new SpawnTimer;

forward OnFilterScriptInit();
forward OnFilterScriptExit();
forward OnPlayerConnect(playerid);
forward OnPlayerDisconnect(playerid);
forward OnPlayerSpawn(playerid);
forward OnPlayerDeath(playerid, killerid, reason);
forward ProtectTheSpawns();

public OnFilterScriptInit() {
	print("\n----------------------------------");
	print(" Spawn System Initiation Complete");
	print("----------------------------------\n");
}

public OnFilterScriptExit() {
	print("\n----------------------------------");
	print(" Spawn System Exit Complete ");
	print("----------------------------------\n");
}

public OnPlayerConnect(playerid)
{
    if (gPlayerCount == 0)
     {
	 SpawnTimer = SetTimer("ProtectTheSpawns", 999, 1);
	 printf("gPlayerCount = %d\nProtectTheSpawns Timer Init", gPlayerCount);
     }
    gPlayerCount++;
}

public OnPlayerDisconnect(playerid)
{
	gPlayerCount--;
	if (gPlayerCount == 0)
	 {
	    KillTimer(SpawnTimer);
	    printf("gPlayerCount = %d\nProtectTheSpawns Timer Exit", gPlayerCount);
	 }
}

public OnPlayerSpawn(playerid)
{
	JustSpawned[playerid] = true;
	SpawnCounter[playerid] = 0;
}

public ProtectTheSpawns()
{
	for (new i; i<MAX_PLAYERS; i++)
	 {
	     if ((IsPlayerConnected(i)) && (JustSpawned[i]))
	      {     
		   if (SpawnCounter[i] != SPAWN_PROTECTION_TIME)
		    {
	           	SetPlayerHealth(i, 400.0000);
            	        SpawnCounter[i]++;
  	                new tmp[32];
		  	format(tmp, sizeof(tmp), "~n~~n~~n~~n~~n~~n~~n~~n~~g~(%d)", SpawnCounter[i]);
		   	GameTextForPlayer(i, tmp, 999, 5);
		    }
		   else
		    {
               	        SetPlayerHealth(i, 100.0000);
               	        SpawnCounter[i] = 0;
		    	JustSpawned[i] = false;
		    }
	      }     
        }     
}