PDA

View Full Version : how to make a soldier aotumaticly be general when the general dies ?


AlbanianGuy
23/01/2010, 12:14 AM
can anyone help me with this ?

Torran
23/01/2010, 12:46 AM
Pick a random id?
Then on that ids death?
Get it to choose a diffrent one?
Im not sure quite what your wanting here

AlbanianGuy
23/01/2010, 12:48 AM
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 ?

mansonh
23/01/2010, 04:18 AM
Untested but i think this is what you are looking for.

Code was updated see: http://forum.sa-mp.com/index.php?topic=147863.msg887586#msg887586

AlbanianGuy
23/01/2010, 06:21 AM
Untested but i think this is what you are looking for.


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 ?

KnooL
23/01/2010, 06:55 AM
What do you use to save the players team and ranks?

mansonh
23/01/2010, 08:00 AM
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.

AlbanianGuy
23/01/2010, 08:15 PM
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 ?

mansonh
23/01/2010, 10:05 PM
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.

AlbanianGuy
23/01/2010, 10:46 PM
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

mansonh
24/01/2010, 12:33 PM
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.

mansonh
24/01/2010, 09:34 PM
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.


#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
}

AlbanianGuy
24/01/2010, 11:57 PM
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

mansonh
25/01/2010, 10:23 PM
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.

AlbanianGuy
25/01/2010, 10:25 PM
.. 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 ? .........

mansonh
25/01/2010, 10:52 PM
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.

AlbanianGuy
26/01/2010, 02:41 AM
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 ..

mansonh
26/01/2010, 03:27 AM
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.

AlbanianGuy
26/01/2010, 03:39 AM
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

mansonh
26/01/2010, 04:31 AM
Yah so if you are going to set up to say 4 teams (0,1,2,3) then set the number to 4.

AlbanianGuy
26/01/2010, 04:32 AM
wit hte last one you just conused me ... and another thing confuses me is that , u know how about those == -1 , what are these ? do i have to change them ?

mansonh
26/01/2010, 07:24 AM
This is why we have the -1

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;
}
}
So at the beginning of the game, whoever spawns fisrt becomes sargent.

AlbanianGuy
26/01/2010, 06:37 PM
.. lol whats wit hte president again ... lol

mansonh
26/01/2010, 08:55 PM
Again just copied it from the old script, changed!

AlbanianGuy
26/01/2010, 10:28 PM
HAHAHa you are a funny guy , hahah , well i dont even know what to do now .......... :lol:

mansonh
26/01/2010, 11:09 PM
Well I don't know how else to explain it.
So maybe http://wiki.sa-mp.com/

AlbanianGuy
26/01/2010, 11:12 PM
ah cmon , can u do it for the other pair too , pls

mansonh
27/01/2010, 05:40 AM
You need to learn sometime.
Its really not that hard to change. Really really easy.

I don't know how much easier to say it, i basically told you exactly what to write.

When you set player team just use another number for your new teams you have 0 and 1, just use 2 ,3 ,4 ,... for however many teams you have.

Then set Sargents[4] = {-1,-1,-1,-1}; //for 4 teams.

Seriously how hard is that.

Go to the samp wiki and learn how to script:
Are you a scripting beginner? (http://forum.sa-mp.com/index.php?topic=2750.0)

I am trying to be nice here, but if you can't follow such a simple script, then you really need to go back to basics.

Is samp pawn your first language? cause then i would understand, its a hard first language.

AlbanianGuy
27/01/2010, 06:07 AM
ahhh u are making my life harder .. look but for which teams is this for new sargeants[2]={-1,-1}; ?
for the first 2 ?
and to make it for other treas i put hte number if the first one ? ... :mrgreen:

Kinetic
27/01/2010, 06:24 AM
Honestly I think that if you cant handle this, you need to practice on something of a lower caliber. If you ever want to learn any kind of coding, don't rely on people to give it to you. And especially when a code is given, dont ask for more. If I were mansonh, I would just let this guy figure it out by himself, cuz he has already helped out a ton.

AlbanianGuy
27/01/2010, 06:54 AM
Honestly I think that if you cant handle this, you need to practice on something of a lower caliber. If you ever want to learn any kind of coding, don't rely on people to give it to you. And especially when a code is given, dont ask for more. If I were mansonh, I would just let this guy figure it out by himself, cuz he has already helped out a ton.



.................... he is helping me because i realy need help ....

mansonh
27/01/2010, 07:49 AM
No I am not making your life harder.
if(Give someone a peice of code) they will come back when it breaks && you failed to teach them;
else if(Give someone the instructions to do it themselves)
{
If(They learn) they are coders;
else they are not;
}

I am trying to help you, but if you cannot/not willing to learn and figure things out yourself, then I cannot help you. This is a very simple peice of code to understand, and as Kenetic said, you need to practice on something of a lower caliber.

I am guessing that this is your first programming language. I would seriously suggest something easier:
http://www.python.org/ is a very good language to start learning on.
http://www.python.org/doc/2.5.2/tut/tut.html

AlbanianGuy
27/01/2010, 08:04 AM
ok i think i got it ... and htanks very much ! and i got another question . how to put balance between teams ?

mansonh
27/01/2010, 08:14 AM
Wherever you set the player teams, check if the teams are balanced.
Theres lots of team balancing code out there. heres just one simple example:

http://forum.sa-mp.com/index.php?topic=140197.msg848134#msg848134

AlbanianGuy
29/01/2010, 02:22 AM
hey , i just tested the" how to make the soldier , sargeant , and the player , doesnt respawn as sargeant .. it just says , the sargean has died ,, (this guy )is now sargeant .. and the guy who has to be sargeant doesnt become sargeant ...and do u know how to make players like , the sargeant to now be chosen anymore .. after on player odes, and ot send to playerid message , the sargeant isnt avaliable , you will spawn as police , (in case the player pushes LEFTSHIFT to spawn he spawns as police , only when hte sargeant isnt avaliable ? pls pls pls pls psl , help , me , and can i ask u one question , why u dont want to help me ,a nd let me figure it out by myselff, cuz i dont have a clue...........

Jonny5
13/05/2012, 03:35 PM
hes already helped you! 4 pages of help i see.
he just about wrote your hole code for you and if you cant be bothered to
read and learn yourself then no one will help!

The point was you dont have a clue! Like you just said, that means go get a clue!
read the wiki, pawn language ref, tutorials ect..

Stop trying to script a server when you are not a scripter!
Learn to script first then try to write a server...