Raised This Month: $ Target: $400
 0% 

Acomodar IDs, Re ordenar todo en una variable


  
 
 
Thread Tools Display Modes
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 03-26-2013 , 22:38   Re: Acomodar IDs, Re ordenar todo en una variable
#21

PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "[R]ak"


public plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
set_task(3.0"test")
    
}

public 
test() {
        
    const 
MAX_ID 10
    
    
new SuperID[MAX_ID] = {
        
7,
        
5,
        
2,
        
1,
        
27,
        
3,
        
4,
        
6,
        
8,
        
9
        
    
}
    
    new 
i;
    
    for(
0sizeof SuperIDi++)
        
server_print("ID %d = %d"iSuperID[i])
        
    new 
RandSuperID[MAX_ID], TotalIDRandNum
    
    
for(0sizeof RandSuperIDi++) {
        
        
TotalID rak_get_total_id(SuperIDsizeof SuperID)
        
        
RandNum random(TotalID)
        
        
RandSuperID[i] = SuperID[RandNum]
        
        
SuperID[RandNum] = 0
        
    
}        
    
    
server_print("*-----------------------------------------------*")
    
    
server_print("*-----------------------------------------------*")
    
    for(
0sizeof SuperIDi++)
        
server_print("ID %d = %d"iRandSuperID[i])
        
}

stock rak_get_total_id(Data[], size) {
    
    new 
i
    
    rak_sortID
(Datasize)
    
    for(
0sizei++)
        if(!
Data[i])
            break
            
    return 
i
    
}

stock rak_sortID(Data[], size) {
    
    for(new 
isizei++) {
        
        if(!
Data[i] && != size -1) {
            
            for(new 
i+1sizez++) {
                
                if(
Data[z]) {
                    
                    
Data[i] = Data[z]
                    
                    
Data[z] = 0
                    
                    
break;
                    
                }
            }
        }
    }

output
Code:
ID 0 = 7
ID 1 = 5
ID 2 = 2
ID 3 = 1
ID 4 = 27
ID 5 = 3
ID 6 = 4
ID 7 = 6
ID 8 = 8
ID 9 = 9
*-----------------------------------------------*
*-----------------------------------------------*
ID 0 = 27
ID 1 = 9
ID 2 = 3
ID 3 = 4
ID 4 = 7
ID 5 = 2
ID 6 = 6
ID 7 = 8
ID 8 = 1
ID 9 = 5
__________________

www.amxmodx-es.com

Steam: Luchokoldo
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 03-26-2013 , 22:44   Re: Acomodar IDs, Re ordenar todo en una variable
#22

Asi que, lo que quiere es que desordenen las celdas de g_SpecStatus que sean mayores a 0 y los que estan en 0 dejarlos de ultimas?

Last edited by XINLEI; 03-26-2013 at 22:45.
XINLEI is offline
LeeanAndNeka
Senior Member
Join Date: Feb 2012
Location: Argentina ♥
Old 03-26-2013 , 22:50   Re: Acomodar IDs, Re ordenar todo en una variable
#23

Mañana lo adapto y comento como me fue. Gracias shinoda, Xinlei y rak

Quote:
Originally Posted by XINLEI View Post
Asi que, lo que quiere es que desordenen las celdas de g_SpecStatus que sean mayores a 0 y los que estan en 0 dejarlos de ultimas?
Quiero obtener ids al azar (Solo espectadores) y guardarlos en la variable sin que haya ningun 0 de por medio (0 seria vacio).

Last edited by LeeanAndNeka; 03-26-2013 at 22:53.
LeeanAndNeka is offline
Send a message via MSN to LeeanAndNeka Send a message via Skype™ to LeeanAndNeka
Old 03-26-2013, 22:52
LeeanAndNeka
This message has been deleted by LeeanAndNeka.
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 03-26-2013 , 23:07   Re: Acomodar IDs, Re ordenar todo en una variable
#24

Quote:
Originally Posted by LeeanAndNeka View Post
Quiero obtener ids al azar (Solo espectadores) y guardarlos en la variable sin que haya ningun 0 de por medio (0 seria vacio).
En el titulo lo que quiere es que al desconectarse cambiar la celda(ID) a 0 y pasar el/los 0 a las ultimas celdas (de forma que los ultimos en el array sean los que tienen 0).

Me equivoco?
XINLEI is offline
LeeanAndNeka
Senior Member
Join Date: Feb 2012
Location: Argentina ♥
Old 03-27-2013 , 12:54   Re: Acomodar IDs, Re ordenar todo en una variable
#25

Acomodar IDs de manera random y una vez hecho esto ya no pasa por aca.. Cada ves el un usuario se desconecta le asigno 0 si estaba en algunas de las celdas del array como para dejarlo vacio. Y cuando otro se conecta lo pongo en el ultimo lugar (Sin contar los 0)
LeeanAndNeka is offline
Send a message via MSN to LeeanAndNeka Send a message via Skype™ to LeeanAndNeka
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 03-27-2013 , 13:57   Re: Acomodar IDs, Re ordenar todo en una variable
#26

Cuando se refiere a spec. Esta muerto? o se unió al server como espectador?
XINLEI is offline
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 03-27-2013 , 18:41   Re: Acomodar IDs, Re ordenar todo en una variable
#27

habla de unirse al servidor como espectador.. esta haciendo un "AutoMix" o como lo llaman tambien "PUG" hay 10 personas jugando y el resto entra de espectador y se le asigna una posición para poder ingresar en caso de que salga alguien q esta jugando; yo hice un automix y use directamente array dinamicas
__________________

www.amxmodx-es.com

Steam: Luchokoldo
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
LeeanAndNeka
Senior Member
Join Date: Feb 2012
Location: Argentina ♥
Old 03-27-2013 , 19:17   Re: Acomodar IDs, Re ordenar todo en una variable
#28

Que mal estoy con esto ultimamente u.u
PHP Code:
#include <amxmodx>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "[R]ak"

#define is_valid_player(%1) (1 <= %1 <= MaxPlayers)
new MaxPlayers


public plugin_init() {
    
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
MaxPlayers get_maxplayers()
    
set_task(10.0"test")
    
}

public 
test() 
{
    const 
MAX_ID 10
    
new SuperID[MAX_ID]
    
    new 
i;
    
    for(
0sizeof SuperIDi++)
        
log_to_file("Pruebas.txt""ID %d = %d"iSuperID[i])
    
    new 
RandSuperID[MAX_ID], TotalIDRandNum
    
    
for(0sizeof RandSuperIDi++)
    {
        
        
TotalID rak_get_total_id(SuperIDsizeof SuperID)
        
        
RandNum random(TotalID)
        
        
log_to_file("Pruebas.txt""GET TOTAL ID = %d^nRANDNUM = %d^nSUPERID[RANDNUM] = "TotalIDRandNum)
        
        
RandSuperID[i] = SuperID[RandNum]
        
        
SuperID[RandNum] = 0
        
    
}        
    
    
log_to_file("Pruebas.txt""*-----------------------------------------------*")
    
    
log_to_file("Pruebas.txt""*-----------------------------------------------*")
    
    for(
0sizeof SuperIDi++)
        
log_to_file("Pruebas.txt""ID %d = %d"iRandSuperID[i])
    
}

stock neqi_get_specs(Data[], size)
{
    
    new 
iPlayers32 ], iNumber
    
new RandomPlayerz
    get_players
(iPlayersiNumber)
    
    for(new 
0iNumberi++)
    {
        if( 
is_valid_playeriPlayers] ) /*&& ( get_user_team2( iPlayers[ i ] ) == 3 )*/)
        {
            if( 
size )
            {
                
RandomPlayer get_user_useridiPlayers] )
                
Data] = RandomPlayer
                z
++
                continue;
            }
            break;
        }
        
    }
    
    
}



stock rak_get_total_id(Data[], size)
{
    
    new 
i
    neqi_get_specs
(Datasize)
    
rak_sortID(Datasize)
    
    for(
0sizei++)
        if(!
Data[i])
        break
    
    return 
i
    
}

stock rak_sortID(Data[], size)
{
    
    for(new 
isizei++)
    {
        if(!
Data[i] && != size -1
        {
            for(new 
i+1sizez++)
            {
                if(
Data[z]) 
                {
                    
Data[i] = Data[z]
                    
Data[z] = 0
                    
break;
                }
            }
        }
    }
}  

stock get_user_team2(id
{
    new 
szTeam[2]
    
get_user_teamidszTeam)
    switch( 
szTeam[0] ) 
    {
        case 
'T': return 1
        
case 'C': return 2
        
case 'S': return 3
    
}
    return 
0

OUTPUT
Code:
L 03/27/2013 - 20:11:05: ID 0 = 0
L 03/27/2013 - 20:11:05: ID 1 = 0
L 03/27/2013 - 20:11:05: ID 2 = 0
L 03/27/2013 - 20:11:05: ID 3 = 0
L 03/27/2013 - 20:11:05: ID 4 = 0
L 03/27/2013 - 20:11:05: ID 5 = 0
L 03/27/2013 - 20:11:05: ID 6 = 0
L 03/27/2013 - 20:11:05: ID 7 = 0
L 03/27/2013 - 20:11:05: ID 8 = 0
L 03/27/2013 - 20:11:05: ID 9 = 0
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: GET TOTAL ID = 1
RANDNUM = 0
SUPERID[RANDNUM] = 
L 03/27/2013 - 20:11:05: *-----------------------------------------------*
L 03/27/2013 - 20:11:05: *-----------------------------------------------*
L 03/27/2013 - 20:11:05: ID 0 = 7
L 03/27/2013 - 20:11:05: ID 1 = 7
L 03/27/2013 - 20:11:05: ID 2 = 7
L 03/27/2013 - 20:11:05: ID 3 = 7
L 03/27/2013 - 20:11:05: ID 4 = 7
L 03/27/2013 - 20:11:05: ID 5 = 7
L 03/27/2013 - 20:11:05: ID 6 = 7
L 03/27/2013 - 20:11:05: ID 7 = 7
L 03/27/2013 - 20:11:05: ID 8 = 7
L 03/27/2013 - 20:11:05: ID 9 = 7
LeeanAndNeka is offline
Send a message via MSN to LeeanAndNeka Send a message via Skype™ to LeeanAndNeka
shinoda
Spanish Moderator
Join Date: Nov 2009
Location: ag_crossfire
Old 03-27-2013 , 20:08   Re: Acomodar IDs, Re ordenar todo en una variable
#29

Mientras más detalles das, más díficil logro entenderte

Quote:
Originally Posted by LeeanAndNeka View Post
Fue un ejemplo que quiza quedo justo shinoda lo siento. Pero yo si tengo asi:
PHP Code:
g_SpecStatus] = 
g_SpecStatus
] = 12 
g_SpecStatus
] = 
g_SpecStatus
] = 24 
g_SpecStatus
] = 
g_SpecStatus
] = 

// DEBERIA QUEDAR ASI 

g_SpecStatus] = 
g_SpecStatus
] = 12 
g_SpecStatus
] = 24
g_SpecStatus
] = 1  
g_SpecStatus
] = 0  
g_SpecStatus
] = 0  

// CON TU METODO


g_SpecStatus] = 24
g_SpecStatus
] = 12 
g_SpecStatus
] = 8
g_SpecStatus
] = 1  
g_SpecStatus
] = 0  
g_SpecStatus
] = 
PHP Code:
stock zeros_end_arrayinput[], len )
{
    new 
j
    
    
for( new ileni++ )
    {
        if( 
input[i] )
        {
            
inputj++ ] = input]
        }
    }
    
    if( 
len )
    {
        
arraysetinput[j], 0len )
    }
    
    return 
j


Quote:
Originally Posted by LeeanAndNeka View Post
En esa funcion (Acomodarspecs) lo que quiero hacer es lo siguiente. Obtener el id de uno de los espectadores (al azar) y guardarlo en MiVariable[ 0 ], agarrar otro espectador y ponerlo en MiVariable[ 1 ] y asi, obviamente sin que se repita el id en ningun lugar xd
PHP Code:
stock copy_random_valuesinput[], max1output[], max2 )
{
    new 
temp max1
    
new = -1rand
    
    
do
    {
        if( ++
max2 )
            break
        
        
rand randomtemp )
        
output] = inputrand 
        
inputrand ] = input[ --temp ]
    }
    while( 
max1 )


Ejemplo:

PHP Code:
public plugin_cfg( )
{
    new 
input[ ] = { 0204056008}    
    new 
len zeros_end_arrayinputsizeof input )
    
    for( new 
isizeof inputi++ )
    {
        
server_print"[%i]: %i"iinput[i] )
    }
    
server_print"^n" )
    
    new 
output]
        
// En 2do parámetro es 'len' (devuelto por zeros_end_array) para evitar iteraciones innecesarias.
    
copy_random_valuesinputlenoutputsizeof output )
    
    for( new 
isizeof outputi++ )
    {
        
server_print"[%i] : %i"ioutput[i] )
    }

Nota que para usar el 2do stock, también es necesario usar el 1ro.
__________________
Oh hell no this shit is awesome !!!
shinoda is offline
Send a message via MSN to shinoda Send a message via Skype™ to shinoda
LeeanAndNeka
Senior Member
Join Date: Feb 2012
Location: Argentina ♥
Old 03-28-2013 , 15:09   Re: Acomodar IDs, Re ordenar todo en una variable
#30

Gracias shinoda por tu ayuda Ahora el problema es que no puedo hacer para llenar el array con los IDs de los usuarios conectados. Ejemplo: Hay 4 conectados (ID: 5, 11, 1, 9) y cuando ejecute la funcion quiero que primero los carge a esos IDs al azar, y que queden los 0 al final. Con el metodo de rak puedo obtener los ids normalmente sin que sea random, total despues los acomoda aleatoriamente solo. Probare, si alguien ve algo mal en neqi_get_specs de este reply https://forums.alliedmods.net/showpo...0&postcount=28 aviseme AJAJAJJA
LeeanAndNeka is offline
Send a message via MSN to LeeanAndNeka Send a message via Skype™ to LeeanAndNeka
 



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 06:14.


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