I am trying to replace the pills model once it is created.
Like when a bot has pills and dies, it should replace the pills model that pops up with the one in the script.
But when I activate it, the game stucks and crashes.
When I comment out the SetEntityModel(entity, model); I can see in the echos that it sees the pill model when a bot dies. I just wonder why it would make the whole thing crash?!
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
if (!IsValidEntityIndex(entity))
return;
SDKHook(entity, SDKHook_SpawnPost, OnSpawnPost);
}
bool IsValidEntityIndex(int client)
{
return (MaxClients+1 <= client <= GetMaxEntities());
}
/****************************************************************************************************/
public void OnSpawnPost(int entity)
{
RequestFrame(OnNextFrame, EntIndexToEntRef(entity));
}
/****************************************************************************************************/
public void OnNextFrame(int entityRef)
{
//PrintToChatAll("*************************change*****************************");
int entity;
while((entity = FindEntityByClassname(entity, "weapon_pain_pills*")) > -1)
{
if(IsValidEntity(entity) )
{
char sModel[64];
GetEntPropString(entity, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
//PrintToChatAll("%s*************************change*****************************", sModel);
if(StrContains(sModel, "models/w_models/weapons/w_eq_painpills.mdl") > -1 )
{
PrintToChatAll("%s*************************change*****************************", sModel);
char model[256] = "models/props_interiors/toiletpaperroll.mdl";
//SetEntityModel(entity, model); //<- enabling this makes the game crash
}
}
}
}
__________________