Help Script not working
#1

Код:
#include <a_samp>


#define TEAM1 1
#define TEAM2 2
#define TEAM1_COLOR 0xFF0000FF//Red
#define TEAM2_COLOR 0x008000FF //Green

new gTeam[MAX_PLAYERS];
new disSpawn;
new Text:Team1;
new Text:Team2;
new playercash;

forward SettingPlayerTeam();

main()
{
}
public OnGameModeInit()
{
	SetGameModeText("Test");
	AddPlayerClass(0, 0,0,0,0, 0, 0, 0, 0, 0, 0);
	AddPlayerClass(0, 0,0,0,0, 5, 0, 0, 0, 0, 0);
	SetTimer("SpawnTimer",30000,0);
	print("Starting timer...");
 	SetTimer("Timer", 30000, 0);

	new str[50];
 	format(str, sizeof(str), "Team1: %d", GetRemainingMembers(TEAM1));
 	Team1 = TextDrawCreate(0, 0, str);
 	format(str, sizeof(str), "Team2: %d", GetRemainingMembers(TEAM1));
 	Team2 = TextDrawCreate(0, 0, str);
 	return 1;
}
public OnPlayerConnect(playerid)
{
	SetPVarInt(playerid, "Dead", 0);
 	SetTimerEx("SettingPlayerTeam",10,1,"i",playerid);
  SetPVarInt(playerid, "UpdateTimer", SetTimerEx("UpdatePlayer", 2000, true, "i", playerid));
}
public OnPlayerDeath(playerid, killerid, reason)
{
	if(killerid == INVALID_PLAYER_ID) {
	SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
	ResetPlayerMoney(playerid);
	} else {
	SendDeathMessage(killerid,playerid,reason);
	SetPlayerScore(killerid,GetPlayerScore(killerid)+1);
	playercash = GetPlayerMoney(playerid);
	if (playercash > 0) {
		GivePlayerMoney(killerid, playercash);
		ResetPlayerMoney(playerid);
	}
  TogglePlayerSpectating(playerid, 1);
  PlayerSpectatePlayer(playerid, killerid);
	SetPVarInt(playerid, "Dead", 1);
	{
	}
	}
  if(GetTotalTeamMembers(TEAM1) == 0) //If Blue Team has no more players...
	{
  	SetTimer("GreenWin",10000,0);
	GiveMoneyToTeam(TEAM1, 10000);
    SendRconCommand("gmx");
	SendClientMessageToAll(0xFF0000FF, "Green Team has won!");
  }
  else if(GetTotalTeamMembers(TEAM2) == 0) //If Red Team has no more players..
	{
	SetTimer("RedWin",10000,0);
	GiveMoneyToTeam(TEAM2, 10000);
	SendRconCommand("gmx");
	SendClientMessageToAll(0xFF0000FF, "Red Team has won!");
  }
	return 1;
}

public OnPlayerSpawn(playerid)
{
	SetPlayerToTeamColor(playerid);
	SetPlayerHealth(playerid, 1);
 	if(disSpawn == 0)
	{
	SendClientMessage(playerid,0xFF0000AA,"Your are too late, you can't spawn anymore");
 	TogglePlayerSpectating(playerid, 1);
  PlayerSpectatePlayer(playerid,1);
	return 0;
	}
	UpdateTeamTDS();
	TextDrawShowForPlayer(playerid, Team1);
	TextDrawShowForPlayer(playerid, Team2);
	return 1;
}

stock UpdateTeamTDS()
{
	new str[50];
 	format(str, sizeof(str), "Team1: %d", GetRemainingMembers(TEAM1)); //Replace with your own team
	TextDrawSetString(Team1, str);
 	format(str, sizeof(str), "Team2: %d", GetRemainingMembers(TEAM2)); //...
	TextDrawSetString(Team2, str);
	return 1;
}

stock GetRemainingMembers(teamid)
{
	new tCount;
	for(new i=0; i<MAX_PLAYERS; i++)
	{
	  if(GetPlayerTeam(i) == teamid && GetPVarInt(i, "Dead") == 0)
		{
			tCount = i;
			break;
	  }
	}
	return tCount;
}

stock SetgTeam(playerid, teamid)
{
	SetPVarInt(playerid, "gTeam", teamid);
	return 1;
}

stock GetgTeam(playerid)
{
	return GetPVarInt(playerid, "gTeam");
}

stock GetTotalTeamMembers(teamid)
{
	new totalmembers[2];
	for(new x=0; x<MAX_PLAYERS; x++)
 	{
		if(teamid == TEAM1 && GetgTeam(x) == TEAM1)
		{
		  totalmembers[0] = x;
		}
		else if(teamid == TEAM2 && GetgTeam(x) == TEAM2)
		{
		  totalmembers[1] = x;
		}
	}
	return totalmembers[teamid];
}

stock GiveMoneyToTeam(teamid, amount)
{
	for(new x=0; x<MAX_PLAYERS; x++)
 	{
		if(teamid == TEAM1 && GetgTeam(x) == TEAM1)
		{
			GivePlayerMoney(x, amount);
		}
		else if(teamid == TEAM2 && GetgTeam(x) == TEAM2)
		{
			GivePlayerMoney(x, amount);
		}
	}

	return 1;
}


forward GameModeRestart();

public GameModeRestart()
{
	SendRconCommand ("gmx");
}

public OnGameModeExit()
{
  print("Gamemode ended.");
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1314.8419, 2114.5310, 11.0156);
	SetPlayerInterior(playerid, 0);
	SetPlayerFacingAngle(playerid, 34.7677);
	SetPlayerCameraPos(playerid, 1311.3419, 2118.5310, 12.5156);
	SetPlayerCameraLookAt(playerid, 1314.8419, 2114.5310, 11.0156);
	SetPlayerTeamFromClass(playerid, classid);
	return 1;
}

public OnPlayerDisconnect(playerid)
{
	//Kill the update timer for the player...
	KillTimer(GetPVarInt(playerid, "UpdateTimer"));
}

//Called every 2 seconds for a player
stock UpdatePlayer(playerid)
{
	new file[128];
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
	format(file, sizeof(file), "%s.ini", name);
 	new uCash = GetPlayerMoney(playerid);
	dini_IntSet(file,"AdminLevel", PlayerInfo[playerid][AdminLevel]);
 	dini_IntSet(file,"Cash", uCash);
 	dini_IntSet(file,"Kills", PlayerInfo[playerid][pKills]);
  	dini_IntSet(file,"Deaths", PlayerInfo[playerid][pDeaths]);
  	dini_IntSet(file,"Locked", PlayerInfo[playerid][pLocked]);
  	dini_IntSet(file,"Local", PlayerInfo[playerid][pLocal]);
  	dini_IntSet(file,"Int", PlayerInfo[playerid][pInt]);
  	return 1;
}

forward SetPlayerToTeamColor(playerid);

public SetPlayerToTeamColor(playerid)
{
	if (gTeam[playerid] == TEAM1)
	{
		SetPlayerColor(playerid, TEAM1_COLOR);
	}
	else if (gTeam[playerid] == TEAM2)
	{
		SetPlayerColor(playerid, TEAM2_COLOR);
	}
}

forward SetPlayerTeamFromClass(playerid, classid);

public SetPlayerTeamFromClass(playerid, classid)
{
	if (classid == 0)
	{
		gTeam[playerid] = TEAM1;
	}
	else
	{
		gTeam[playerid] = TEAM2;
	}
}

public SettingPlayerTeam()
{
  for(new playerid; playerid < 200; playerid++)
    SetPlayerTeam(playerid, gTeam[playerid]);
  return 1;
}
the text draw wont show for the team
just me : shows 0 for both team
2people on diff team: shows 1 for my team
2 people on same team: shows no textdraw

Reply
#2

pawn Код:
stock GetRemainingMembers(teamid)
{
    new tCount;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
      if(GetPlayerTeam(i) == teamid && GetPVarInt(i, "Dead") == 0)
        {
            tCount = i;
            break;
      }
    }
    return tCount;
}
This should increase the tCount var, so:
pawn Код:
tCount++; // Replace this with 'tCount = i'
Also, I highly suggest that you don't run that player update every 2 seconds. That is extremely unefficient.
Reply
#3

okay i changed it so now the problem is
just me spawned: shows 0 for both team
2 people on diff team : shows 1 for the team i am on
2 people on same team : shows 0 for both team
Reply
#4

bump?
Reply
#5

bump
dont i have to add it so when the player spawns the player team will go up by 1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)