Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precache_player_model #533

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions plugins/include/amxmisc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,30 @@ stock get_players_ex(players[MAX_PLAYERS], &num, GetPlayersFlags:flags = GetPlay
get_flags(_:flags, strFlags, charsmax(strFlags));
get_players(players, num, strFlags, team);
}

/**
* Precaches a player model file.
*
* @note Can only be used inside of the plugin_precache() forward.
* @note Also searches for a "T.mdl" file and precaches that one as well if found.
* @note Player models MUST be placed in the following directory:
* "models/player/%name%/%name%.mdl" where "name" is the name of the model.
*
* @param name Name of the model file without the .mdl extension (e.g. "admin")
* @param id Variable to store the "T.mdl" cache id if found
*
* @return Unique cache id of the model
* @error If called outside of the plugin_precache() forward, an error is
* thrown from the precache_model() native.
*/
stock precache_player_model(const name[], &id = 0)
{
new model[128];
formatex(model, charsmax(model), "models/player/%s/%sT.mdl", name, name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some models have t.mdl instead of T.mdl, this can be a problem on OS with case-sensitive filesystem (like Linux) rehlds/ReHLDS@6715402.


if(file_exists(model))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the way how it should be checked, you need to check if model really needs it rehlds/ReHLDS@9080b9b#diff-462e3f794ed90c12c86f5d8d5b725c4aR5405.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WPMGPRoSToTeMa Which I assume can't be done with a stock?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OciXCrom it can be done through the reading of model file.

id = precache_model(model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to precache it via precache_generic, because precache_generic doesn't have limit like precache_model (on ReHLDS).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WPMGPRoSToTeMa I changed it to generic.


replace_string(model, charsmax(model), "T.mdl", ".mdl");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this way, it works because GoldSrc allows only one dot in file path. Imagine if model path is models/player/superT.mdl/superT.mdl.mdl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WPMGPRoSToTeMa I changed it to check the last characters only

return precache_model(model);
}