Raised This Month: $110 Target: $400
 27% 

Solved i need help to replace a prop model with custom one


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rory98
Junior Member
Join Date: Oct 2021
Old 10-20-2021 , 23:20   i need help to replace a prop model with custom one
Reply With Quote #1

i have searched the forum for script to change a prop model with a custom one,i found this,what im trying to do is to change the ammo pile model to a custom one
the code compile just fine, but the game wont load and crashes with this error :
588/ - weapon_ammo_spawn: UTIL_SetModel: not precached: models/witch_bowl/bowl.mdl

Code:
#include <sourcemod> 
#include <sdktools> 
#include <sdkhooks> 

public OnMapStart() 
{ 
    PrecacheModel("models/witch_bowl/bowl.mdl"); 
} 

public void OnEntityCreated(entity, const String:classname[]) 
{ 

    if ( StrEqual(classname, "weapon_ammo_spawn") ) 
    { 
        SDKHook(entity, SDKHook_SpawnPost, Hook_EntitySpawned); 
    } 
} 

public void Hook_EntitySpawned(entity) 
{ 
    if(IsValidEntity(entity)) 
    { 
        SetEntityModel(entity, "models/witch_bowl/bowl.mdl"); 
    } 
}
__________________
rory

Last edited by rory98; 10-22-2021 at 21:48.
rory98 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-21-2021 , 12:21   Re: i need help to replace a prop model with custom one
Reply With Quote #2

Which game? Is that a custom model?

Try using:
PHP Code:
PrecacheModel("models/witch_bowl/bowl.mdl"true); 
(added true parameter) but may not be related.
__________________
Marttt is offline
rory98
Junior Member
Join Date: Oct 2021
Old 10-21-2021 , 16:02   Re: i need help to replace a prop model with custom one
Reply With Quote #3

Quote:
Originally Posted by Marttt View Post
Which game? Is that a custom model?

Try using:
PHP Code:
PrecacheModel("models/witch_bowl/bowl.mdl"true); 
(added true parameter) but may not be related.
game is l4d, and yes its a custom model
i tried to add "true". and still same error
__________________
rory
rory98 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-21-2021 , 20:30   Re: i need help to replace a prop model with custom one
Reply With Quote #4

witch_bowl/bowl.mdl ? nope

Could you check your model path, one more time ?
You have model, in your server files AND in your own game files ?
__________________
Do not Private Message @me

Last edited by Bacardi; 10-21-2021 at 20:36.
Bacardi is online now
cravenge
Veteran Member
Join Date: Nov 2015
Location: Middle of Nowhere
Old 10-21-2021 , 23:22   Re: i need help to replace a prop model with custom one
Reply With Quote #5

Iirc, OnEntityCreated fires first before OnMapStart so precaching the model there might be already too late. Why not...
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)

    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"weapon_ammo_spawn") == 0
    { 
        
SDKHook(entitySDKHook_SpawnPostHook_EntitySpawned);
    }
}

public 
void Hook_EntitySpawned(int entity
{
    
// I think IsValidEntity is no longer needed here since all hooks get unhooked
    // automatically when the entity in question is destroyed
    
if (!IsModelPrecached("models/witch_bowl/bowl.mdl"))
    {
        
PrecacheModel("models/witch_bowl/bowl.mdl");
    }
    
SetEntityModel(entity"models/witch_bowl/bowl.mdl");

?
__________________

Last edited by cravenge; 10-21-2021 at 23:24.
cravenge is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-22-2021 , 05:21   Re: i need help to replace a prop model with custom one
Reply With Quote #6

You can try looping through all entities aswell as a workaround some seconds after OnMapStart:

PHP Code:
    int entity = -1;
    while ((
entity FindEntityByClassname(entity"weapon_ammo_spawn")) != -1)
    {
        
SetEntityModel(entity"models/witch_bowl/bowl.mdl");
    } 
__________________

Last edited by Marttt; 10-22-2021 at 05:22.
Marttt is offline
rory98
Junior Member
Join Date: Oct 2021
Old 10-22-2021 , 18:41   Re: i need help to replace a prop model with custom one
Reply With Quote #7

Quote:
Originally Posted by Bacardi View Post
witch_bowl/bowl.mdl ? nope

Could you check your model path, one more time ?
You have model, in your server files AND in your own game files ?
yes i double checked that, everything is on the right place.
__________________
rory
rory98 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-22-2021 , 19:58   Re: i need help to replace a prop model with custom one
Reply With Quote #8

Zip and upload model in your post
__________________
Do not Private Message @me
Bacardi is online now
rory98
Junior Member
Join Date: Oct 2021
Old 10-22-2021 , 21:43   Re: i need help to replace a prop model with custom one
Reply With Quote #9

Quote:
Originally Posted by cravenge View Post
Iirc, OnEntityCreated fires first before OnMapStart so precaching the model there might be already too late. Why not...
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)

    if (
entity || entity 2048)
    {
        return;
    }
    
    if (
strcmp(classname"weapon_ammo_spawn") == 0
    { 
        
SDKHook(entitySDKHook_SpawnPostHook_EntitySpawned);
    }
}

public 
void Hook_EntitySpawned(int entity
{
    
// I think IsValidEntity is no longer needed here since all hooks get unhooked
    // automatically when the entity in question is destroyed
    
if (!IsModelPrecached("models/witch_bowl/bowl.mdl"))
    {
        
PrecacheModel("models/witch_bowl/bowl.mdl");
    }
    
SetEntityModel(entity"models/witch_bowl/bowl.mdl");

?
it works as intended , thanks!
__________________
rory
rory98 is offline
rory98
Junior Member
Join Date: Oct 2021
Old 10-22-2021 , 21:47   Re: i need help to replace a prop model with custom one
Reply With Quote #10

Quote:
Originally Posted by Bacardi View Post
Zip and upload model in your post
i managed to solve it, thanks for reply
__________________
rory
rory98 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode