AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved cs_set_user_model (https://forums.alliedmods.net/showthread.php?t=329986)

lexzor 01-15-2021 13:21

cs_set_user_model
 
Hello! I have this code

PHP Code:

ublic plugin_init(){
    
register_logevent("taskdo"2"1=Round_Start"
}

public 
taskdo(id){
    
    
set_task(1.0"skincheck")
    
}

public 
skincheck(id){
    
    if(
is_user_alive(id)){
        
        new 
iSkin[32]
        
        
cs_get_user_model(idiSkincharsmax(iSkin))
        
        if (
equaliiSkin"fbi" ) || equali iSkin"sias" )){
            
            if ( 
cs_get_user_team(id) == CS_TEAM_T ){
                
                
cs_reset_user_model(id)
                
                switch(
checkT[id]){
                    
                    case 
1:{
                        
                        
cs_set_user_model(id"isis")
                        
                        
checkPS[id] = 1
                        
                    
}
                    
                    case 
2:{
                        
                        
cs_set_user_model(id"alqaeda")
                        
                        
checkPS[id] = 2
                        
                    
}
                    
                }
                
                
            }
            } else if  (
equaliiSkin"isis" ) || equali iSkin"alqaeda" )){
            
            if( 
cs_get_user_team(id) == CS_TEAM_CT ){
                
                
cs_reset_user_model(id)
                
                switch(
checkCT[id]){
                    
                    case 
1:{
                        
                        
cs_set_user_model(id"fbi")
                        
                        
checkPS[id] = 3
                        
                    
}
                    
                    case 
2:{
                        
                        
cs_set_user_model(id"sias")
                        
                        
checkPS[id] = 4
                        
                    
}
                    
                }
                
            }
            
        }
        
    } else 
ColorChat(0GREEN"^x04[%s]^x01 Player is not alive!" )
    


The problem is that the output is this
PHP Code:

ColorChat(0GREEN"^x04[%s]^x01 Player is not alive!" 

I don't know why is not working :|

OciXCrom 01-15-2021 15:21

Re: cs_set_user_model
 
Because there's no "id" defined anywhere so it's 0. Even if you did put it in set_task, "round start" is a global event and there is no "id".
Why are you doing this in "round start" instead of "player spawn" event?

lexzor 01-17-2021 01:28

Re: cs_set_user_model
 
because player spawn would give me an server console error that say "Invalid player 1" or any other number. i will try something and i will repost it here

lexzor 01-17-2021 01:40

Re: cs_set_user_model
 
Ok, i tried what u said to me and now it's working. but i have another question.

it's neccesarly to use "cs_reset_user_model" before "cs_set_user_model" or i can just use set user model

lexzor 01-17-2021 03:30

Re: cs_set_user_model
 
also, i have another problem.

skin "alqaeda" is a model for terrorist

if i have that model enabled when i'm terrorist. some players see me as a default counter-terrorist models.

I don't have the same problem as them and i don't know why this is happening. what should i do ? this is skincheck code

PHP Code:

public plugin_init() {
    
RegisterHam(Ham_Spawn"player""skincheck"1
}

public 
skincheck(id){    
    if(
is_user_alive(id) && get_user_flags(id) & VIP_FLAG){    
        
cs_reset_user_model(id)        
        if ( 
cs_get_user_team(id) == CS_TEAM_T ){            
            switch(
checkT[id]){                
                case 
1:{                    
                    
cs_set_user_model(id"isis")                
                    
checkPS[id] = 1                    
                
}
                
                case 
2:{                    
                    
cs_set_user_model(id"alqaeda")                    
                    
checkPS[id] = 2                    
                
}                
            }            
            } else if( 
cs_get_user_team(id) == CS_TEAM_CT ){            
            switch(
checkCT[id]){                
                case 
1:{                    
                    
cs_set_user_model(id"fbi")                    
                    
checkPS[id] = 3                    
                
}
                
                case 
2:{                    
                    
cs_set_user_model(id"sias")                    
                    
checkPS[id] = 4                    
                
}                
            }            
        }        
    }



OciXCrom 01-17-2021 07:47

Re: cs_set_user_model
 
Quote:

Originally Posted by lexzor (Post 2732913)
because player spawn would give me an server console error that say "Invalid player 1" or any other number. i will try something and i will repost it here

What's the logic behind that?! I always use PlayerSpawn to set player models. If you check if the user is alive, you can't possibly get an "invalid player" error.

Quote:

Originally Posted by lexzor (Post 2732914)
Ok, i tried what u said to me and now it's working. but i have another question.

it's neccesarly to use "cs_reset_user_model" before "cs_set_user_model" or i can just use set user model

Can the player have 2 player models at once? Obviously cs_set_user_model replaces the previous one and "reset" is pointless.

Quote:

Originally Posted by lexzor (Post 2732914)
also, i have another problem.

skin "alqaeda" is a model for terrorist

if i have that model enabled when i'm terrorist. some players see me as a default counter-terrorist models.

I don't have the same problem as them and i don't know why this is happening. what should i do ? this is skincheck code

Show the code where you precache the models, if you even do it. If not, that's the problem.
Or you didn't upload the files on your server/downloadurl or players use "cl_minmodels 1".

lexzor 01-17-2021 07:56

Re: cs_set_user_model
 
PHP Code:

new playerskins[][] = {
    
"sias",
    
"fbi",
    
"isis",
    
"alqaeda"
}

public 
plugin_precache(){
    static 
playermodels[256]
    
    for (new 
0sizeof(playerskins) -1i++){    
        
formatex(playermodelscharsmax(playermodels), "models/player/%s/%s.mdl"playerskins[i], playerskins[i])    
        
precache_model(playermodels)    
    } 


i deleted all models from my cs folder and now i get same problem. the skin isn't event there, the folder doesn t exist in my models folder, but he exists in server models. how is this even possible ?

OciXCrom 01-17-2021 07:57

Re: cs_set_user_model
 
Why "sizeof - 1"? There's your problem. The last skin isn't registered because of the "-1".
Also, I'd suggest using a better function to handle this:

Code:
precache_player_model(const szModel[], &id = 0) {     new model[128]     formatex(model, charsmax(model), "models/player/%s/%sT.mdl", szModel, szModel)     if(file_exists(model))         id = precache_generic(model)     static const extension[] = "T.mdl"     #pragma unused extension     copy(model[strlen(model) - charsmax(extension)], charsmax(model), ".mdl")     return precache_model(model) }

Some models have an additional T.mdl file. This one takes it in mind, plus it only requires the model name as an argument, same as "cs_set_user_model".

lexzor 01-17-2021 08:12

Re: cs_set_user_model
 
Thank you! that -1 was the problem. Thank you a lot man.


All times are GMT -4. The time now is 14:07.

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