AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get last player joined (https://forums.alliedmods.net/showthread.php?t=281457)

EFFx 04-11-2016 16:39

get last player joined
 
How can i pick-up the last player joined in X team?

Can you guys help?

siriusmd99 04-11-2016 16:50

Re: get last player joined
 
I can make this script for You but i want to ask:
If last player disconnects then the last player will Be the precedent?

EFFx 04-11-2016 16:58

Re: get last player joined
 
Like, when I talk /last, will show in the chat player who came by last in time., When he gets out, someone will go in his place, and will be the last.
Example, has five players on a team and six on the other, take the last player on the team who is 6 and amostre chatting.
If have 7 take the last and the penultimate, and so on.

Freezo Begin 04-11-2016 18:16

Re: get last player joined
 
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <ColorChat> #define PLUGIN "xxx" #define VERSION "1.0" #define AUTHOR "Freezo aka Spawner" new Trie:playersTeam; new getUsername[32]; new i; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_clcmd("say /last", "getLastJoinedP")         register_event( "TeamInfo", "joinTeam", "a")         playersTeam = TrieCreate();     } public getLastJoinedP(id){             if(TrieGetCell(playersTeam, getUsername, i)){         ColorChat(id, GREY, "^1The Last player Join the server is ^4= ^3%s ", getUsername)         // do ur extra stuff here     }     } public joinTeam(){         new id;id = read_data(1);     new choosedTeam[19];         get_user_name(id, getUsername, charsmax(getUsername));         read_data(2, choosedTeam, charsmax(choosedTeam));         TrieSetCell(playersTeam, getUsername, ++i)     } public plugin_end() {     TrieDestroy(playersTeam) }

Edit:
Note : This can be done without Trie & also i didn't specify the last in Terro and the last in CT.

EFFx 04-11-2016 18:49

Re: get last player joined
 
Quote:

Originally Posted by Freezo Begin (Post 2410236)
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <ColorChat> #define PLUGIN "xxx" #define VERSION "1.0" #define AUTHOR "Freezo aka Spawner" new Trie:playersTeam; new getUsername[32]; new i; public plugin_init() { &nbsp;&nbsp;&nbsp;&nbsp;register_plugin(PLUGIN, VERSION, AUTHOR) &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;register_clcmd("say /last", "getLastJoinedP") &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;register_event( "TeamInfo", "joinTeam", "a") &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;playersTeam = TrieCreate(); &nbsp;&nbsp;&nbsp;&nbsp; } public getLastJoinedP(id){ &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;if(TrieGetCell(playersTeam, getUsername, i)){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;ColorChat(id, GREY, "^1The Last player Join the server is ^4= ^3%s ", getUsername) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;// do ur extra stuff here &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp; } public joinTeam(){ &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;new id;id = read_data(1); &nbsp;&nbsp;&nbsp;&nbsp;new choosedTeam[19]; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;get_user_name(id, getUsername, charsmax(getUsername)); &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;read_data(2, choosedTeam, charsmax(choosedTeam)); &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;TrieSetCell(playersTeam, getUsername, ++i) &nbsp;&nbsp;&nbsp;&nbsp; } public plugin_end() { &nbsp;&nbsp;&nbsp;&nbsp;TrieDestroy(playersTeam) }


Edit:
Note : This can be done without Trie & also i didn't specify the last in Terro and the last in CT.

Working perfectly, but how i said, i want to know if is T or CT.
One more feature, set the guy to spectator.


Like this :D

PHP Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <ColorChat>
 
#define PLUGIN "xxx"
#define VERSION "1.0"
#define AUTHOR "Freezo aka Spawner"
 
new Trie:playersTeam;
new 
getUsername[32];
new 
id2id3,id4
new i;
new 
TeamLimit];
 
public 
plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
register_concmd("amx_set_limit""getLastJoinedP",ADMIN_RCON,"<ammount1> <ammount2> - Set a limit")
 
 
register_event"TeamInfo""joinTeam""a")
 
 
playersTeam TrieCreate();
 
}
public 
getLastJoinedP(id,ilevel,icid)
{
 if(!
cmd_access(id,ilevel,icid,3)) return PLUGIN_HANDLED
 
 
new LimitTR], LimitCT];
 
read_argv1LimitTR,  charsmaxLimitTR  ) );
 
read_argv2LimitCTcharsmaxLimitCT ) );
 
 
TeamLimit] = is_str_numLimitTR  ) ? str_to_num(LimitTR  ) : -1;
 
TeamLimit] = is_str_numLimitCT ) ? str_to_numLimitCT ) : -1;
 
 if( 
TeamLimit] < && TeamLimit] < )
 {
  
console_printid"You need to add one ammount over of 0." );
  return 
PLUGIN_HANDLED;
 }
 
 if(
TrieGetCell(playersTeamgetUsernamei))
 {
  if(
get_user_team(id2) == 1)
  {
   static 
playersT[32],iNumT
   get_players
(playersT,iNumT,"eh","TERRORIST")
   if(
iNumT TeamLimit])
   {
    for(new 
0;i<iNumT;i++)
    {
     
user_silentkill(id3)
     
cs_set_user_team(id3,CS_TEAM_SPECTATOR)
    }
    
client_print_color(idGREY"^4[AMXX]^1: The Last player Join the server is the Terrorist ^4%s",getUsername)
    
client_print_color(0,RED,"^4[AMXX]^1:^3 %s^1 has been transfered to the^3 SPECTATOR!"getUsername)
   }
  }
  else if(
get_user_team(id2) == 2)
  {
   static 
playersCT[32],iNumCT
   get_players
(playersCT,iNumCT,"eh","CT")
   if(
iNumCT TeamLimit])
   {
    for(new 
0;i<iNumCT;i++)
    {
     
user_silentkill(id4)
     
cs_set_user_team(id4,CS_TEAM_SPECTATOR)
    }
    
client_print_color(idGREY"^4[AMXX]^1: The Last player Join the server is the Counter-Terrorist ^4%s",getUsername)
    
client_print_color(0,BLUE,"^4[AMXX]^1:^3 %s^1 has been transfered to the^3 SPECTATOR!"getUsername)
   }
  }
 }
 return 
PLUGIN_HANDLED
}
public 
joinTeam()
{
 
id2 read_data(1);
 
id3 read_data(1);
 
id4 read_data(1);
 new 
choosedTeam[19];
 
 if(
get_user_team(id2) == 1)
 {
  
get_user_name(id3getUsernamecharsmax(getUsername));
 }
 else if(
get_user_team(id2) == 1)
 {
  
get_user_name(id4getUsernamecharsmax(getUsername));
 }
 
read_data(2choosedTeamcharsmax(choosedTeam));
 
 
TrieSetCell(playersTeamgetUsername, ++i)
 
}
public 
plugin_end()
{
 
TrieDestroy(playersTeam)


But i cant remove the two last players, Example, have 7 players, i cant transfer 2, only 1.

EFFx 04-11-2016 20:03

Re: get last player joined
 
Edit: Fixed

EFFx 04-16-2016 18:41

Re: get last player joined
 
What you want say HamletEagle? Have you a better code?

Black Rose 04-17-2016 14:43

Re: get last player joined
 
He probably wanted to say that tries in this case are wasted resources.
This is how you sort players.

The last player doing something will be at 0, next one will be at 1 and so on...

Code:
new gPlayers[33]; public jointeam(id) { // This is psuedocode...     new pos = DoesExist(gPlayers, sizeof gPlayers, id);     if ( pos == -1 )         pos = sizeof gPlayers - 1;     for ( new i = pos ; i ; i-- )         gPlayers[i] = gPlayers[i - 1];     gPlayers[0] = id; } public client_disconnect(id) {     new pos = DoesExist(gPlayers, sizeof gPlayers, id);     if ( pos == -1 )         return;     for ( new i = pos ; i < sizeof gPlayers - 1 ; i++ )         gPlayers[i] = gPlayers[i + 1];     gPlayers[sizeof gPlayers - 1] = 0; } DoesExist(haystack[], size, needle) {     for ( new i = 0 ; i < size ; i++ ) {         if ( haystack[i] == needle)             return i;     }     return -1; }

Here's a little example on how the code is doing things to help explain it.
Code:

Scenario:
Player 1 joins
Player 2 joins
Player 3 joins
Player 4 joins

Player 2 changes teams.

Player 3 leaves.

Adding (joining):
1
|
V
0->0->0->0->0->0 ...


2
|
V
1->0->0->0->0->0 ...


3
|
V
2->1->0->0->0->0 ...


4
|
V
3->2->1->0->0->0 ...


Moving up (changing teams):
2
|
V
4->3->2  1  0  0 ...


Removing (leaving game):
2  4  3<-1<-0<-0  ...
      |
      V


Result:
2  4  1  0  0  0 ...


EFFx 04-17-2016 14:54

Re: get last player joined
 
Ah, but i fixed the plugin, thank you guys for try to help me.
Karma

Hectik17 05-23-2016 21:35

Re: get last player joined
 
Quote:

Originally Posted by EFFx (Post 2411926)
Ah, but i fixed the plugin, thank you guys for try to help me.
Karma

hey is this a plugin to make the teams limmitmax to 5? and anyone else that trys to join a team is transferd to spec?

im looking for a working team limiter or a team lock plugin and this looks like i could use it to solve my problem, all the other teamlock/limit plugins are not working. would you happen to have teh full working .sma of this pluging i can use? been looking for somthing like this that works for allmost a year now, im having the problem of players joining my pug matches and stacking teh teams 5 - 6 players and i constantly have to kick them. its so anoying, please help Thanks!


All times are GMT -4. The time now is 18:40.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.