AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Any idea why this makes the game crash? (https://forums.alliedmods.net/showthread.php?t=332483)

finishlast 05-15-2021 10:55

Any idea why this makes the game crash?
 
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(entitySDKHook_SpawnPostOnSpawnPost);
}

bool IsValidEntityIndex(int client)
{
    return (
MaxClients+<= client <= GetMaxEntities());
}


/****************************************************************************************************/

public void OnSpawnPost(int entity)
{
    
RequestFrame(OnNextFrameEntIndexToEntRef(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(entityProp_Data"m_ModelName"sModelsizeof(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

                
}


            }
        
    }





andi67 05-15-2021 15:03

Re: Any idea why this makes the game crash?
 
Precache your model OnMapStart.
..

cravenge 05-15-2021 23:39

Re: Any idea why this makes the game crash?
 
You can't change the pills' model by force but what you can do is make it invisible and attach a decoy entity to it with the model you want.

finishlast 05-16-2021 05:28

Re: Any idea why this makes the game crash?
 
1 Attachment(s)
The innitial crash was in fact the wrong precache, silly me, thank you Andi67.

As for the model change I gave up on replacing the pills attached to the body bc - unlike Silvers, Lux, Marttt and all the other pros - I am too dump to figure out how this stuff works with all this attach entity decoy stuff hahaha

I thought that it is possible to "just" replace the pills that lie on the ground, after the survivor dies but unfortunatelly it is not working as expected.

I only managed to replace all the pills on the map with this approach but not the pills that lie on the ground after death, even though I dont understand the difference between those pills.

andi67 05-16-2021 07:06

Re: Any idea why this makes the game crash?
 
Well, get the position of the player, loop through the entitys with FindEntityByClassname , create new entity with CreateEntityByName with your model, remove the original model, teleport your new created entity to the last position than use SDKHooks to detect if someone touched it. Should not so hard to get this working....


All times are GMT -4. The time now is 16:30.

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