23.01.2010, 00:14
can anyone help me with this ?
|
Originally Posted by Torran
Pick a random id?
Then on that ids death? Get it to choose a diffrent one? Im not sure quite what your wanting here |
|
Originally Posted by mansonh
Untested but i think this is what you are looking for.
Code:
new President= -1;
public OnPlayerSpawn(playerid)
{
if(President==-1)
{
President=playerid;
}
}
public OnPlayerDisconnect(playerid, reason)
{
if(playerid == President)
{
SelectNewPresident(playerid, "disconnected");
}
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(playerid == President)
{
SelectNewPresident(playerid, "died");
}
}
stock SelectNewPresident(PreviousPres, reason[])
{
new playerid;
while(President==PreviousPres)
{
playerid = Random(MAX_PLAYERS-1);
if(IsPlayerConnected(playerid))
{
President==playerid;
}
}
new msg[128], new prevName[24], newName[24];
GetPlayerName(PreviousPres, prevName, sizeof(prevName));
GetPlayerName(President, newName, sizeof(newName));
format(msg, sizeof(msg), "President %s has %s, %s has become President", prevName, reason, newName);
SendClientMessageToAll(0xDEEE20FF, msg);
}
|
|
Originally Posted by KnooL
What do you use to save the players team and ranks?
|
peace #include <a_samp>
#define teamA 0
#define teamB 1
new playerTeam[MAX_PLAYERS];//0 teamA , 1 teamB
new sargeants[2]={-1,-1};
//You need to set the players team on spawn or something however you set teams
//use playerTeam[playerid] = //team that you want;
public OnPlayerSpawn(playerid)
{
//Assuming team has already been chosen
if(sargeants[playerTeam[playerid]]==-1)
{
//Only get here if there is no sargeant yet
sargeants[playerTeam[playerid]]=playerid;
}
}
public OnPlayerDisconnect(playerid, reason)
{
if(sargeants[playerTeam[playerid]]==playerid)
{
SelectNewSargent(playerid, "disconnected");
}
}
public OnPlayerDeath(playerid, killerid, reason)
{
if(sargeants[playerTeam[playerid]]==playerid)
{
SelectNewSargent(playerid, "died");
}
}
stock SelectNewSargent(previousSarg, reason[])
{
new playerid, bestPID=-1, bestPScore=-1, team = playerTeam[previousSarg];
for(playerid=0; playerid<GetMaxPlayers(); playerid++)
{
if(IsPlayerConnected(playerid) && playerid != previousSarg &&
playerTeam[playerid]==team && GetPlayerScore(playerid) > bestPScore)
{
bestPID = playerid;
bestPScore = GetPlayerScore(playerid);
}
}
if(bestPID!=-1)
{
new msg[128], prevName[24], newName[24];
GetPlayerName(previousSarg, prevName, sizeof(prevName));
GetPlayerName(bestPID, newName, sizeof(newName));
format(msg, sizeof(msg), "Sargent %s has %s, %s has become Sargent", prevName, reason, newName);
for(playerid=0; playerid<GetMaxPlayers(); playerid++)
{
if(IsPlayerConnected(playerid) && playerTeam[playerid]==team)
SendClientMessage(playerid, 0xDEEE20FF, msg);
}
sargeants[team]=bestPID;
}//else Sargent stays Sargent as there are no other members
}
|
Originally Posted by mansonh
No i don't its pretty simple.
Add more teams, you can easily create any numbers of teams teams just by assigning aplayer to any team number you want playerTeam[playerid] = 9999999; Then just increase the side of sargents[2] to the max team number+1 many teams you have. Then the code should work. |