Raised This Month: $51 Target: $400
 12% 

Change weapon models [ham]


Post New Thread Reply   
 
Thread Tools Display Modes
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 01-31-2012 , 11:29   Re: Change weapon models [ham]
Reply With Quote #11

Code:
/* Plugin generated by AMXX-Studio */ /* INI FILE */ /* "weapon_m4a1" "models/newmodel/m4a1.mdl" "weapon_ak47" "models/newmodel/ak47.mdl" */ #include <amxmodx> #include <amxmisc> #include <hamsandwich> #include <fakemeta> new i, g_size new EntName[ 64 ][ 64 ] new ModelName[ 64 ][ 64 ] public plugin_init() {         for( i = 0; i < g_size ; i++ )         RegisterHam( Ham_Item_Deploy, EntName[ i ] , "fwReplaceModels", 1); } public plugin_precache( ) {     load_settings( "models.ini" ); } load_settings( const File[] ) {     static szFilename[136];     static szPath[ 64 ];     get_configsdir(szPath, 63);     formatex(szFilename, 63, "%s/%s", szPath, File);         static szData[64]     static iLen     static iPos     iPos = 0;     while (read_file( szFilename, iPos++, szData,63,iLen))     {         remove_quotes(szData)         if (iLen == 0 || check_invalid_chars(szData) ) // Saltear linea si se encuentra un ; o # al principio             continue;                     parse( szData, EntName[g_size], charsmax(EntName), ModelName[g_size], charsmax(ModelName) );                 precache_model( ModelName[ i ] );                 g_size++     } } bool:check_invalid_chars( const string[] = " " ) {     if( string[0] == '#' || string[0] == ';' || (string[0] == '/' && string[1] == '/' ) )         return true; // se encontro un string invalido , por lo tanto returna con 1 ( true )         return false; // no se encontro nada , por lo tanto , returnea 0 (falso , no se encontro ningun dato)     } public fwReplaceModel( entity ) {     if( pev_valid( entity ) != 2 ) return HAM_IGNORED;         new id = get_pdata_cbase( entity, 41, 4 );         static entclass[32];     pev(entity, pev_classname, entclass, 31);         for( i = 0; i < g_size; i++ )     {         if( equal( entclass, EntName[ i ]) )             set_pev( id, pev_viewmodel2, ModelName[ i ] );             }         return HAM_IGNORED; }
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 01-31-2012 at 11:30.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-31-2012 , 11:54   Re: Change weapon models [ham]
Reply With Quote #12

Use the new file natives.
Trie would be more appropriate here.
Don't use static in a function called just one time.
Why 64 ? There are only 30 weapons if I'm right but again a trie would be better.
__________________

Last edited by Arkshine; 01-31-2012 at 11:55.
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-31-2012 , 11:59   Re: Change weapon models [ham]
Reply With Quote #13

You can try this one:
Attached Files
File Type: sma Get Plugin or Get Source (weapon_models.sma - 422 views - 1.6 KB)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 01-31-2012 , 12:45   Re: Change weapon models [ham]
Reply With Quote #14

I don't know how to use Tries , is any tutorial here or a explication about that?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-31-2012 , 12:58   Re: Change weapon models [ham]
Reply With Quote #15

Quote:
Originally Posted by lucas_7_94 View Post
I don't know how to use Tries , is any tutorial here or a explication about that?
Tries are basically arrays that are indexed by a string rather than a number.

Example:
Code:
// this is not legit AMXX code, just pseudo code set[0] = 1; // normal array way set["value"] = 1; // TrieSetCell set["value"] = "1"; // TrieSetString set["value"] = {1,2,3}; // TrieSetArray value = set["value"]; // TrieGetCell/String/Array if("value" in set) // TrieKeyExists

Think of Tries as Arrays and keys as indexes.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-31-2012 , 13:08   Re: Change weapon models [ham]
Reply With Quote #16

Exo, give me a example for weapon_models.ini please.
lqlqlq is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-31-2012 , 13:13   Re: Change weapon models [ham]
Reply With Quote #17

Example is in last link he gave you.

Version updated : https://forums.alliedmods.net/showth...74#post1641974
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Lolz0r
Veteran Member
Join Date: Nov 2010
Location: Balgaria
Old 01-31-2012 , 13:22   Re: Change weapon models [ham]
Reply With Quote #18

LOL thanks, but who plugin is better(ConnorMcLeod or Exolent[jNr] or lucas)?

Last edited by Lolz0r; 01-31-2012 at 15:14.
Lolz0r is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 01-31-2012 , 13:47   Re: Change weapon models [ham]
Reply With Quote #19

exolent, arkshine , or connor , or somebody , i made this.

Code:
public plugin_init() {         WeaponInfo[ 0 ] = TrieCreate( );     WeaponInfo[ 1 ] = TrieCreate( );         static what[32]             for( i = 0; i < g_size ; i++ )     {         RegisterHam( Ham_Item_Deploy, whathere, "fwReplaceModels", 1);     } } public plugin_precache( ) {     load_settings( "models.ini" ); } load_settings( const File[] ) {     new iFile = fopen( File, "rt" );     if( !iFile ) return;         new szBuffer[1024]     while( !feof( iFile ) )     {         fgets( iFile, szBuffer, charsmax( szBuffer ) );                 remove_quotes( szBuffer )                 if( check_invalid_chars(szBuffer) )             continue                 parse( szBuffer, classname, charsmax(classname), model, charsmax(model) );                 precache_model( model );                 TrieSetCell(WeaponInfo[ 0 ], classname, g_size)         TrieSetCell(WeaponInfo[ 1 ], model, g_size)         g_size++                     } }

But , how i can get the value from the trie in the loop ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-31-2012 , 13:58   Re: Change weapon models [ham]
Reply With Quote #20

Quote:
Originally Posted by ConnorMcLeod View Post
Example is in last link he gave you.
No, it's different than yours.

Quote:
Originally Posted by lqlqlq View Post
Exo, give me a example for weapon_models.ini please.
Mine has the classname with the associated view model:

Code:
"weapon_ak47" "models/custom_weapons/v_ak47.mdl"
Quote:
Originally Posted by lucas_7_94 View Post
But , how i can get the value from the trie in the loop ?
You are using the tries wrong.

Code:
new Trie:gWeaponModels; public plugin_precache( ) {     gWeaponModels = TrieCreate( );         load_settings( "models.ini" ); } load_settings( const File[] ) {     new iFile = fopen( File, "rt" );     if( !iFile ) return;         new szBuffer[1024]     while( !feof( iFile ) )     {         fgets( iFile, szBuffer, charsmax( szBuffer ) );                 remove_quotes( szBuffer )                 if( check_invalid_chars(szBuffer) )             continue                 parse( szBuffer, classname, charsmax(classname), model, charsmax(model) );                 precache_model( model );                 if( !TrieKeyExists( gWeaponModels, classname ) ) {             RegisterHam( Ham_Item_Deploy, classname, "FwdItemDeployPost", 1 );         }                 TrieSetString( gWeaponModels, classname, model );     } } public FwdItemDeployPost( entity ) {     new classname[ 32 ], model[ 64 ];     entity_get_string( entity, EV_SZ_classname, classname, charsmax( classname ) );         if( TrieGetString( gWeaponModels, classname, model, charsmax( model ) )     {         const m_pPlayer = 41;                 new id = get_pdata_cbase( entity, m_pPlayer, 4 );                 entity_set_string( id, EV_SZ_viewmodel, model );     } }

Some variables aren't defined in your load_settings() function, though.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 01-31-2012 at 14:03.
Exolent[jNr] 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:26.


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