SA-MP Forums Archive
Need someone to explain me - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Need someone to explain me (/showthread.php?tid=158115)



Need someone to explain me - [XST]O_x - 08.07.2010

Hey there people!

So I'm adding something to a DM script and I'm kind of stuck,I need some help.
Well the thing I'm trying to do is getting the player's position in the server,by the amount of kills.
This is what I have under OnPlayerDeath:
pawn Код:
pInfo[killerid][Kills]++;
    pInfo[playerid][Deaths]++; // Doesn't matter at the moment
Well firstly I need to know a way to get how much players are connected,and then getting the position of the player by the amount of his kills.

Any help appreciated.


Re: Need someone to explain me - CAR - 08.07.2010

So you want to know who has got the most kills in a list with from high to low or something?

pawn Код:
new Pname[24];
for(new i; i<MAX_PLAYERS; i++)
{
   GetPlayerName(i, Pname, 24);
   if(pInfo[i][Kills] >= otherones)....
}
Lol, I started with something but I don't know... sorry


Re: Need someone to explain me - [XST]O_x - 08.07.2010

Quote:
Originally Posted by CAR
Посмотреть сообщение
So you want to know who has got the most kills in a list with from high to low or something?

pawn Код:
new Pname[24];
for(new i; i<MAX_PLAYERS; i++)
{
   GetPlayerName(i, Pname, 24);
   if(pInfo[i][Kills] >= otherones)....
}
Lol, I started with something but I don't know... sorry
So you don't know? xD..

Anyway no,what I meant is,I have three textdraws at the bottom of the screen,Kills,Deaths,and Position.

The position should be something like: PositionFromKills out of Number of Players,and should look like:
(if for example there are 7 players on the server)

3/7

Hope you got it now


Re: Need someone to explain me - CAR - 08.07.2010

All right but I don't know how to get the position of the playerid by all that stuff, maybe by kills...
pawn Код:
//top
new Position[MAX_PLAYERS];
new Text:Textdraw[MAX_PLAYERS];

//onplayerupdate or something
for(new i; i<MAX_PLAYERS; i++)
{
   if(pInfo[playerid][Kills] < playerid[i][Kills]) return Position[playerid]++;
}
TextdrawDestroy(Textdraw[playerid]);
Textdraw[playerid] = TextDrawCreate(100,100, Position[playerid]);
TextDrawShowForPlayer(Textdraw[playerid]);
Hope you got a little idea oh and OnPlayerConnect, you must set Position[playerid] = 1; because you get position 0 if you are first :P


Re: Need someone to explain me - [XST]O_x - 08.07.2010

Wait I don't get what you've given me,what is this code doing?
And what is GetPlayerName for? o.O


Re: Need someone to explain me - CAR - 08.07.2010

Oh I remove GetPlayerName, but the function is looking for someone who has got more kills than you and if someone gots the position goes lower, so if it's like this:
some3one 0 kills
You 1 kill
someone 2 kills
some2one 3 kills

You get 3 position because 2 people got more kills and 1 just not


Re: Need someone to explain me - [XST]O_x - 08.07.2010

So this is the part that gets how much players are in the server? xD
Sorry if I get on your nerves,I'm really confused right now o.O


Re: Need someone to explain me - CAR - 08.07.2010

Yeah this:
for(new i; i<MAX_PLAYERS; i++)
Checks all the players


Re: Need someone to explain me - Hiddos - 08.07.2010

I'd guess you'd need a loop inside a loop.

For the amount of players online, you can either loop through all players and, if they're connected, update a variable, or simply update it with OnPlayer(Dis)Connect.

Maybe a small example of what you could do with listing highest players above:

pawn Код:
new pOnline = 0;
public OnPlayerConnect(playerid)
{
  pOnline++;
  return 1;
}

public OnPlayerConnect(playerid,reason)
{
  pOnline--;
  return 1;
}

//Unsure about this, you might try to edit it. I'm not used to this.
new blub[MAX_PLAYERS]; // Why I named it that? No idea.
for(new i; i < MAX_PLAYERS; i++)
{
  if(!IsPlayerConnected(i)) continue;
  for(new bla; bla < MAX_PLAYERS; bla++)
  {
    if(GetPlayerMoney(playerid) > GetPlayerMoney(blub[bla]) && GetPVarInt(playerid,"Checked") != 1)
    {
      for(new bla2; bla2 < MAX_PLAYERS: bla2--)
      {
      while(bla != bla2) {
      if(bla2 == 0) continue;
      blub[bla2] = blub[bla2-1];
      }}
      blub[bla] = i;
      SetPVarInt(playerid,"Checked",1)
    }
  }
DeletePVar(i,"Checked")
Something like that. It won't be RAM-friendly, and it probably won't work either. But give it a try. This shows the ID with the highest amount of money in the first thingy (blub[0]) and the player with the lowest money in blub[499].

Be sure to check for non-connected players though

As for O_x: You and I share a lot in common for some reason. I'm confused as well.


Re: Need someone to explain me - [XST]O_x - 08.07.2010

Hiddos,your code is fatass xD
Thanks =P,
but can I change GetPlayerMoney to pInfo[playerid][Kills]?