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

How to change skin of weapon?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasior
Member
Join Date: Mar 2012
Old 01-10-2017 , 22:18   How to change skin of weapon?
Reply With Quote #1

Hi people,

I have a plugin which allows you to change the skin of your weapon but... you can only do it if you hold the weapon in your hand. Now how do I change it into being able to change it regardless of what weapon do I hold so:

Right now:
I have knife, try to change ak47 skin, doesn't work
I have ak47, try to change ak47 skin, works

What I desire:
I have knife, try to change ak47 skin, works!

Code:
#include <amxmodx> 
#include <engine>  
#include <nvault> 

#define MAX_PLAYERS    32 
#define MENUITEM_DISABLED    (1<<26) 
#define ADMIN_FLAG_W (1<<22)

#define PLUGIN "AK47 Menu" 
#define VERSION "1.0"  
#define AUTHOR "Gasior" 

#define TASK_INTERVAL 4.0 


enum Karabin
{ 
    NoKarabinMSet = -1, 
    Asiimov,
    Pomarancza,
    Rise,
    CzasSmierci,
    CzerwonaLinia,
    Wulkan,
    Orzel,
    Standardowy 
} 

enum KarabinModels 
{ 
    ModelName[ 64 ], 
    PlayerModel[ 64 ],  
    ViewModel[ 64 ] 
}  

new const g_ModelData[ Karabin ][ KarabinModels ] =  
{ 
    { "Asiimov" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_Asiimov.mdl" },
    { "Pomarancza" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_Pomarancza.mdl" },
    { "Rise" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_Rise.mdl" },
    { "CzasSmierci" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_CzasSmierci.mdl" },  
    { "CzerwonaLinia" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_CzerwonaLinia.mdl" },
    { "Wulkan" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_Wulkan.mdl" },
    { "Orzel" ,    "models/p_ak47.mdl" ,        "models/ProjektSpark/CSGO/ak47/v_Orzel.mdl" },
    { "Standardowy" ,    "models/p_ak47.mdl" ,        "models/v_ak47.mdl" }

}; 

new g_Menu; 
new Karabin:karabin_model[ MAX_PLAYERS + 1 ]; 
new g_szAuthID[ MAX_PLAYERS + 1 ][ 34 ]; 
new zapis_vault; 

public plugin_init() {  
     
    register_plugin( PLUGIN , VERSION , AUTHOR ); 
     
    register_event( "CurWeapon" , "CurWeapon" , "be" , "1=1" ); 
     
    g_Menu = register_menuid( "Karabin Mod" ); 
    register_menucmd( g_Menu , 1023 , "Karabinmenu" ); 
     
    register_clcmd( "say /ak47" , "display_karabin" ); 
    register_clcmd( "say_team /ak47" , "display_karabin" ); 
     
    zapis_vault = nvault_open( "g_karabiny" ); 
     
    if( zapis_vault == INVALID_HANDLE ) 
        set_fail_state( "Nie moge otworzyc pliku :/" ); 
} 

public plugin_precache()  
{  
    for ( new Karabin:i = Asiimov; i < Karabin ; i++ ) 
    { 
        precache_model( g_ModelData[ i ][ PlayerModel ] ); 
        precache_model( g_ModelData[ i ][ ViewModel ] ); 
    } 
}  

public client_authorized( id )  
{ 
    get_user_authid( id , g_szAuthID[ id ] , charsmax( g_szAuthID[] ) ); 
     
    LoadData( id ); 
} 

public display_karabin(id)  
{ 
    new menuBody[ 512 ]; 
     
    add(menuBody, charsmax( menuBody ) , "\rWybierz swoj \wAK47^n^n" ); 
    add(menuBody, charsmax( menuBody ), "\y1. \wAsiimov^n" ); 
    add(menuBody, charsmax( menuBody ), "\y2. \wPomarancza^n" ); 
    add(menuBody, charsmax( menuBody ), "\y3. \wRise^n" ); 
    add(menuBody, charsmax( menuBody ), "\y4. \wCzas Smierci^n" ); 
    add(menuBody, charsmax( menuBody ), "\y5. \wCzerwonaLinia^n" ); 
    add(menuBody, charsmax( menuBody ), "\y6. \wWulkan^n" ); 
    add(menuBody, charsmax( menuBody ), "\y7. \wOrzel^n" ); 
    add(menuBody, charsmax( menuBody ), "\y8. \wStandardowy\w^n^n" ); 
    add(menuBody, charsmax( menuBody ), "Odwiedz nas na \rProjektSpark.pl^n" , 0 ); 
    add(menuBody, charsmax( menuBody ), "\r0. Exit^n" ); 
     
    new keys = ( 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<8 | 1<<9 ); 
    show_menu( id , keys , menuBody , -1 , "Karabin Mod" ); 
} 

public Karabinmenu( id , key )  
{ 
    if ( 0 <= key <= 8 ) 
    { 
        SetKarabin( id , Karabin:key ); 
         
        SaveData( id ); 
    } 
     
    return PLUGIN_HANDLED; 
}  

public SetKarabin(id , Karabin:ak47)  
{ 
    new Karabin:iModelIndex = NoKarabinMSet; 

    if ( get_user_weapon( id ) != CSW_AK47 ){
    return PLUGIN_HANDLED 
    }
    else{
    iModelIndex = ak47; 
 
    karabin_model[ id ] = iModelIndex 
     
    entity_set_string( id , EV_SZ_viewmodel , g_ModelData[ iModelIndex ][ ViewModel ] ); 
    entity_set_string( id , EV_SZ_weaponmodel , g_ModelData[ iModelIndex ][ PlayerModel ] ); 
    }
    return PLUGIN_HANDLED;  
} 

public CurWeapon(id) 
{ 
    SetKarabin(id, karabin_model[id])    
    return PLUGIN_HANDLED    
} 

public SaveData(id) 
{  
    new szKey[ 40 ] , szData[ 3 ]; 
     
    formatex( szKey , charsmax( szKey ) , "%s_ak47" , g_szAuthID[ id ] ); 
    num_to_str( _:karabin_model[ id ] , szData , charsmax( szData ) ); 
     
    nvault_set( zapis_vault , szKey , szData ); 
} 

public LoadData(id)  
{  
    new szKey[ 40 ] , szData[ 3 ] , iTS;  
     
    formatex( szKey , charsmax( szKey ) , "%s_ak47" , g_szAuthID[ id ] ); 
     
    if ( nvault_lookup( zapis_vault , szKey , szData , charsmax( szData ) , iTS ) )   
    { 
        karabin_model[ id ] = Karabin:str_to_num( szData ); 
    } 
}
Any suggestions?
Gasior is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 01-10-2017 , 22:21   Re: How to change skin of weapon?
Reply With Quote #2

PHP Code:
    if ( get_user_weaponid ) != CSW_AK47 ){
    return 
PLUGIN_HANDLED 
    
}
    else{
    
iModelIndex ak47 
->

PHP Code:
    iModelIndex ak47 
Try it
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Gasior
Member
Join Date: Mar 2012
Old 01-10-2017 , 22:45   Re: How to change skin of weapon?
Reply With Quote #3

Have tried that, that changes all your skins then ;/ .

Code:
public SetKarabin(id , Karabin:ak47)  
{ 
    new Karabin:iModelIndex = NoKarabinMSet; 

    if ( get_user_weapon( id ) == CSW_AK47 ){
    iModelIndex = ak47; 
 
    karabin_model[ id ] = iModelIndex 
     
    entity_set_string( id , EV_SZ_viewmodel , g_ModelData[ iModelIndex ][ ViewModel ] ); 
    entity_set_string( id , EV_SZ_weaponmodel , g_ModelData[ iModelIndex ][ PlayerModel ] ); 
    }
    return PLUGIN_CONTINUE;  
}
Also tried this, nada.

Last edited by Gasior; 01-10-2017 at 22:58.
Gasior is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 01-10-2017 , 23:16   Re: How to change skin of weapon?
Reply With Quote #4

Why do you need to change it if you're not holding it? You will not be able to to see it until you deploy or drop the weapon.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.
wickedd is offline
Gasior
Member
Join Date: Mar 2012
Old 01-10-2017 , 23:25   Re: How to change skin of weapon?
Reply With Quote #5

My point is to be able to change the model of the AK47 or any other weapon, so that when I pick it up it presents to this model.

So for instance I would be able to pick all the models of weapons without actually having them at this particular moment.
Gasior is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 01-10-2017 , 23:33   Re: How to change skin of weapon?
Reply With Quote #6

Quote:
Originally Posted by Gasior View Post
My point is to be able to change the model of the AK47 or any other weapon, so that when I pick it up it presents to this model.
You can use Ham_Item_Deploy.
Edit: FYI CurWeapon is fired every time you shoot, reload or change weapons.
Quote:
Originally Posted by Gasior View Post
So for instance I would be able to pick all the models of weapons without actually having them at this particular moment.
Can you give more details?
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 01-10-2017 at 23:38.
wickedd is offline
Gasior
Member
Join Date: Mar 2012
Old 01-11-2017 , 00:36   Re: How to change skin of weapon?
Reply With Quote #7

So imagine you join my server, which you are welcome to!

You have a menu with all the weapons. You can pick any weapon and set any model available for any weapon you want. You set Galaxy for deagle, you set model RANDOM for Ak47. You win the round you have money you buy deagle and ak47 and when you pick those weapon you have a model that you have selected earlier.

Hamsandwich is failing me :C
Gasior is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 01-11-2017 , 09:11   Re: How to change skin of weapon?
Reply With Quote #8



PHP Code:
 if ( get_user_weaponid ) != CSW_AK47 ){
    return 
PLUGIN_HANDLED 
    
}
    else{
    
iModelIndex ak47 
- >
PHP Code:
    if ( get_user_weaponid ) == CSW_AK47 )
    {
        
iModelIndex ak47
    

__________________
Project: Among Us

Last edited by Craxor; 01-11-2017 at 09:12.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-11-2017 , 11:06   Re: How to change skin of weapon?
Reply With Quote #9

I have created a plugin that does what you want, because I'm bored. It's using better methods than your current one and I've also added a configuration file for the weapons. Note that I fastly wrote this and it's not fail proof. If you find any bugs or something should be changed just tell me.

Create a file in addons/amxmodx/configs named weapons_menu.ini. Inside it, you will add weapons in this format:
Code:
weapon_menu_display_name weapon_classname v_model p_model
Example(taking a weapon from your const):
Code:
Asiimov weapon_ak47 models/ProjektSpark/CSGO/ak47/v_Asiimov.mdl models/p_ak47.mdl
The command for the menu is say /weapons. Feel free to change it how you like(add message, rename commands, menu title, etc)

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PluginName    "Weapons Menu"
#define PluginVersion "0.1"
#define PluginAuthor  "HamletEagle"

enum _:WeaponData
{
    
weaponClassName[32],
    
viewModel[128],
    
previewModel[128]
}

const 
m_pPlayer     41
const m_pActiveItem 373
const XoWeapon      4
const XoPlayer      5

new const FileName[] = "weapons_menu.ini"

new Trie:HandlePlayerCustomization
new Array:HandleWeaponsData

new HandleWeaponMenu

public plugin_init()
{
    
register_plugin
    
(
        .
plugin_name PluginName,
        .
version     PluginVersion,
        .
author       PluginAuthor
    
)
    
    
HandlePlayerCustomization TrieCreate()
    
HandleWeaponsData         ArrayCreate(WeaponData)
    
HandleWeaponMenu          menu_create("Choose your weapon:""WeaponsMenuHandler")
    
    new 
handleFilePath[128], bool:itemAdded
    get_configsdir
(handleFilePathcharsmax(handleFilePath))
    
format(handleFilePathcharsmax(handleFilePath), "%s/%s"handleFilePathFileName)
    
    new 
filePointer fopen(handleFilePath"rt")
    if(
filePointer)
    {
        new 
Trie:classnameRegistered TrieCreate()
        new 
fileData[256], weaponMenuName[32], data[WeaponData]
        
        while(!
feof(filePointer))
        {
            
fgets(filePointerfileDatacharsmax(fileData))
            
trim(fileData)
            
            if(
fileData[0] == ';' || fileData[0] == '/')
            {
                continue
            }
            
            
parse
            
(
                
fileData             
                
weaponMenuName       charsmax(weaponMenuName       ), 
                
data[weaponClassName], charsmax(data[weaponClassName]), 
                
data[viewModel      ], charsmax(data[viewModel      ]), 
                
data[previewModel   ], charsmax(data[previewModel   ])
            )
            
            if(!
file_exists(data[viewModel]) || !file_exists(data[previewModel]))
            {
                
log_amx("Weapon %s was skipped, missing resources"weaponMenuName)
                continue
            }
            
            if(!
TrieKeyExists(classnameRegistereddata[weaponClassName]))
            {
                
TrieSetCell(classnameRegistereddata[weaponClassName], 0)
                
RegisterHam(Ham_Item_Deploydata[weaponClassName], "CBasePlayer_ItemDeploy"true)
            }
            
            
precache_model(data[viewModel])
            
precache_model(data[previewModel])
            
            
menu_additem(HandleWeaponMenuweaponMenuName)
            
itemAdded true
            
            ArrayPushArray
(HandleWeaponsDatadata)
        }
        
        
menu_setprop(HandleWeaponMenuMPROP_EXITMEXIT_ALL)
        
TrieDestroy(classnameRegistered)
        
fclose(filePointer)
    }
    
    if(!
itemAdded)
    {
        
Destroy()
        
set_fail_state("Configuration file is empty")
    }
    
    
register_clcmd("say /weapons""ClientCommand_DisplayWeaponMenu")
}

public 
plugin_end()
{
    
Destroy()
}

public 
WeaponsMenuHandler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_cancel(id)
        return 
PLUGIN_HANDLED
    
}
    
    if(
is_user_connected(id))
    {
        new 
playerAuthid[32], data[WeaponData]
        
get_user_authid(idplayerAuthidcharsmax(playerAuthid))
        
        
ArrayGetArray(HandleWeaponsDataitemdata)
        
TrieSetArray(HandlePlayerCustomizationplayerAuthiddatasizeof data)
        
        new 
activeItem get_pdata_cbase(idm_pActiveItemXoPlayer)
        if(
pev_valid(activeItem))
        {
            new 
activeItemClassName[32]
            
pev(activeItempev_classnameactiveItemClassNamecharsmax(activeItemClassName))
            if(
equal(activeItemClassNamedata[weaponClassName]))
            {
                
CBasePlayer_ItemDeploy(activeItem)
            }
        }
        
        
menu_cancel(id)
    }

    return 
PLUGIN_CONTINUE
}

public 
CBasePlayer_ItemDeploy(const entity)
{
    if(
pev_valid(entity))
    {
        new 
id get_pdata_cbase(entitym_pPlayerXoWeapon)
        if(
is_user_alive(id))
        {
            new 
playerAuthid[32], data[WeaponData]
            
get_user_authid(idplayerAuthidcharsmax(playerAuthid))
            if(
TrieKeyExists(HandlePlayerCustomizationplayerAuthid))
            {
                
TrieGetArray(HandlePlayerCustomizationplayerAuthiddatasizeof data)
                
                new 
entityClassName[32]
                
pev(entitypev_classnameentityClassNamecharsmax(entityClassName))
                
                if(
equal(entityClassNamedata[weaponClassName]))
                {
                    
set_pev(idpev_viewmodel2data[viewModel])
                    
set_pev(idpev_weaponmodel2data[previewModel])
                }
            }
        }
    }
}

public 
client_disconnect(id)
{
    new 
playerAuthid[32]
    
get_user_authid(idplayerAuthidcharsmax(playerAuthid))
    if(
TrieKeyExists(HandlePlayerCustomizationplayerAuthid))
    {
        
TrieDeleteKey(HandlePlayerCustomizationplayerAuthid)
    }
}

Destroy()
{
    
TrieDestroy(HandlePlayerCustomization)
    
ArrayDestroy(HandleWeaponsData)
    
menu_destroy(HandleWeaponMenu)
}

public 
ClientCommand_DisplayWeaponMenu(id)
{
    if(
is_user_connected(id))
    {
        
menu_display(idHandleWeaponMenu0)
    }

__________________

Last edited by HamletEagle; 01-12-2017 at 06:19.
HamletEagle is offline
Gasior
Member
Join Date: Mar 2012
Old 01-11-2017 , 21:59   Re: How to change skin of weapon?
Reply With Quote #10

Your above plugin, does not not precached models, but it is very interesting concept to look at.

Craxor, that also will not and does not work.

Last edited by Gasior; 01-11-2017 at 21:59.
Gasior 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 16:21.


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