Skip to content

Commit 0439bd6

Browse files
committed
improve model reset
1 parent 1190e82 commit 0439bd6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

api_player_model.sma

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public Native_SetPlayerSequence(iPluginId, iArgc) {
9898
public client_connect(pPlayer) {
9999
copy(g_rgszCustomPlayerModel[pPlayer], charsmax(g_rgszCustomPlayerModel[]), NULL_STRING);
100100
copy(g_rgszDefaultPlayerModel[pPlayer], charsmax(g_rgszDefaultPlayerModel[]), NULL_STRING);
101+
copy(g_rgszCurrentPlayerModel[pPlayer], charsmax(g_rgszCurrentPlayerModel[]), NULL_STRING);
102+
g_rgiPlayerAnimationIndex[pPlayer] = 0;
103+
g_rgbPlayerUseDefaultModel[pPlayer] = true;
101104
}
102105

103106
public Message_ClCorpse(iMsgId, iMsgDest, pPlayer) {
@@ -158,31 +161,34 @@ public @Player_UpdateAnimationModel(this) {
158161
new iAnimationIndex = is_user_alive(this) ? GetAnimationIndexByAnimExt(szAnimExt) : 0;
159162
if (iAnimationIndex != g_rgiPlayerAnimationIndex[this]) {
160163
g_rgiPlayerAnimationIndex[this] = iAnimationIndex;
161-
@Player_UpdateModel(this);
164+
@Player_UpdateModel(this, false);
162165
}
163166
}
164167

165168
public @Player_UpdateCurrentModel(this) {
169+
new bool:bUsedDefault = g_rgbPlayerUseDefaultModel[this];
170+
166171
g_rgbPlayerUseDefaultModel[this] = false;
167172

168173
if (equal(g_rgszCustomPlayerModel[this], NULL_STRING)) {
169174
if (!equal(g_rgszDefaultPlayerModel[this], NULL_STRING)) {
170175
static szModel[MAX_RESOURCE_PATH_LENGTH];
171176
format(szModel, charsmax(szModel), "models/player/%s/%s.mdl", g_rgszDefaultPlayerModel[this], g_rgszDefaultPlayerModel[this]);
172177
copy(g_rgszCurrentPlayerModel[this], charsmax(g_rgszCurrentPlayerModel[]), szModel);
173-
g_rgbPlayerUseDefaultModel[this] = true;
174178
}
179+
180+
g_rgbPlayerUseDefaultModel[this] = true;
175181
} else {
176182
copy(g_rgszCurrentPlayerModel[this], charsmax(g_rgszCurrentPlayerModel[]), g_rgszCustomPlayerModel[this]);
177183
}
178184

179-
@Player_UpdateModel(this);
185+
@Player_UpdateModel(this, !bUsedDefault && g_rgbPlayerUseDefaultModel[this]);
180186
}
181187

182-
public @Player_UpdateModel(this) {
188+
public @Player_UpdateModel(this, bool:bForce) {
183189
new iAnimationIndex = g_rgiPlayerAnimationIndex[this];
184190

185-
if (!g_rgbPlayerUseDefaultModel[this] || iAnimationIndex) {
191+
if (bForce || !g_rgbPlayerUseDefaultModel[this] || iAnimationIndex) {
186192
new iModelIndex = engfunc(EngFunc_ModelIndex, g_rgszCurrentPlayerModel[this]);
187193
@Player_SetModelIndex(this, iAnimationIndex ? iAnimationIndex : iModelIndex);
188194
set_pev(g_pPlayerModel[this], pev_modelindex, iAnimationIndex ? iModelIndex : 0);
@@ -216,7 +222,7 @@ public @Player_SetSequence(this, const szSequence[]) {
216222
}
217223

218224
g_rgiPlayerAnimationIndex[this] = iAnimationIndex;
219-
@Player_UpdateModel(this);
225+
@Player_UpdateModel(this, false);
220226

221227
new iSequence = GetSequenceIndex(szSequence);
222228
set_pev(this, pev_sequence, iSequence);

0 commit comments

Comments
 (0)