View Single Post
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-14-2021 , 21:56   Re: player models bug
Reply With Quote #3

Quote:
Originally Posted by LondoN View Post
found the solution

new hModel[32];
formatex(hModel, charsmax(hModel), "%s", g_hDBModels[g_hPlayerModel]);
cs_set_user_model(id, hModel);

this is the solution.
Formatting with just "%s" is exactly the same as just using that variable directly (if you are not needing to edit the new string without changing the original string). If you really do need to copy the variable, as-is, use copy().

Also, avoid assigning strings to variables directly except when you declare variable with a default value. In fact, it's completely unnecessary to have those extra variable where you do this anyways. Just use the variables directly in parse:

PHP Code:
parse(szBufferg_hDBModels[g_hPlayerName], charsmax(g_hDBModels[g_hPlayerName]), g_hDBModels[g_hPlayerModel], charsmax(g_hDBModels[g_hPlayerModel])) 
Also, since you are not using g_hDBModels as a global variable, you shouldn't declare it as a global variable. Only declare it in the functions that use it. If it's in a function that is called often, you simply declare it in that function with "static" instead of "new".

Lastly, using MAX_PLAYERS for sizing your string arrays is confusing. You should either just use a number or create another, more aptly named define, to size those arrays. You shouldn't ever need to use that value ever again anyways because you should be using charsmax() anytime that you need to know the max length of a string for that variable or use sizeof() if you need a variable to have the same size as another variable.
__________________
fysiks is offline