AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Change user skin (https://forums.alliedmods.net/showthread.php?t=282330)

skz 05-04-2016 14:07

Change user skin
 
Hi guys, I have a own menu for changing team in my server and personalized skins, and with instant auto team balance, even with the player models of connor, sometimes some users have T skin on CT side, or CT skin on T side...

I tryed this way to fix it, and it works, but when the server have a lot of players there, sometimes some players overflow...

PHP Code:

public new_round()
{    
    for(new 
i33i++)  
    {
        if(
is_user_connected(i))
        { 
            
set_task(3.0"models"i)
        }
    }
}

public 
models(id)
{
    if(
is_user_connected(id))
    {
        if ( 
cs_get_user_team(id) == CS_TEAM_CTcs_set_user_model(id"azul_ws")
        if ( 
cs_get_user_team(id) == CS_TEAM_Tcs_set_user_model(id"vermelho_ws")
    }
    
    
remove_task(id)


Is there a better way to make this? I already tryed with saving the user team in a variable and in the next round if he his in another team, change the skin, but it doesn't work because sometimes the player change team, and instant auto team ballance puts them in the other team again and they will have the skin of the team he changed...
I already tryed to save in a bool if the user was team ballanced but it doesnt work and I dont know why...

siriusmd99 05-04-2016 14:50

Re: Change user skin
 
if(is_user_connected(id))

you forgot to add is_user_alive(id)

are you going to set models on dead players?

And before setting task, remove if another has been set

if(is_user_connected(i))
{
if(task_exists(i))
remove_task(i)
set_task(3.0, "models", i)
}

EFFx 05-04-2016 15:08

Re: Change user skin
 
If is for all players, add:

PHP Code:

set_task(3.0,"models")

public 
models()
{
       new 
players[32],inum
       get_players
(players,inum,"a")
       for(new 
0;i<inum;i++)
       {
            if(
cs_get_user_team(players[i]]) == CS_TEAM_T)
            {
                    
cs_set_user_model(players[i], "vermelho_ws")
            }
            else if(
cs_get_user_team(players[i]) == CS_TEAM_CT)
            {
                   
cs_set_user_model(players[i],"azul_ws")
            }
      }



siriusmd99 05-04-2016 15:19

Re: Change user skin
 
Quote:

Originally Posted by EFFx (Post 2416635)
If is for all players, add:

PHP Code:

set_task(3.0,"models")

public 
models()
{
       new 
players[32],inum
       get_players
(players,inum,"a")
       for(new 
0;i<inum;i++)
       {
            if(
cs_get_user_team(players[i]]) == CS_TEAM_T)
            {
                    
cs_set_user_model(players[i], "vermelho_ws")
            }
            else if(
cs_get_user_team(players[i]) == CS_TEAM_CT)
            {
                   
cs_set_user_model(players[i],"azul_ws")
            }
      }



Yes, it's better , no need to make task for every player but you missed something.

At the topic of the plugin :

PHP Code:

#define TASK_SETMODEL 5632 //or any numbers you want 

then :

PHP Code:

if(task_exists(TASK_SETMODEL))
remove_task(TASK_SETMODEL)
set_task(3.0,"models"TASK_SETMODEL


And you can use :

PHP Code:

switch(cs_get_user_team(players[i]){
case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws")
case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws")


It wont call function cs_get_user_team 2 times if first returns false.

skz 05-04-2016 15:37

Re: Change user skin
 
overflowed as same

skz 05-04-2016 16:40

Re: Change user skin
 
PHP Code:

public new_round()
{    
    new 
players[32],inum 
    get_players
(players,inum,"c"
    for(new 
0;i<inum;i++) 
    { 
        if(
task_exists(TASK_SETMODEL))  remove_task(TASK_SETMODEL
        
set_task(3.0,"models"TASK_SETMODEL)  
    }
}

public 
models() 

    new 
players[32],inum 
    get_players
(players,inum,"a"
    for(new 
0;i<inum;i++) 
    { 
        switch(
cs_get_user_team(players[i]))
        { 
            case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws"
            case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws"
        } 
    }  
    
remove_task(TASK_SETMODEL)


this way worked, thanks for your help! :)

siriusmd99 05-04-2016 16:45

Re: Change user skin
 
Quote:

Originally Posted by skz (Post 2416673)
PHP Code:

public new_round()
{    
    new 
players[32],inum 
    get_players
(players,inum,"c"
    for(new 
0;i<inum;i++) 
    { 
        if(
task_exists(TASK_SETMODEL))  remove_task(TASK_SETMODEL
        
set_task(3.0,"models"TASK_SETMODEL)  
    }
}

public 
models() 

    new 
players[32],inum 
    get_players
(players,inum,"a"
    for(new 
0;i<inum;i++) 
    { 
        switch(
cs_get_user_team(players[i]))
        { 
            case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws"
            case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws"
        } 
    }  
    
remove_task(TASK_SETMODEL)


this way worked, thanks for your help! :)


Yes, but remove get players and loop at round start event :D

Use this code:

PHP Code:

public new_round()
{    
    
   if(
task_exists(TASK_SETMODEL))  remove_task(TASK_SETMODEL
   
set_task(3.0,"models"TASK_SETMODEL)  
    
}

public 
models() 

    new 
players[32],inum 
    get_players
(players,inum,"a"
    for(new 
0;i<inum;i++) 
    { 
        switch(
cs_get_user_team(players[i]))
        { 
            case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws"
            case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws"
        } 
    }  
    
remove_task(TASK_SETMODEL)



EFFx 05-04-2016 17:01

Re: Change user skin
 
You're right, sirius, if is for all players, dont need get_players because functions that have not a id, like models() dont need that and set_task(TASK_SETMODEL), just add set_task(3.0,"models")

Like

PHP Code:

public new_round() 
{     
   
set_task(3.0,"models")   
     


public 
models()  
{  
    new 
players[32],inum  
    get_players
(players,inum,"a")  
    for(new 
0;i<inum;i++)  
    {  
        switch(
cs_get_user_team(players[i])) 
        {  
            case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws")  
            case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws")  
        }  
    }   



siriusmd99 05-04-2016 17:12

Re: Change user skin
 
No, we need ID because if there happens new round before 3 seconds passed then function will be called again.

Like :
new round, set task
after 1 second:
new round, set task
After 2 seconds - function, after 1 second - function.
It just calls the function too frequent and early.

skz 05-06-2016 16:35

Re: Change user skin
 
PHP Code:

public new_round()
{    
    if(
task_exists(TASK_SETMODEL))  remove_task(TASK_SETMODEL
    
set_task(3.0,"models"TASK_SETMODEL)  
}

public 
models() 

    new 
players[32],inum 
    get_players
(players,inum,"a"
    for(new 
0;i<inum;i++) 
    { 
        switch(
cs_get_user_team(players[i]))
        { 
            case 
CS_TEAM_Tcs_set_user_model(players[i], "vermelho_ws"
            case 
CS_TEAM_CTcs_set_user_model(players[i],"azul_ws"
        } 
    }  
    
remove_task(TASK_SETMODEL)


It continues to give overflow to all players on the round start :(


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

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