Raised This Month: $51 Target: $400
 12% 

Pick A Random Player Bug on Start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-19-2023 , 15:28   Pick A Random Player Bug on Start
Reply With Quote #1

whenever my plugin is on (amx_pugin 1), it will transfer all players to CT and then pick a random player and transfer him to T. (one vs all CT)

here is the method:

PHP Code:
public PickARandomPlayer()
{
    new 
playersT[32], playersCT[32], numTnumCT
    get_players
(playersT,numT,"e","TERRORIST")
    for(new 
i=0;i<numT;i++)
        
cs_set_user_team(playersT[i],CS_TEAM_CT)

    
get_players(playersCT,numCT,"e","CT")
        
newTerror playersCT[random_num(0,numCT-1)]
    
cs_set_user_team(newTerror ,CS_TEAM_T)

sometimes, when there are only two players on the map and both are T, if I turn on the plugin, it will give this error:

Run time error 10: native error (native "cs_set_user_team")

then I will transfer myself to CT and will re-turn on the plugin again and it will work.

where is the problem and how to avoid such issue?
__________________
To Infinity n Beyond

Last edited by Cuttlas; 12-19-2023 at 15:29.
Cuttlas is offline
Old 12-19-2023, 21:14
Bugsy
This message has been deleted by Bugsy.
Natsheh
Veteran Member
Join Date: Sep 2012
Old 12-20-2023 , 02:40   Re: Pick A Random Player Bug on Start
Reply With Quote #2

Indent your code and add curly brackets to the for loop the compiler is not that smart to determine when the loop ends....

And try again..
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 12-20-2023 at 02:41.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 12-20-2023 , 07:07   Re: Pick A Random Player Bug on Start
Reply With Quote #3

If you are guaranteed to have players on both teams, why not just pick a player that's already a t to skip instead of switching him twice?
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-21-2023 , 00:23   Re: Pick A Random Player Bug on Start
Reply With Quote #4

Not tested, if I understand correctly that would be it.

Code:
public PickARandomPlayer()
{
        if(getRandomPlayer() != 0)
        {
                new iPlayers[32], iNum, id
                get_players(iPlayers, iNum)
                for(new i = 0; i < iNum; i++)
                {
                        id = iPlayers[i]

                        if(cs_get_user_team(id) == CS_TEAM_CT || cs_get_user_team(id) == CS_TEAM_UNASSIGNED)
                                continue

                        cs_set_user_team(id, CS_TEAM_CT)
                }

                new iTarget = getRandomPlayer()

                if(iTarget)
                {
                        cs_set_user_team(iTarget ,CS_TEAM_T)
                }
        }
} 

getRandomPlayer()
{
        new iPlayers[MAX_PLAYERS], iNum
        get_players(iPlayers, iNum, "e", "CT")

        if(!iNum)
                return 0

        return iPlayers[random(iNum)]
}
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-21-2023 , 15:13   Re: Pick A Random Player Bug on Start
Reply With Quote #5

still the same error:

Run time error 10: native error (native "cs_set_user_team")
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-21-2023 , 18:24   Re: Pick A Random Player Bug on Start
Reply With Quote #6

PHP Code:

#include <amxmodx>
#include <cstrike>

new const Version[] = "0.1";

enum PlayerData
{
    
SlotID,
    
CsTeams:CSTeam
}

public 
plugin_init() 
{
    
register_plugin"Solo T vs CT" Version "bugsy" );
    
    
register_clcmd"say setteams" "Set_Solo_T_vs_CT" );
}

public 
Set_Solo_T_vs_CTid )
{
    new 
iPlayersMAX_PLAYERS ] , iPlayingPlayersMAX_PLAYERS ][ PlayerData ] , iNum;
    new 
iRandomIndex iPlayer iRandom CsTeams:cstTeam iPlayingPlayersCount;
    
    
//Get all players in the iPlayers array.
    
get_playersiPlayers iNum );
    
    
//Loop through players and load iPlayingPlayers array with those who are on a team
    
for ( new iNum i++ )
    {
        
iPlayer iPlayers];
        
        
//If player is on a team, add to iPlayingPlayers array and increment iPlayingPlayersCount counter
        
if ( CS_TEAM_T <= ( cstTeam cs_get_user_teamiPlayer ) ) <= CS_TEAM_CT )
        {
            
iPlayingPlayersiPlayingPlayersCount ][ SlotID ] = iPlayer;
            
iPlayingPlayersiPlayingPlayersCount ][ CSTeam ] = cstTeam;
            
iPlayingPlayersCount++;
        }
    }
    
    
//We need at least 2 players
    
if ( iPlayingPlayersCount )
    {
        
//Select a random player who will be the solo T
        
iRandomIndex randomiPlayingPlayersCount );
        
iRandom iPlayingPlayersiRandomIndex ][ SlotID ];
        
        
//Move randomly selected solo T to T only if not already a T
        
if ( iPlayingPlayersiRandomIndex ][ CSTeam ] != CS_TEAM_T )
            
cs_set_user_teamiRandom CS_TEAM_T );
        
        
//Loop through remaining players and send them to CT, or do nothing if already CT
        
for ( new iNum i++ )
        {
            
iPlayer iPlayingPlayers][ SlotID ];
            
            
//Only move the player to CT if its not therandom player
            
if ( iPlayer != iRandom )
            {
                
//Only move to CT if not already a CT
                
if ( iPlayingPlayers][ CSTeam ] != CS_TEAM_CT )
                    
cs_set_user_teamiPlayer CS_TEAM_CT );
            }
        }
    }
    else
    {
        
client_printid print_chat "* There is not enough players to set solo T vs all CT." );
    }
    
    return 
PLUGIN_HANDLED;

__________________

Last edited by Bugsy; 12-21-2023 at 19:47.
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-22-2023 , 16:29   Re: Pick A Random Player Bug on Start
Reply With Quote #7

@Bugsy thank you, bro, worked very well

but we have a tag mismatch warning on: iPlayingPlayers[ iPlayingPlayersCount ][ CSTeam ] = cstTeam;
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-22-2023 , 17:07   Re: Pick A Random Player Bug on Start
Reply With Quote #8

Did you change anything? It compiles clean for me. I would not post code with compile errors or warnings.

Code:
AMX Mod X Compiler 1.9.0.5271
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2013 AMX Mod X Team

Header size:            368 bytes
Code size:             1360 bytes
Data size:              592 bytes
Stack/heap size:      16384 bytes
Total requirements:   18704 bytes
Done.
__________________

Last edited by Bugsy; 12-22-2023 at 17:08.
Bugsy is offline
Cuttlas
Senior Member
Join Date: Jan 2015
Old 12-23-2023 , 00:13   Re: Pick A Random Player Bug on Start
Reply With Quote #9

I'm using amxmodx 1.8.2 bro
__________________
To Infinity n Beyond
Cuttlas is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-23-2023 , 00:20   Re: Pick A Random Player Bug on Start
Reply With Quote #10

Upgrade your server

You can try this:
PHP Code:
iPlayingPlayersiPlayingPlayersCount ][ CSTeam ] = CsTeams:cstTeam
if that doesn't work, try
PHP Code:
enum _:PlayerData
{
    
SlotID,
    
CsTeams:CSTeam

__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:43.


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