All pastes #933989 Raw Edit

Stuff

public text v1 · immutable
·published 2008-03-08 15:57 UTC
rendered paste body
#include <a_samp>
#include <core>
#include <float>

//Color Defines
#define COLOR_RED 0xAA3333AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_DARKRED 0x660000AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_GREY 0xAFAFAFAA
//Team Defines
#define TEAM_1 0
#define TEAM_2 1
#define TEAM_REF 2
#define MAX_STRING 255

new gTeam[MAX_PLAYERS];
new gPlayerClass[MAX_PLAYERS];
new tkscore[MAX_PLAYERS];
new TEAM1[256], TEAM2[256], MAXKILLS;
new wpn1, wpn2, wpn3;
new ammo1, ammo2, ammo3;
new DeathCount[MAX_PLAYERS];
new sCount1, sCount2;
new winner[256];
//new astring[256];
new aAutoS;


//------------------------------------------------------------------------------

main()
{
	print("\n----------------------------------");
	print("         ClanBattle: v1.0           ");
	print("----------------------------------\n");
	print("Loading Config......\n");
	printf("    | %s VS %s |         ",TEAM1, TEAM2);
	printf("    |First Clan to %d Kills",MAXKILLS);
//	if(aAutoS > 0){ print("    |Auto-Clan-Detection   [Activated]\n"); }else{ print("    |Auto-Clan-Detection   [Disabled]\n");}
}

//------------------------------------------------------------------------------

public OnGameModeInit()
{
	SetGameModeText("HC4L Gang Server");
	SetTeamCount(3);
	ShowNameTags(1);
	ShowPlayerMarkers(1);
	SetWorldTime(1);
	rConfig();
	UsePlayerPedAnims();


	AddPlayerClass(299,1410.8242,2102.9089,12.0156,352.7742,wpn1,ammo1,wpn2,ammo2,wpn3,ammo3); // Team1 spawn
	if(aAutoS == 0){
	AddPlayerClass(105,1306.5330,2211.8743,12.0156,270.3902,wpn1,ammo1,wpn2,ammo2,wpn3,ammo3); // Team2 spawn
	AddPlayerClass(21,1368.5774,2196.8315,9.7578,176.8027,43,500,0,0,0,0); //Ref spawn
	}
	return 1;
 }

//------------------------------------------------------------------------------



public OnPlayerConnect(playerid)
{
    new wString[256];
    
    SetPlayerWeather(playerid, 47);
	SendClientMessage(playerid, COLOR_YELLOW, "Welcome to ClanBattle v1.0");
	SendClientMessage(playerid, COLOR_YELLOW, "Type an ! before your message to talk to the team");
	format(wString, sizeof(wString), " %s vs %s  ||  First Clan to %d Kills", TEAM1, TEAM2, MAXKILLS);
	SetPlayerArmour(playerid, 100);
	SendClientMessage(playerid, COLOR_LIGHTBLUE, wString);
	SendClientMessage(playerid, COLOR_YELLOW, "Type /stuntls to go to the Los Santos Stunt Airport");
	SetPlayerColor(playerid, COLOR_GREY);
	gTeam[playerid] = ClanDetect(playerid);
	return 1;
}

public OnPlayerDisconnect(playerid)
{
	tkscore[playerid] = 0;
	return 1;
}



//------------------------------------------------------------------------------



public OnPlayerSpawn(playerid)
{
	SetPlayerInterior(playerid,0);
	if(gTeam[playerid] == TEAM_1)
	{
	SetPlayerColor(playerid,COLOR_RED);// Red
	SetPlayerArmour(playerid, 100);
	}
	else if(gTeam[playerid] == TEAM_2)
	{
	SetPlayerColor(playerid,COLOR_BLUE); // Blue
	SetPlayerArmour(playerid, 100);
	}
	else if(gTeam[playerid] == TEAM_REF)
	{
	SetPlayerColor(playerid,COLOR_LIGHTBLUE); // Light Blue
	SetPlayerArmour(playerid, 100);
	}
	
	if(aAutoS == 1) // AUTO SPAWN IMPLEMENTATION
	{
	    if(gTeam[playerid] == TEAM_1)
		{
		SetPlayerPos(playerid,1410.8242,2102.9089,12.0156,352.7742);
		SetPlayerFacingAngle(playerid, 270);
		SetPlayerSkin(playerid, 105);
		return 1;
  		}
		else if(gTeam[playerid] == TEAM_2)
		{
		SetPlayerPos(playerid,1306.5330,2211.8743,12.0156,270.3902);
		SetPlayerFacingAngle(playerid, 90);
	 	SetPlayerSkin(playerid, 299);
	 	return 1;
		}
		else if(gTeam[playerid] == TEAM_REF)
		{
		SetPlayerPos(playerid,1368.5774,2196.8315,9.7578,176.8027);
		SetPlayerFacingAngle(playerid, 90);
		SetPlayerSkin(playerid, 21);
		ResetPlayerWeapons(playerid);
		GivePlayerWeapon(playerid, 43,500);
		return 1;
		}
		}
		return 1;
 }


public SetupPlayerForClassSelection(playerid) // CHANGE ALL
{
	SetPlayerInterior(playerid, 0);
	SetPlayerPos(playerid,1410.5830,2109.2654,12.0156);
	SetPlayerFacingAngle(playerid, 90);
	SetPlayerCameraPos(playerid,1368.5774,2196.8315,9.7578,176.8027);
	SetPlayerCameraLookAt(playerid,1368.5774,2196.8315,9.7578,176.8027);
	return 1;
}




//------------------------------------------------------------------------------

public OnPlayerDeath(playerid, killerid, reason)
{
if(gTeam[killerid] != gTeam[playerid])
{
	SendDeathMessage(killerid,playerid,reason);
	SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
}
else {
	new warning[256];
  format(warning, sizeof(warning), "Be careful! Do Not Team-Kill");
  SendClientMessage(killerid, 0xFFFF00AA, warning);
  SendDeathMessage(killerid,playerid,reason);
  SetPlayerScore(killerid, GetPlayerScore(killerid) - 1);
  tkscore[playerid]++;
  return 1;
  }
	new string[256], string2[256], string3[256], gtstring[256];
	DeathCount[playerid]++;

	if(killerid == INVALID_PLAYER_ID) {
	SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
	SetPlayerScore(playerid, GetPlayerScore(playerid)-1);
	}
	
	if(IsPlayerConnected(killerid))
	{
	if(gTeam[killerid] == TEAM_1)
	{
		sCount1++;
		format(string2, sizeof(string2), "%s Score: %d", TEAM1, sCount1);
		SendClientMessageToAllEx(COLOR_YELLOW, string2);
		for(new z=0;z<MAX_PLAYERS;z++)
		{
		if(gTeam[z] == 0)
		{
		format(gtstring, sizeof(gtstring), "~b~%s Score: ~r~%d", TEAM1, sCount1);
		GameTextForPlayer(z,gtstring,3500,3);
	}
	}
	}
	if(gTeam[killerid] == TEAM_2)
	{
	    sCount2++;
		format(string3, sizeof(string3), "%s Score: %d", TEAM2, sCount2);
		SendClientMessageToAllEx(COLOR_YELLOW, string3);
		for(new y=0;y<MAX_PLAYERS;y++)
		{
		if(gTeam[y] == 1)
		{
		format(gtstring, sizeof(gtstring), "~b~%s Score: ~r~%d", TEAM2, sCount2);
		GameTextForPlayer(y,gtstring,3500,3);
	}
	}
	}
	}
	if(sCount1 == MAXKILLS)
	{
	    format(string, sizeof(string), "%s has WON the CLAN WAR!", TEAM1);
	    strins(winner,TEAM1,0,sizeof(winner));
	    iStats();
		sStats();
  		iFreeze();
		TogglePlayerControllable(playerid,0);
	    SendClientMessageToAllEx(COLOR_YELLOW, string);
	}
	else if(sCount2 == MAXKILLS)
	{
	    format(string, sizeof(string), "%s has WON the CLAN WAR!", TEAM2);
	    strins(winner,TEAM2,0,sizeof(winner));
	    iStats();
		sStats();
		iFreeze();
		TogglePlayerControllable(playerid,0);
	    SendClientMessageToAllEx(COLOR_YELLOW, string);
	}
 return 1;
}


//------------------------------------------------------------------------------

public OnPlayerRequestClass(playerid, classid)
{
 if(aAutoS == 1)
	{

			if(gTeam[playerid] == TEAM_1)
	        {
         		SetPlayerSkin(playerid, 299);
				GameTextForPlayer(playerid,TEAM1,1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2789.9348,-2418.5481,13.6331);
				SetPlayerFacingAngle(playerid, 87);
				SetPlayerCameraPos(playerid,2783.6499,-2418.1187,13.6347);
				SetPlayerCameraLookAt(playerid,2789.9348,-2418.5481,13.6331);
			}
			else if(gTeam[playerid] == TEAM_2)
	        {
	            SetPlayerSkin(playerid, 105);
				GameTextForPlayer(playerid,TEAM2,1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2640.1646,-2502.8940,13.4922);
				SetPlayerFacingAngle(playerid, 278);
				SetPlayerCameraPos(playerid,2647.3855,-2503.3369,13.4922);
				SetPlayerCameraLookAt(playerid,2640.1646,-2502.8940,13.4922);
			}
			else if(gTeam[playerid] == TEAM_REF)
		    {
                SetPlayerSkin(playerid, 21);
				GameTextForPlayer(playerid,"~g~Ref",1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2731.3306,-2451.0273,17.5937);
				SetPlayerFacingAngle(playerid, 277);
				SetPlayerCameraPos(playerid,2734.3848,-2450.4028,17.5938);
				SetPlayerCameraLookAt(playerid,2731.3306,-2451.0273,17.5937);
   			}
   			return 1;
		}


if(aAutoS == 0)
	{
	SetPlayerClass(playerid, classid);
	gPlayerClass[playerid] = classid;
	SetupPlayerForClassSelection(playerid);
	switch (classid) {

	    	case 0:
	        {
				GameTextForPlayer(playerid,TEAM1,1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2789.9348,-2418.5481,13.6331);
				SetPlayerFacingAngle(playerid, 87);
				SetPlayerCameraPos(playerid,2783.6499,-2418.1187,13.6347);
				SetPlayerCameraLookAt(playerid,2789.9348,-2418.5481,13.6331);
			}
			case 1:
	        {
				GameTextForPlayer(playerid,TEAM2,1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2640.1646,-2502.8940,13.4922);
				SetPlayerFacingAngle(playerid, 278);
				SetPlayerCameraPos(playerid,2647.3855,-2503.3369,13.4922);
				SetPlayerCameraLookAt(playerid,2640.1646,-2502.8940,13.4922);
			}
			case 2:
		    {
				GameTextForPlayer(playerid,"~g~Ref",1000,3);
				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid,2731.3306,-2451.0273,17.5937);
				SetPlayerFacingAngle(playerid, 277);
				SetPlayerCameraPos(playerid,2734.3848,-2450.4028,17.5938);
				SetPlayerCameraLookAt(playerid,2731.3306,-2451.0273,17.5937);
   				}
		}
}
return 1;
}

//------------------------------------------------------------------------------


SetPlayerClass(playerid, classid) {

	if(classid == 0){ gTeam[playerid] = TEAM_1;
	}
	else if(classid == 1){ gTeam[playerid] = TEAM_2;
	}
	else if(classid == 2){ gTeam[playerid] = TEAM_REF;
	}
	return 1;
}

//------------------------------------------------------------------------------

// READ FILE CONFIG

rConfig()
{
	new File:fhandle;
	new cname[256];
	new temp[256];
	new value[256];
	fhandle = fopen("ClanConfig.txt",io_readwrite);
		while(fread(fhandle,temp,sizeof(temp),false))
		{
		    cname = strtok(temp,0);
			value = strtok(temp,(strlen(cname)+1));
			
			if(strcmp(cname,"Team-1",true) == 0) strins(TEAM1,value,0,MAX_STRING);
			else if(strcmp(cname,"Team-2",true) == 0) strins(TEAM2,value,0,MAX_STRING);
			else if(strcmp(cname,"Max-Clan-Kills",true) == 0) MAXKILLS = strval(value);
			else if(strcmp(cname,"Weapon1",true) == 0) wpn1 = strval(value);
			else if(strcmp(cname,"Weapon2",true) == 0) wpn2 = strval(value);
			else if(strcmp(cname,"Weapon3",true) == 0) wpn3 = strval(value);
			else if(strcmp(cname,"Ammo1",true) == 0) ammo1 = strval(value);
			else if(strcmp(cname,"Ammo2",true) == 0) ammo2 = strval(value);
			else if(strcmp(cname,"Ammo3",true) == 0) ammo3 = strval(value);
//			else if(strcmp(cname,"Clan-Detect",true) == 0) aAutoS = strval(value);
		}
		fclose(fhandle);
		return 1;
}

/*
========================
        Team Chat
========================
*/

 public OnPlayerText(playerid, text[])
   {
		   new strName[MAX_PLAYER_NAME];
		   new strOut[MAX_STRING];
		   new i;
		   i++;

		   GetPlayerName(playerid, strName, sizeof(strName));
		   if(text[0] == '!')
		   {
		     new string[MAX_STRING];
		     strmid(string, text, 1, strlen(text), MAX_STRING);
		     format(strOut, MAX_STRING, "[TC] [%s]: %s", strName, string);

		     for(i = 0; i<MAX_PLAYERS; i++)
		     {
		       if(gTeam[i] == gTeam[playerid])
       			SendClientMessage(i, COLOR_LIGHTBLUE, strOut);
		       }
		     return 0;
		   }
		   return 1;
		 }

/*
========================
	  Save Stats
========================
*/

iStats()
{
 	new File:fhandle;
	new temp[256], temp2[256], temp3[256];

	fhandle = fopen("ClanStats.txt",io_append);
	format(temp,sizeof(temp),"ClanWar %s VS %s\r\n",TEAM1,TEAM2);
	format(temp2, sizeof(temp2), "Winner: %s\r\n",winner);
	format(temp3, sizeof(temp3), "%s: %d  ||  %s: %d\r\n", TEAM1, sCount1, TEAM2, sCount2);
	fwrite(fhandle,temp);
	fwrite(fhandle,temp2);
	fwrite(fhandle,temp3);
	fclose(fhandle);
}

sStats()
{
for(new i=0;i<MAX_PLAYERS;i++)
	{
 if(IsPlayerConnected(i))
 {
 new File:fhandle;
	new temp[256];
	new Score;
	Score = GetPlayerScore(i);
	new Float:ratio = Float:Score / Float:DeathCount[i];

	fhandle = fopen("ClanStats.txt",io_append);
	format(temp,sizeof(temp),"%s Kills: %d Deaths: %d Ratio: %0.2f\r\n",PlayerName(i),Score,DeathCount[i],ratio);
	fwrite(fhandle,temp);
	fclose(fhandle);
}
}
}

/*
========================
	 GetPlayerName
========================
*/

public PlayerName(playerid)
{
  new pName[256];
  GetPlayerName(playerid, pName, sizeof(pName));
}

/*
========================
	   AutoSpawn
========================
*/

public ClanDetect(playerid)
{
 if(IsPlayerConnected(playerid))
	{
	    SendClientMessage(playerid, COLOR_YELLOW, "Detecting Clan...");
		new tmpnick[MAX_PLAYER_NAME];
		new ctxt[256];
		GetPlayerName(playerid, tmpnick, sizeof(tmpnick));
		for(new n=0; n<strlen(tmpnick); n++)
		{
		    if(TEAM1[0] == tmpnick[n])
		    {
		        if(TEAM1[1] == tmpnick[(n+1)])
		        {
		            if(TEAM1[2] == tmpnick[(n+2)])
		            {
		                format(ctxt, sizeof(ctxt), "Detected Clan: %s", TEAM1);
		                SendClientMessage(playerid, COLOR_YELLOW, ctxt);
		    			return TEAM_1;
					}
 			  	}
			 }
		     else if(TEAM2[0] == tmpnick[n])
		     {
		     	if(TEAM2[1] == tmpnick[(n+1)])
		        {
		            if(TEAM2[2] == tmpnick[(n+2)])
		            {
              			format(ctxt, sizeof(ctxt), "Detected Clan: %s", TEAM2);
		                SendClientMessage(playerid, COLOR_YELLOW, ctxt);
					   	return TEAM_2;
					}
 			  	 }
			  }
			}
      		SendClientMessage(playerid, COLOR_YELLOW, "Clan not detected, Set as REF!");
			return TEAM_REF;
		}
		return 0;
}
		
/*
========================
	    Commands
========================
*/

public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/scores", true)==0)
	{
	new sstring[256], sstring2[256];
	
	format(sstring, sizeof(sstring), "%s: %d Kills", TEAM1, sCount1);
	format(sstring2, sizeof(sstring2), "%s: %d Kills", TEAM2, sCount2);
	SendClientMessageToAllEx(COLOR_YELLOW, sstring);
	SendClientMessageToAllEx(COLOR_YELLOW, sstring2);
	return 1;
	}
	
	else if(strcmp(cmdtext, "/reset", true)==0)
	{
		if(IsPlayerConnected(playerid) && IsPlayerAdmin(playerid))
		{
		SendClientMessageToAllEx(COLOR_YELLOW, "Clan War Reset!");
		sCount1 = 0;
		sCount2 = 0;
		for(new i=0;i<MAX_PLAYERS;i++)
		{
			TogglePlayerControllable(i,1);
			SpawnPlayer(i);
			DeathCount[i] = 0;
			SetPlayerScore(i, 0);
		}
		}
	}
		
	else if(strcmp(cmdtext, "/help", true)==0)
	{
	SendClientMessage(playerid, COLOR_YELLOW, "/scores, /reset(Admin Only)");
	return 1;
	}
	
/* /ME COMMAND
*/
	if(!strcmp(cmdtext, "/me", true, 3)) // 3 is the length of /me
 	{
 		if(cmdtext[3] == 0) {
 		    SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /me [text]");
 		    return 1;
		}
		new str[128];
		new playerColor = GetPlayerColor(playerid);
  		GetPlayerName(playerid, str, sizeof(str));
  		format(str, sizeof(str), "%s %s", str, cmdtext[4]);
		SendClientMessageToAll(playerColor, str);
		return 1;
	}

	return 1;
	}


/*
=========================
TogglePlayerControllable
=========================
*/

public iFreeze()
{
for(new i=0;i<MAX_PLAYERS;i++)
	{
	    if(IsPlayerConnected(i))
		{
		TogglePlayerControllable(i,0);
		}
	}
}

/*
========================
     String Defines
========================
*/

strtok(const string[],valve)
{
	new index=valve;
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

stock SendClientMessageToAllEx(color,msg[])
{
	SendClientMessageToAll(color,msg);
	CallRemoteFunction("explain", "s", msg);
}