how to make a soldier aotumaticly be general when the general dies ?
#1

can anyone help me with this ?
Reply
#2

Pick a random id?
Then on that ids death?
Get it to choose a diffrent one?
Im not sure quite what your wanting here
Reply
#3

Quote:
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
look its like , , a president and a vice president . when the president dies the vice president has to be president , so how to do it ?
Reply
#4

Untested but i think this is what you are looking for.

Code was updated see: http://forum.sa-mp.com/index.php?top...7586#msg887586
Code:

Reply
#5

Quote:
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);
}
but i need it fo general and soldier , so i only change teh name of the teams , , right ? and where do i put this ?
Reply
#6

What do you use to save the players team and ranks?
Reply
#7

Quote:
Originally Posted by KnooL
What do you use to save the players team and ranks?
Yah we need to know more about how your code is setup to help you.
Reply
#8

guys look i got a commander , then the if the commander dies , the general with the most points , the most kills , automaticly becomes commander , , do you knopw what i mean ?
Reply
#9

Yes, and the code i gave you should work, just make a loop to find the soldier with the highest score.

I don't know exactly how your team system works, but you should be able to modify my code to fit.

Other than showing us your team system we can't do much more.
Reply
#10

hey but how to find the highest score of the player and when the general dies the soldier becomes general , ok i know hte code for it , how about the loop or what erver you said , how to find it . peace
out
and thanks
Reply
#11

The poster pm'd me regarding this issue. From our convo it looks like I have provided a solution, will post it once its confirmed.
Reply
#12

Here is the final code.
NOTE:
This is a rather simplified version of a teams system made for a specific purpose. Generally team systems can be made very efficiently using a binary system which merges all team and status data into one variable. There are many premade team systems out there, this one was just to help this person with what they wanted, and learning pawn code without going through binary team systems.

pawn Code:
#include <a_samp>
#define teamA 0
#define teamB 1
pawn Code:
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
}
Reply
#13

ok i did this for team 0 , 1 how about to do this for team 2 , 3 ? what do i have to cahnge ? and thanks for help
Reply
#14

I was going to show you and advanced system, but instead I am just going to let you learn it yourself.
Common its not that hard. If you can't learn to script you shouldn't run a server.

All you have to do is add more teams, using 2, 3, 4, 5, ....
And increase the size of the sargeant array from 2(teams) to however many you have.
Reply
#15

.. i know how to make teams , u just putt the number at the end , and but i dont know what to change to the thing u gave me , for 2 other teams , u know what i mean ? .........
Reply
#16

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.
Reply
#17

Quote:
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.
lol .. u realy confuse me with all these stufff ......... i dont know waht to change to the code u gave me , lol and i have the other teams and .. what do i cahnge ..
Reply
#18

You have as many teams as you want.

Currently when someone joins you say playerTeam[playerid] = 0;(or 1)
So if you want another team just say playerTeam[playerid] = 2;(or 3,4,5,6,7.......)

So you can set it to ANY team, even like.

But as you have a sargent on each team sargeants[2]; you will need to increase this to the number of teams.
So if you have a third team, team 2, you need to put it as sargents[3];

I will be honest, if this doesn't make sense yet, you probably should go to the samp wiki and start reading tutorials.
Reply
#19

i think i got it no , so u have just to change the number after seargeant to the team i want to ? i think i got it .... ok thanks anyway
Reply
#20

Yah so if you are going to set up to say 4 teams (0,1,2,3) then set the number to 4.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)