Raised This Month: $52 Target: $400
 13% 

Solved changing v_ model


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Member
Join Date: Feb 2021
Location: Russia
Old 02-23-2021 , 08:26   changing v_ model
Reply With Quote #1

Hello guys! I have 2 questions (I know about 1 question per topic)
1) If i holding a knife, then typing "changeknife 1" in console, viewmodel isn't changing immediately. I need to change to any other weapon and then change back to knife. Is there any way to fix this?
2) Which weapon models can be changed via "entity_set_string(id, EV_SZ_viewmodel, modelname)"?
Here is the script i using:
PHP Code:
#include < amxmodx >
#include < engine >

new const models[][] = {
    
"models/v_knife.mdl",
    
"models/p_knife.mdl",
    
"models/v_knife_r.mdl"
}

enum _:udata {
    
knife
}

new 
UserData[33][udata]

public 
plugin_precache()
{
    for(new 
isizeof(models); i++)
        
precache_model(models[i])
}

public 
plugin_init() {
    
register_plugin ("knife changer""test""kww (yes)")
    
    
register_event ("CurWeapon""event_curweapon""be""1=1")
    
register_clcmd ("changeknife""xknife_handler")
}

public 
client_putinserver id ) {
    
UserData[id][knife] = 0
}

public 
xknife_handler(id) {
    new 
x_arg[16]
    
read_argv(1x_argcharsmax(x_arg))
    
    switch(
x_arg[0]) {
        case 
EOSclient_print(idprint_console"* Usage: changeknife <1|0> (now %i)"UserData[id][knife])
        case 
'0'UserData[id][knife] = 0
        
case '1'UserData[id][knife] = 1
    
}
    
client_print(idprint_console"%i", )
    return 
PLUGIN_HANDLED
}

public 
event_curweapon(id) {
    new 
wpn read_data(2)
    if (
wpn == CSW_KNIFE) {
        switch (
UserData[id][knife]) {
            case 
0:
            {
                
entity_set_string(idEV_SZ_viewmodelmodels[0])
                
entity_set_string(idEV_SZ_weaponmodelmodels[1])
            }
            case 
1:
            {
                
entity_set_string(idEV_SZ_viewmodelmodels[2])
            }
        }
    }
    
    return 
PLUGIN_CONTINUE


Last edited by kww; 02-23-2021 at 10:18.
kww is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-23-2021 , 08:39   Re: changing v_ model
Reply With Quote #2

Quote:
1) If i holding a knife, then typing "changeknife 1" in console, viewmodel isn't changing immediately. I need to change to any other weapon and then change back to knife. Is there any way to fix this?
Just call event_curweapon(id) after client_print

Code:
public xknife_handler(id) {     new x_arg[16]     read_argv(1, x_arg, charsmax(x_arg))         switch(x_arg[0]) {         case EOS: client_print(id, print_console, "* Usage: changeknife <1|0> (now %i)", UserData[id][knife])         case '0': UserData[id][knife] = 0         case '1': UserData[id][knife] = 1     }     client_print(id, print_console, "%i", )         new wpn = get_user_weapon(id)     if (wpn == CSW_KNIFE) {         switch (UserData[id][knife]) {             case 0:             {                 entity_set_string(id, EV_SZ_viewmodel, models[0])                 entity_set_string(id, EV_SZ_weaponmodel, models[1])             }             case 1:             {                 entity_set_string(id, EV_SZ_viewmodel, models[2])             }         }     }     return PLUGIN_HANDLED }

Quote:
2) Which weapon models can be changed via "entity_set_string(id, EV_SZ_viewmodel, modelname)"?
Any weapon without exception.
__________________





Last edited by CrazY.; 02-23-2021 at 08:39.
CrazY. is offline
kww
Member
Join Date: Feb 2021
Location: Russia
Old 02-23-2021 , 08:42   Re: changing v_ model
Reply With Quote #3

Quote:
Originally Posted by CrazY. View Post
Any weapon without exception.
after that there will be no crashes or something else? any bugs or etc...
kww is offline
kww
Member
Join Date: Feb 2021
Location: Russia
Old 02-23-2021 , 08:47   Re: changing v_ model
Reply With Quote #4

So i can remove register_event ("CurWeapon", "event_curweapon", "be", "1=1")?

Last edited by kww; 02-23-2021 at 08:48.
kww is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 02-23-2021 , 09:04   Re: changing v_ model
Reply With Quote #5

Quote:
Originally Posted by kww View Post
after that there will be no crashes or something else? any bugs or etc...
It won't crash the server unless the model isn't precached.


Quote:
Originally Posted by kww View Post
So i can remove register_event ("CurWeapon", "event_curweapon", "be", "1=1")?
Not really, you need to update the viewmodel and weaponmodel every time the weapon is deployed, not just one time.

Your code may be improved using a 2d array instead of multiple switch calls.
The following code will get you started, it's up to you to implement whatever else you need.

Code:
#include <amxmodx> #include <hamsandwich> #include <engine> const MAX_MODEL_LENGTH = 64 enum _:KnifeModel_e {     V_MODEL[MAX_MODEL_LENGTH],     P_MODEL[MAX_MODEL_LENGTH], } // Index starts from 0 new const KNIFE_MODELS[][KnifeModel_e] = {     { "models/v_knife.mdl", "models/p_knife.mdl" },     { "models/v_knife2.mdl", "" } // Leave blank quotes "" for no model } new g_knifeModel[32+1] // this holds the player's knife index in KNIFE_MODELS array public plugin_init() {     register_plugin("Plugin", "Version", "Author")     RegisterHam(Ham_Item_Deploy, "weapon_knife", "HookKnifeDeployPost", 1) } public plugin_precache() {     for (new i = 0; i < sizeof KNIFE_MODELS; i++)     {         if (KNIFE_MODELS[i][V_MODEL][0])             precache_model(KNIFE_MODELS[i][V_MODEL])         if (KNIFE_MODELS[i][P_MODEL][0])             precache_model(KNIFE_MODELS[i][P_MODEL])     } } public client_disconnect(index) {     g_knifeModel[index] = 0 } public HookKnifeDeployPost(index) {     new player = entity_get_edict(index, EV_ENT_owner)     new knifeIndex = g_knifeModel[player]     if (KNIFE_MODELS[knifeIndex][V_MODEL][0])         entity_set_string(player, EV_SZ_viewmodel, KNIFE_MODELS[knifeIndex][V_MODEL])     if (KNIFE_MODELS[knifeIndex][P_MODEL][0])         entity_set_string(player, EV_SZ_weaponmodel, KNIFE_MODELS[knifeIndex][P_MODEL]) }
__________________




CrazY. is offline
kww
Member
Join Date: Feb 2021
Location: Russia
Old 02-23-2021 , 09:10   Re: changing v_ model
Reply With Quote #6

Quote:
Originally Posted by CrazY. View Post
Your code may be improved using a 2d array instead of multiple switch calls.
The following code will get you started, it's up to you to implement whatever else you need.

code
this will be hard for me to understand
Thanks anyway

Last edited by kww; 02-23-2021 at 09:12.
kww is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-23-2021 , 09:56   Re: changing v_ model
Reply With Quote #7

Why create something that already exists in a much better form?
https://forums.alliedmods.net/showthread.php?t=293632
__________________


Dear admins. If somehow you managed to read this, plz fix.

Last edited by OciXCrom; 02-23-2021 at 09:56.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
kww
Member
Join Date: Feb 2021
Location: Russia
Old 02-23-2021 , 10:19   Re: changing v_ model
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
Why create something that already exists in a much better form?
https://forums.alliedmods.net/showthread.php?t=293632
I know that it already exists. I'm trying to make something myself
kww is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-23-2021 , 11:58   Re: changing v_ model
Reply With Quote #9

Quote:
Originally Posted by OciXCrom View Post
Why create something that already exists in a much better form?
https://forums.alliedmods.net/showthread.php?t=293632
For learning purposes? This section is mainly for learning after all.
__________________
HamletEagle 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 06:20.


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