Raised This Month: $ Target: $400
 0% 

How to change grenade model in air?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
danonix
Senior Member
Join Date: Dec 2012
Old 08-26-2014 , 12:53   How to change grenade model in air?
Reply With Quote #1

Hello,

I would like to know if is it possible to change grenade model while it is in air, and if yes, how to do it.

For example, im throwing smoke grenade, so I would like to change it's model to HE GRENADE in air.

Thanks
danonix is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-26-2014 , 13:50   Re: How to change grenade model in air?
Reply With Quote #2

Quote:
Originally Posted by danonix View Post
Hello,

I would like to know if is it possible to change grenade model while it is in air, and if yes, how to do it.

For example, im throwing smoke grenade, so I would like to change it's model to HE GRENADE in air.

Thanks
Hook FM_SetModel and change grenade w_model.
You may need to do this things:

1. On grenade throw event set a bool to true when someone throw a smoke grenade.
2. In FM_SetModel check if the grenade is a sg( check the model or use m_usEvent ) and if bool is true, then set w_ model.
3. In FM_EmitSound check for smoke grenade explosion sound and reset this bool.
__________________

Last edited by HamletEagle; 08-26-2014 at 13:51.
HamletEagle is offline
danonix
Senior Member
Join Date: Dec 2012
Old 08-26-2014 , 14:46   Re: How to change grenade model in air?
Reply With Quote #3

Something like that?

PHP Code:
#include <csx>
#include <fakemeta>

#define W_MODEL "models/w_smokegrenade.mdl"
#define W__NEW_MODEL "models/w_smokegrenadenew.mdl"


new thrown

public 
plugin_precache(){
    
precache_model(W__NEW_MODEL);
    
precache_model(W_MODEL);
}
public 
grenade_throw(GrenadeID){
    if(
GrenadeID==CSW_SMOKEGRENADE){
        
thrown true;
    }
}


public 
fw_setmodel(ent, const model[])
{
    if(!
pev_valid(ent))

        return 
FMRES_IGNORED;

  
    if(
strcmp(W_MODEL,model) )

        return 
FMRES_IGNORED;

    static 
classname[32]
    
pev(ent,pev_classname,classname,31);

    if(
strcmp(classname"grenade") && thrown)
    {
        
engfunc(EngFunc_SetModelentW_NEW_MODEL)
        return 
FMRES_SUPERCEDE;

    }

    return 
FMRES_IGNORED;


danonix is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-26-2014 , 15:28   Re: How to change grenade model in air?
Reply With Quote #4

Default models don't need to be precached. Yeah, sth like you did, but you meed to reset thrown.
__________________

Last edited by HamletEagle; 08-26-2014 at 15:30.
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-26-2014 , 18:20   Re: How to change grenade model in air?
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
Default models don't need to be precached.
Well, let's clarify that statement (to prevent confusion to others). Models that have been precached already (for other purposes) don't need to be precached again. Not all "default models" are precached on every map. Grenade models are a special case where they actually are precached every map (for obvious reasons).

Where "default" is defined as anything that comes with a first install of the game.
__________________

Last edited by fysiks; 08-26-2014 at 18:22.
fysiks is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-26-2014 , 18:34   Re: How to change grenade model in air?
Reply With Quote #6

Just to say, in frostnades plugin (by Avalanche) it's made pretty accurate (I think), so you could take a look there.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
danonix
Senior Member
Join Date: Dec 2012
Old 08-27-2014 , 02:55   Re: How to change grenade model in air?
Reply With Quote #7

Thanks guys.

@Flick3r wanted to do something on my own :p
danonix is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 08-27-2014 , 04:39   Re: How to change grenade model in air?
Reply With Quote #8

That doesnt mean you shouldnt read the source file of existing, well written plugins to understand how things are done properly.
mottzi is offline
Send a message via MSN to mottzi
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-27-2014 , 07:17   Re: How to change grenade model in air?
Reply With Quote #9

Code:
new bool: g_bThrow new const W_MODEL[ ] = "models/w_smokegrenade.mdl" new const W__NEW_MODEL[ ] = "models/w_smokegrenadenew.mdl" public grenade_throw( id, greindex, wId ) {     if( greindex == CSW_SMOKEGRENADE )     {         g_bThrow = true     } } public pfnSetModel( iEnt, const model[] ) {     if( !pev_valid( iEnt) )     {         return FMRES_IGNORED     }         static szClassName[ 20 ]; pev( iEnt, pev_classname, szClassName, charsmax( szClassName ) )         if( equal( szClassName, "grenade" ) )     {             if( equal( model, W_MODEL ) )             {                 if( g_bThrow )                 {                        engfunc( EngFunc_SetModel, iEnt, W_NEW_MODEL )                        g_bThrow = false                 }             }     } }

You should try something like this
__________________
HamletEagle is offline
danonix
Senior Member
Join Date: Dec 2012
Old 08-27-2014 , 08:28   Re: How to change grenade model in air?
Reply With Quote #10

This will work similar to that what I Did, but with better code right?
danonix is offline
Reply



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 11:25.


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