AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Knife Models [XP System & Skills Support] (https://forums.alliedmods.net/showthread.php?t=293632)

OciXCrom 04-06-2017 06:57

Re: Knife Models
 
It's much work, I don't fell like doing it. I made a transformation of this plugin that you can use for other weapons. Here's the code:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <formatin>

#define PLUGIN_VERSION "1.4"
#define MAX_SKINS 30

enum _:Info
{
    
Name[32],
    
VModel[128],
    
PModel[128],
    
Flag
}

enum _:Weapon
{
    
Name[16],
    
NameLower[16],
    
weapon_id[20],
    
CSW_ID
}

new 
g_eSkins[MAX_SKINS][Info]
new 
g_eWeapon[Weapon]
new 
g_eSkinsNum
new g_iSkin[33]
new 
g_szDefaultV[32]
new 
g_szDefaultP[32]
new 
g_iSayText

public plugin_init()
{    
    
register_plugin(formatin("%s Models"g_eWeapon[Name]), PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXWeaponModels"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
register_event("CurWeapon""OnSelectWeapon""be""1=1"formatin("2=%i"g_eWeapon[CSW_ID]))
    
    
register_clcmd(formatin("say /%s"g_eWeapon[NameLower]), "ShowMenu")
    
register_clcmd(formatin("say_team /%s"g_eWeapon[NameLower]), "ShowMenu")
    
    
g_iSayText get_user_msgid("SayText")
}

public 
plugin_precache()
{
    new 
szWeapon[32]
    
get_plugin(-1szWeaponcharsmax(szWeapon))
    
replace(szWeaponcharsmax(szWeapon), "crx_""")
    
replace(szWeaponcharsmax(szWeapon), "_models.amxx""")
    
    
copy(g_eWeapon[Name], charsmax(g_eWeapon[Name]), szWeapon)
    
strtolower(szWeapon)
    
copy(g_eWeapon[NameLower], charsmax(g_eWeapon[NameLower]), szWeapon)
    
formatex(g_eWeapon[weapon_id], charsmax(g_eWeapon[weapon_id]), "weapon_%s"szWeapon)
    
g_eWeapon[CSW_ID] = get_weaponid(g_eWeapon[weapon_id])
    
    
register_dictionary("WeaponModels.txt")
    
    if(!
g_eWeapon[CSW_ID])
        
set_fail_state(formatin("%L"LANG_SERVER"WM_INVALID_WEAPON"g_eWeapon[weapon_id]))
        
    
formatex(g_szDefaultVcharsmax(g_szDefaultV), "models/v_%s.mdl"g_eWeapon[NameLower])
    
formatex(g_szDefaultPcharsmax(g_szDefaultP), "models/p_%s.mdl"g_eWeapon[NameLower])
        
    
/*log_amx("Name: %s", g_eWeapon[Name])
    log_amx("NameLower: %s", g_eWeapon[NameLower])
    log_amx("weapon_id: %s", g_eWeapon[weapon_id])
    log_amx("CSW_ID: %i", g_eWeapon[CSW_ID])*/
    
    
ReadFile()
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/%sModels.ini"szConfigsNameg_eWeapon[Name])
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[300], szFlag[2]
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS';': continue
                default:
                {
                    
parse(szData,     g_eSkins[g_eSkinsNum][Name], charsmax(g_eSkins[][Name]),    g_eSkins[g_eSkinsNum][VModel], charsmax(g_eSkins[][VModel]),
                    
g_eSkins[g_eSkinsNum][PModel], charsmax(g_eSkins[][PModel]), szFlagcharsmax(szFlag))
                    
                    if(!
is_blank(g_eSkins[g_eSkinsNum][VModel]))
                        
precache_model(g_eSkins[g_eSkinsNum][VModel])
                        
                    if(!
is_blank(g_eSkins[g_eSkinsNum][PModel]))
                        
precache_model(g_eSkins[g_eSkinsNum][PModel])
                        
                    
g_eSkins[g_eSkinsNum][Flag] = is_blank(szFlag) ? ADMIN_ALL read_flags(szFlag)
                        
                    
szFlag[0] = EOS
                    g_eSkinsNum
++
                }
            }
        }
        
        
fclose(iFilePointer)
    }
}

public 
ShowMenu(id)
{
    new 
szTitle[128]
    
formatex(szTitlecharsmax(szTitle), "%L"id"WM_MENU_TITLE"g_eWeapon[Name])
    
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
iFlags get_user_flags(id), ig_eSkinsNumi++)
    {
        if(
g_eSkins[i][Flag] == ADMIN_ALL || iFlags g_eSkins[i][Flag])
            
menu_additem(iMenuformatin("%s %s"g_eSkins[i][Name], g_iSkin[id] == formatin("%L"id"WM_MENU_SELECTED") : formatin("")))
        else
            
menu_additem(iMenuformatin("%s %L"g_eSkins[i][Name], id"WM_MENU_VIP_ONLY"), .paccess g_eSkins[i][Flag])
    }
    
    if(
menu_pages(iMenu) > 1)
        
menu_setprop(iMenuMPROP_TITLEformatin("%s%L"szTitleid"WM_MENU_TITLE_PAGE"))
        
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        if(
g_iSkin[id] == iItem)
            
ColorChat(id"%L"id"WM_CHAT_ALREADY")
        else
        {
            
g_iSkin[id] = iItem
            
            
if(is_user_alive(id) && get_user_weapon(id) == g_eWeapon[CSW_ID])
                
OnSelectWeapon(id)
            
            
ColorChat(id"%L"id"WM_CHAT_SELECTED"g_eSkins[iItem][Name])
        }
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
    
g_iSkin[id] = 0

public OnSelectWeapon(id)
{
    if(
is_blank(g_eSkins[g_iSkin[id]][VModel]))
        
set_pev(idpev_viewmodel2g_szDefaultV)
    else 
set_pev(idpev_viewmodel2g_eSkins[g_iSkin[id]][VModel])
    
    if(
is_blank(g_eSkins[g_iSkin[id]][PModel]))
        
set_pev(idpev_weaponmodel2g_szDefaultP)
    else 
set_pev(idpev_weaponmodel2g_eSkins[g_iSkin[id]][PModel])
}

bool:is_blank(szString[])
    return 
szString[0] == EOS
    
ColorChat
(const id, const szInput[], any:...)
{
    new 
iPlayers[32], iCount 1
    
static szMessage[191]
    
vformat(szMessagecharsmax(szMessage), szInput3)
    
format(szMessage[0], charsmax(szMessage), "%L %s"id id LANG_PLAYER"WM_CHAT_PREFIX"g_eWeapon[Name], szMessage)
    
    
replace_all(szMessagecharsmax(szMessage), "!g""^4")
    
replace_all(szMessagecharsmax(szMessage), "!n""^1")
    
replace_all(szMessagecharsmax(szMessage), "!t""^3")
    
    if(
id)
        
iPlayers[0] = id
    
else
        
get_players(iPlayersiCount"ch")
    
    for(new 
iiCounti++)
    {
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEg_iSayText_iPlayers[i])
            
write_byte(iPlayers[i])
            
write_string(szMessage)
            
message_end()
        }
    }


The plugin needs to be named crx_<WEAPON NAME HERE>_models.amxx. So, if you want models for ak47, you will name the plugin crx_AK47_models.amxx. The command will be /ak47 and the config file configs/AK47Models.ini. Inside it you can add models like this:

PHP Code:

"Cool AK47" "v_model.mdl" "p_model.mdl" "flag" 

Also, the lang file located in data/lang/WeaponModels.txt:

PHP Code:

[en]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
This skin is already selected!
WM_CHAT_SELECTED You have selected the skin !g%s
WM_MENU_TITLE 
= \y< \rChoose your %s model \y>
WM_MENU_TITLE_PAGE = ^n\r-- \yPage:\r
WM_MENU_SELECTED 
= \y~ \rSELECTED \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Invalid weapon ^"%s^"

[mk]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
Ovoj skin vekje e izbran!
WM_CHAT_SELECTED Go izbra skinot !g%s
WM_MENU_TITLE 
= \y< \rIzberi model za %\y>
WM_MENU_TITLE_PAGE = ^n\r-- \yStranica:\r
WM_MENU_SELECTED 
= \y~ \rIZBRAN \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Nevalidno oruzhje ^"%s^"

[bg]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
Tozi skin veche e izbran!
WM_CHAT_SELECTED Izbra skina !g%s
WM_MENU_TITLE 
= \y< \rIzberi model za %\y>
WM_MENU_TITLE_PAGE = ^n\r-- \yStranica:\r
WM_MENU_SELECTED 
= \y~ \rIZBRAN \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Nevalidno orujie ^"%s^" 

If you want another weapon, copy the plugin + the .ini file and change its name, for example crx_M4A1_models.amxx and M4A1Models.ini.

FreezerPT 04-06-2017 10:33

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2509804)
It's much work, I don't fell like doing it. I made a transformation of this plugin that you can use for other weapons. Here's the code:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <formatin>

#define PLUGIN_VERSION "1.4"
#define MAX_SKINS 30

enum _:Info
{
    
Name[32],
    
VModel[128],
    
PModel[128],
    
Flag
}

enum _:Weapon
{
    
Name[16],
    
NameLower[16],
    
weapon_id[20],
    
CSW_ID
}

new 
g_eSkins[MAX_SKINS][Info]
new 
g_eWeapon[Weapon]
new 
g_eSkinsNum
new g_iSkin[33]
new 
g_szDefaultV[32]
new 
g_szDefaultP[32]
new 
g_iSayText

public plugin_init()
{    
    
register_plugin(formatin("%s Models"g_eWeapon[Name]), PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXWeaponModels"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
register_event("CurWeapon""OnSelectWeapon""be""1=1"formatin("2=%i"g_eWeapon[CSW_ID]))
    
    
register_clcmd(formatin("say /%s"g_eWeapon[NameLower]), "ShowMenu")
    
register_clcmd(formatin("say_team /%s"g_eWeapon[NameLower]), "ShowMenu")
    
    
g_iSayText get_user_msgid("SayText")
}

public 
plugin_precache()
{
    new 
szWeapon[32]
    
get_plugin(-1szWeaponcharsmax(szWeapon))
    
replace(szWeaponcharsmax(szWeapon), "crx_""")
    
replace(szWeaponcharsmax(szWeapon), "_models.amxx""")
    
    
copy(g_eWeapon[Name], charsmax(g_eWeapon[Name]), szWeapon)
    
strtolower(szWeapon)
    
copy(g_eWeapon[NameLower], charsmax(g_eWeapon[NameLower]), szWeapon)
    
formatex(g_eWeapon[weapon_id], charsmax(g_eWeapon[weapon_id]), "weapon_%s"szWeapon)
    
g_eWeapon[CSW_ID] = get_weaponid(g_eWeapon[weapon_id])
    
    
register_dictionary("WeaponModels.txt")
    
    if(!
g_eWeapon[CSW_ID])
        
set_fail_state(formatin("%L"LANG_SERVER"WM_INVALID_WEAPON"g_eWeapon[weapon_id]))
        
    
formatex(g_szDefaultVcharsmax(g_szDefaultV), "models/v_%s.mdl"g_eWeapon[NameLower])
    
formatex(g_szDefaultPcharsmax(g_szDefaultP), "models/p_%s.mdl"g_eWeapon[NameLower])
        
    
/*log_amx("Name: %s", g_eWeapon[Name])
    log_amx("NameLower: %s", g_eWeapon[NameLower])
    log_amx("weapon_id: %s", g_eWeapon[weapon_id])
    log_amx("CSW_ID: %i", g_eWeapon[CSW_ID])*/
    
    
ReadFile()
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/%sModels.ini"szConfigsNameg_eWeapon[Name])
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[300], szFlag[2]
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS';': continue
                default:
                {
                    
parse(szData,     g_eSkins[g_eSkinsNum][Name], charsmax(g_eSkins[][Name]),    g_eSkins[g_eSkinsNum][VModel], charsmax(g_eSkins[][VModel]),
                    
g_eSkins[g_eSkinsNum][PModel], charsmax(g_eSkins[][PModel]), szFlagcharsmax(szFlag))
                    
                    if(!
is_blank(g_eSkins[g_eSkinsNum][VModel]))
                        
precache_model(g_eSkins[g_eSkinsNum][VModel])
                        
                    if(!
is_blank(g_eSkins[g_eSkinsNum][PModel]))
                        
precache_model(g_eSkins[g_eSkinsNum][PModel])
                        
                    
g_eSkins[g_eSkinsNum][Flag] = is_blank(szFlag) ? ADMIN_ALL read_flags(szFlag)
                        
                    
szFlag[0] = EOS
                    g_eSkinsNum
++
                }
            }
        }
        
        
fclose(iFilePointer)
    }
}

public 
ShowMenu(id)
{
    new 
szTitle[128]
    
formatex(szTitlecharsmax(szTitle), "%L"id"WM_MENU_TITLE"g_eWeapon[Name])
    
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
iFlags get_user_flags(id), ig_eSkinsNumi++)
    {
        if(
g_eSkins[i][Flag] == ADMIN_ALL || iFlags g_eSkins[i][Flag])
            
menu_additem(iMenuformatin("%s %s"g_eSkins[i][Name], g_iSkin[id] == formatin("%L"id"WM_MENU_SELECTED") : formatin("")))
        else
            
menu_additem(iMenuformatin("%s %L"g_eSkins[i][Name], id"WM_MENU_VIP_ONLY"), .paccess g_eSkins[i][Flag])
    }
    
    if(
menu_pages(iMenu) > 1)
        
menu_setprop(iMenuMPROP_TITLEformatin("%s%L"szTitleid"WM_MENU_TITLE_PAGE"))
        
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        if(
g_iSkin[id] == iItem)
            
ColorChat(id"%L"id"WM_CHAT_ALREADY")
        else
        {
            
g_iSkin[id] = iItem
            
            
if(is_user_alive(id) && get_user_weapon(id) == g_eWeapon[CSW_ID])
                
OnSelectWeapon(id)
            
            
ColorChat(id"%L"id"WM_CHAT_SELECTED"g_eSkins[iItem][Name])
        }
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
    
g_iSkin[id] = 0

public OnSelectWeapon(id)
{
    if(
is_blank(g_eSkins[g_iSkin[id]][VModel]))
        
set_pev(idpev_viewmodel2g_szDefaultV)
    else 
set_pev(idpev_viewmodel2g_eSkins[g_iSkin[id]][VModel])
    
    if(
is_blank(g_eSkins[g_iSkin[id]][PModel]))
        
set_pev(idpev_weaponmodel2g_szDefaultP)
    else 
set_pev(idpev_weaponmodel2g_eSkins[g_iSkin[id]][PModel])
}

bool:is_blank(szString[])
    return 
szString[0] == EOS
    
ColorChat
(const id, const szInput[], any:...)
{
    new 
iPlayers[32], iCount 1
    
static szMessage[191]
    
vformat(szMessagecharsmax(szMessage), szInput3)
    
format(szMessage[0], charsmax(szMessage), "%L %s"id id LANG_PLAYER"WM_CHAT_PREFIX"g_eWeapon[Name], szMessage)
    
    
replace_all(szMessagecharsmax(szMessage), "!g""^4")
    
replace_all(szMessagecharsmax(szMessage), "!n""^1")
    
replace_all(szMessagecharsmax(szMessage), "!t""^3")
    
    if(
id)
        
iPlayers[0] = id
    
else
        
get_players(iPlayersiCount"ch")
    
    for(new 
iiCounti++)
    {
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEg_iSayText_iPlayers[i])
            
write_byte(iPlayers[i])
            
write_string(szMessage)
            
message_end()
        }
    }


The plugin needs to be named crx_<WEAPON NAME HERE>_models.amxx. So, if you want models for ak47, you will name the plugin crx_AK47_models.amxx. The command will be /ak47 and the config file configs/AK47Models.ini. Inside it you can add models like this:

PHP Code:

"Cool AK47" "v_model.mdl" "p_model.mdl" "flag" 

Also, the lang file located in data/lang/WeaponModels.txt:

PHP Code:

[en]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
This skin is already selected!
WM_CHAT_SELECTED You have selected the skin !g%s
WM_MENU_TITLE 
= \y< \rChoose your %s model \y>
WM_MENU_TITLE_PAGE = ^n\r-- \yPage:\r
WM_MENU_SELECTED 
= \y~ \rSELECTED \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Invalid weapon ^"%s^"

[mk]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
Ovoj skin vekje e izbran!
WM_CHAT_SELECTED Go izbra skinot !g%s
WM_MENU_TITLE 
= \y< \rIzberi model za %\y>
WM_MENU_TITLE_PAGE = ^n\r-- \yStranica:\r
WM_MENU_SELECTED 
= \y~ \rIZBRAN \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Nevalidno oruzhje ^"%s^"

[bg]
WM_CHAT_PREFIX = !g[%s Models]!n
WM_CHAT_ALREADY 
Tozi skin veche e izbran!
WM_CHAT_SELECTED Izbra skina !g%s
WM_MENU_TITLE 
= \y< \rIzberi model za %\y>
WM_MENU_TITLE_PAGE = ^n\r-- \yStranica:\r
WM_MENU_SELECTED 
= \y~ \rIZBRAN \y~
WM_MENU_VIP_ONLY = \y~ \rVIP \y~
WM_INVALID_WEAPON Nevalidno orujie ^"%s^" 

If you want another weapon, copy the plugin + the .ini file and change its name, for example crx_M4A1_models.amxx and M4A1Models.ini.

Ok nice, but if i want m4, what i write in chat /m4?

OciXCrom 04-06-2017 14:44

Re: Knife Models
 
The same thing you wrote between crx_ and _models, but with small letters. So, it will be /m4a1.

FreezerPT 10-14-2017 11:33

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2493139)

Description

  • A simple plugin that adds a menu from which you can choose your Knife skin. The menu can be accessed by typing /knife in the chat.


Cvars

  • km_open_at_spawn "0" -- whether the menu will be automatically opened on first spawn.


Adding skins

  • The skins can be added in configs/KnifeModels.ini by following the example:

    PHP Code:

    [Skin Name]
    V_MODEL path to v_ model
    P_MODEL 
    path to p_ model 

  • If the skin doesn't have a p_ model, you can choose not to add the P_MODEL field.
  • You can also change the sounds and add a specific admin flag:

    PHP Code:

    [Skin Name]
    V_MODEL path to v_ model
    P_MODEL 
    path to p_ model
    FLAG 
    = if you want the knife to be for VIP users/adminsenter the flag here
    DEPLOY_SOUND 
    sound when you deploy the knife
    HIT_SOUND 
    sound when you hit a player
    HITWALL_SOUND 
    sound when you hit a wall
    SLASH_SOUND 
    sound when you swing the knife
    STAB_SOUND 
    sound when you stab a player 

  • Example:

    PHP Code:

    [My Cool Knife]
    V_MODEL models/v_coolknife.mdl
    P_MODEL 
    models/p_coolknife.mdl
    FLAG 
    b
    DEPLOY_SOUND 
    coolknife/deploy.wav
    HIT_SOUND 
    coolknife/hit.wav
    HITWALL_SOUND 
    coolknife/hitwall.wav
    SLASH_SOUND 
    coolknife/slash.wav
    STAB_SOUND 
    coolknife/stab.wav 


https://raw.githubusercontent.com/Oc...using_this.png
https://raw.githubusercontent.com/Oc...ad_default.png

I like your plugin but have a problem, because when a player leaves ther server and comeback,
he have to choose again the model! How can i put the plugin save the model, for steam id or something

OciXCrom 10-14-2017 12:54

Re: Knife Models
 
That's not a problem, it's how I made it work. I'll add a saving option later.

FreezerPT 10-14-2017 15:38

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2554480)
That's not a problem, it's how I made it work. I'll add a saving option later.

But can you tell me how can i do, or can you do this quicly

OciXCrom 10-14-2017 17:43

Re: Knife Models
 
In order to tell you, I would need to provide code, so if I could do that, I would have done it instead. I'll do it tomorrow if I have time.

FreezerPT 10-15-2017 05:02

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2554541)
In order to tell you, I would need to provide code, so if I could do that, I would have done it instead. I'll do it tomorrow if I have time.

Ok if you edit the code, can you tell me please! Thanx for your time bro!

OciXCrom 10-16-2017 09:40

Re: Knife Models
 
Here:
  • They are saved by SteamID.
  • The saved skin will be reset if you edit the knife name from the .ini file.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <formatin>
#include <hamsandwich>
#include <nvault>

#define PLUGIN_VERSION "2.0-AM"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"

enum
{
    
SOUND_NONE 0,
    
SOUND_DEPLOY,
    
SOUND_HIT,
    
SOUND_HITWALL,
    
SOUND_SLASH,
    
SOUND_STAB
}

enum _:Knives
{
    
NAME[32],
    
V_MODEL[128],
    
P_MODEL[128],
    
DEPLOY_SOUND[128],
    
HIT_SOUND[128],
    
HITWALL_SOUND[128],
    
SLASH_SOUND[128],
    
STAB_SOUND[128],
    
FLAG,
    
bool:HAS_CUSTOM_SOUND
}

new Array:
g_aKnives,
    
bool:g_bFirstTime[33],
    
g_eKnife[33][Knives],
    
g_szInfo[33][35],
    
g_iKnife[33],
    
g_pAtSpawn,
    
g_iKnivesNum,
    
g_iSayText,
    
g_iVault

public plugin_init()
{
    
register_plugin("Knife Models"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXKnifeModels"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
    if(!
g_iKnivesNum)
        
set_fail_state("No knives found in the configuration file.")
    
    
register_dictionary("KnifeModels.txt")
    
    
register_event("CurWeapon""OnSelectKnife""be""1=1""2=29")
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
    
register_forward(FM_EmitSound,    "OnEmitSound")
    
    
register_clcmd("say /knife""ShowMenu")
    
register_clcmd("say_team /knife""ShowMenu")
    
    
g_pAtSpawn register_cvar("km_open_at_spawn""0")
    
g_iSayText get_user_msgid("SayText")
    
g_iVault nvault_open("KnifeModels")
}

public 
plugin_precache()
{
    
g_aKnives ArrayCreate(Knives)
    
ReadFile()
}

public 
plugin_end()
{
    
ArrayDestroy(g_aKnives)
    
nvault_close(g_iVault)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/KnifeModels.ini"szConfigsName)
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[160], szKey[32], szValue[128]
        new 
eKnife[Knives]
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS';': continue
                case 
'[':
                {
                    if(
szData[strlen(szData) - 1] == ']')
                    {
                        if(
g_iKnivesNum)
                            
PushKnife(eKnife)
                            
                        
g_iKnivesNum++
                        
replace(szDatacharsmax(szData), "[""")
                        
replace(szDatacharsmax(szData), "]""")
                        
copy(eKnife[NAME], charsmax(eKnife[NAME]), szData)
                    }
                    else continue
                }
                default:
                {
                    
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '=')
                    
trim(szKey); trim(szValue)
                    
                    if(
equal(szKey"FLAG"))
                        
eKnife[FLAG] = read_flags(szValue)
                    else if(
equal(szKey"V_MODEL"))
                    {
                        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"P_MODEL"))
                    {
                        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"DEPLOY_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HIT_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HITWALL_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"SLASH_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"STAB_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                }
            }
        }
        
        if(
g_iKnivesNum)
            
PushKnife(eKnife)
        
        
fclose(iFilePointer)
    }
}

public 
client_putinserver(id)
{
    
g_bFirstTime[id] = true
    ArrayGetArray
(g_aKnives0g_eKnife[id])
    
g_iKnife[id] = 0
    get_user_authid
(idg_szInfo[id], charsmax(g_szInfo[]))
    
use_vault(id1)
}

public 
client_disconnect(id)
    
use_vault(id0)

public 
OnEmitSound(idiChannel, const szSample[])
{
    if(!
is_user_connected(id) || !g_eKnife[id][HAS_CUSTOM_SOUND] || !is_knife_sound(szSample))
        return 
FMRES_IGNORED
    
    
switch(detect_knife_sound(szSample))
    {
        case 
SOUND_DEPLOY: if(g_eKnife[id][DEPLOY_SOUND][0]) { play_knife_sound(idg_eKnife[id][DEPLOY_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HIT: if(g_eKnife[id][HIT_SOUND][0]) { play_knife_sound(idg_eKnife[id][HIT_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HITWALL: if(g_eKnife[id][HITWALL_SOUND][0]) { play_knife_sound(idg_eKnife[id][HITWALL_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_SLASH: if(g_eKnife[id][SLASH_SOUND][0]) { play_knife_sound(idg_eKnife[id][SLASH_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_STAB: if(g_eKnife[id][STAB_SOUND][0]) { play_knife_sound(idg_eKnife[id][STAB_SOUND][0]); return FMRES_SUPERCEDE; }
    }
    
    return 
FMRES_IGNORED
}

public 
ShowMenu(id)
{
    new 
szTitle[128]
    
formatex(szTitlecharsmax(szTitle), "%L"id"KM_MENU_TITLE")
    
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
eKnife[Knives], iFlags get_user_flags(id), ig_iKnivesNumi++)
    {
        
ArrayGetArray(g_aKnivesieKnife)
        
        if(
eKnife[FLAG] == ADMIN_ALL || iFlags eKnife[FLAG])
            
menu_additem(iMenuformatin("%s %s"eKnife[NAME], g_iKnife[id] == formatin("%L"id"KM_MENU_SELECTED") : formatin("")), eKnife[NAME])
        else
            
menu_additem(iMenuformatin("%s %L"eKnife[NAME], id"KM_MENU_VIP_ONLY"), eKnife[NAME], eKnife[FLAG])
    }
    
    if(
menu_pages(iMenu) > 1)
        
menu_setprop(iMenuMPROP_TITLEformatin("%s%L"szTitleid"KM_MENU_TITLE_PAGE"))
        
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        if(
g_iKnife[id] == iItem)
            
ColorChat(id"%L"id"KM_CHAT_ALREADY")
        else
        {
            
g_iKnife[id] = iItem
            ArrayGetArray
(g_aKnivesiItemg_eKnife[id])
            
            if(
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
                
OnSelectKnife(id)
            
            new 
szName[32], iUnused
            menu_item_getinfo
(iMenuiItemiUnusedszNamecharsmax(szName), .callback iUnused)
            
ColorChat(id"%L"id"KM_CHAT_SELECTED"szName)
        }
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
OnPlayerSpawn(id)
{
    if(
is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])
    {
        
g_bFirstTime[id] = false
        ShowMenu
(id)
    }
}

public 
OnSelectKnife(id)
{
    
set_pev(idpev_viewmodel2g_eKnife[id][V_MODEL])
    
set_pev(idpev_weaponmodel2g_eKnife[id][P_MODEL])
}

PushKnife(eKnife[Knives])
{
    if(!
eKnife[V_MODEL][0])
        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), DEFAULT_V)
        
    if(!
eKnife[P_MODEL][0])
        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), DEFAULT_P)
        
    
ArrayPushArray(g_aKniveseKnife)
}

bool:is_knife_sound(const szSample[])
    return 
bool:equal(szSample[8], "kni"3)

detect_knife_sound(const szSample[])
{
    static 
iSound
    iSound 
SOUND_NONE
    
    
if(equal(szSample"weapons/knife_deploy1.wav"))
        
iSound SOUND_DEPLOY
    
else if(equal(szSample[14], "hit"3))
        
iSound szSample[17] == 'w' SOUND_HITWALL SOUND_HIT
    
else if(equal(szSample[14], "sla"3))
        
iSound SOUND_SLASH
    
else if(equal(szSample[14], "sta"3))
        
iSound SOUND_STAB
        
    
return iSound
}

use_vault(const id, const iType)
{
    if(!
g_szInfo[id][0])
        return
        
    new 
szData[40]
        
    switch(
iType)
    {
        case 
0:
        {
            
formatex(szDatacharsmax(szData), "%s|%i"g_eKnife[id][NAME], g_iKnife[id])
            
nvault_set(g_iVaultg_szInfo[id], szData)
        }
        case 
1:
        {
            new 
eKnife[Knives], szKnifeName[32], szKnifeNum[8]
            
nvault_get(g_iVaultg_szInfo[id], szDatacharsmax(szData))
            
strtok(szDataszKnifeNamecharsmax(szKnifeName), szKnifeNumcharsmax(szKnifeNum), '|')
            
            new 
iNumber str_to_num(szKnifeNum)
            
ArrayGetArray(g_aKnivesiNumbereKnife)
            
            if(
equali(szKnifeNameeKnife[NAME]) && (eKnife[FLAG] == ADMIN_ALL || get_user_flags(id) & eKnife[FLAG]))
                
g_iKnife[id] = iNumber
        
}
    }
}

play_knife_sound(id, const szSound[])
    
engfunc(EngFunc_EmitSoundidCHAN_WEAPONszSound1.0ATTN_NORM0PITCH_NORM)
    
ColorChat(const id, const szInput[], any:...)
{
    new 
iPlayers[32], iCount 1
    
static szMessage[191]
    
vformat(szMessagecharsmax(szMessage), szInput3)
    
format(szMessage[0], charsmax(szMessage), "%L %s"id id LANG_PLAYER"KM_CHAT_PREFIX"szMessage)
    
    
replace_all(szMessagecharsmax(szMessage), "!g""^4")
    
replace_all(szMessagecharsmax(szMessage), "!n""^1")
    
replace_all(szMessagecharsmax(szMessage), "!t""^3")
    
    if(
id)
        
iPlayers[0] = id
    
else
        
get_players(iPlayersiCount"ch")
    
    for(new 
iiCounti++)
    {
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEg_iSayText_iPlayers[i])
            
write_byte(iPlayers[i])
            
write_string(szMessage)
            
message_end()
        }
    }



panipani 10-30-2017 00:19

Re: Knife Models
 
Could you add Sub menu ? Please I really want it. something like this:

/knife
-----------
1. CS GO Knifes
2. Fun Knifes
---------------
1. knife skin
2. knife skin
3. knife skin
4. knife skin
5. knife skin
----------------------
1. knife skin
2. knife skin
3. knife skin
4. knife skin
5. knife skin


pls

panipani 10-30-2017 00:34

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2554847)
Here:
  • They are saved by SteamID.
  • The saved skin will be reset if you edit the knife name from the .ini file.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <formatin>
#include <hamsandwich>
#include <nvault>

#define PLUGIN_VERSION "2.0-AM"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"

enum
{
    
SOUND_NONE 0,
    
SOUND_DEPLOY,
    
SOUND_HIT,
    
SOUND_HITWALL,
    
SOUND_SLASH,
    
SOUND_STAB
}

enum _:Knives
{
    
NAME[32],
    
V_MODEL[128],
    
P_MODEL[128],
    
DEPLOY_SOUND[128],
    
HIT_SOUND[128],
    
HITWALL_SOUND[128],
    
SLASH_SOUND[128],
    
STAB_SOUND[128],
    
FLAG,
    
bool:HAS_CUSTOM_SOUND
}

new Array:
g_aKnives,
    
bool:g_bFirstTime[33],
    
g_eKnife[33][Knives],
    
g_szInfo[33][35],
    
g_iKnife[33],
    
g_pAtSpawn,
    
g_iKnivesNum,
    
g_iSayText,
    
g_iVault

public plugin_init()
{
    
register_plugin("Knife Models"PLUGIN_VERSION"OciXCrom")
    
register_cvar("CRXKnifeModels"PLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY|FCVAR_UNLOGGED)
    
    if(!
g_iKnivesNum)
        
set_fail_state("No knives found in the configuration file.")
    
    
register_dictionary("KnifeModels.txt")
    
    
register_event("CurWeapon""OnSelectKnife""be""1=1""2=29")
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
    
register_forward(FM_EmitSound,    "OnEmitSound")
    
    
register_clcmd("say /knife""ShowMenu")
    
register_clcmd("say_team /knife""ShowMenu")
    
    
g_pAtSpawn register_cvar("km_open_at_spawn""0")
    
g_iSayText get_user_msgid("SayText")
    
g_iVault nvault_open("KnifeModels")
}

public 
plugin_precache()
{
    
g_aKnives ArrayCreate(Knives)
    
ReadFile()
}

public 
plugin_end()
{
    
ArrayDestroy(g_aKnives)
    
nvault_close(g_iVault)
}

ReadFile()
{
    new 
szConfigsName[256], szFilename[256]
    
get_configsdir(szConfigsNamecharsmax(szConfigsName))
    
formatex(szFilenamecharsmax(szFilename), "%s/KnifeModels.ini"szConfigsName)
    new 
iFilePointer fopen(szFilename"rt")
    
    if(
iFilePointer)
    {
        new 
szData[160], szKey[32], szValue[128]
        new 
eKnife[Knives]
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            switch(
szData[0])
            {
                case 
EOS';': continue
                case 
'[':
                {
                    if(
szData[strlen(szData) - 1] == ']')
                    {
                        if(
g_iKnivesNum)
                            
PushKnife(eKnife)
                            
                        
g_iKnivesNum++
                        
replace(szDatacharsmax(szData), "[""")
                        
replace(szDatacharsmax(szData), "]""")
                        
copy(eKnife[NAME], charsmax(eKnife[NAME]), szData)
                    }
                    else continue
                }
                default:
                {
                    
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '=')
                    
trim(szKey); trim(szValue)
                    
                    if(
equal(szKey"FLAG"))
                        
eKnife[FLAG] = read_flags(szValue)
                    else if(
equal(szKey"V_MODEL"))
                    {
                        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"P_MODEL"))
                    {
                        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
                        
precache_model(szValue)
                    }
                    else if(
equal(szKey"DEPLOY_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HIT_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"HITWALL_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"SLASH_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                    else if(
equal(szKey"STAB_SOUND"))
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        copy
(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
                        
precache_sound(szValue)
                    }
                }
            }
        }
        
        if(
g_iKnivesNum)
            
PushKnife(eKnife)
        
        
fclose(iFilePointer)
    }
}

public 
client_putinserver(id)
{
    
g_bFirstTime[id] = true
    ArrayGetArray
(g_aKnives0g_eKnife[id])
    
g_iKnife[id] = 0
    get_user_authid
(idg_szInfo[id], charsmax(g_szInfo[]))
    
use_vault(id1)
}

public 
client_disconnect(id)
    
use_vault(id0)

public 
OnEmitSound(idiChannel, const szSample[])
{
    if(!
is_user_connected(id) || !g_eKnife[id][HAS_CUSTOM_SOUND] || !is_knife_sound(szSample))
        return 
FMRES_IGNORED
    
    
switch(detect_knife_sound(szSample))
    {
        case 
SOUND_DEPLOY: if(g_eKnife[id][DEPLOY_SOUND][0]) { play_knife_sound(idg_eKnife[id][DEPLOY_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HIT: if(g_eKnife[id][HIT_SOUND][0]) { play_knife_sound(idg_eKnife[id][HIT_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HITWALL: if(g_eKnife[id][HITWALL_SOUND][0]) { play_knife_sound(idg_eKnife[id][HITWALL_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_SLASH: if(g_eKnife[id][SLASH_SOUND][0]) { play_knife_sound(idg_eKnife[id][SLASH_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_STAB: if(g_eKnife[id][STAB_SOUND][0]) { play_knife_sound(idg_eKnife[id][STAB_SOUND][0]); return FMRES_SUPERCEDE; }
    }
    
    return 
FMRES_IGNORED
}

public 
ShowMenu(id)
{
    new 
szTitle[128]
    
formatex(szTitlecharsmax(szTitle), "%L"id"KM_MENU_TITLE")
    
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
eKnife[Knives], iFlags get_user_flags(id), ig_iKnivesNumi++)
    {
        
ArrayGetArray(g_aKnivesieKnife)
        
        if(
eKnife[FLAG] == ADMIN_ALL || iFlags eKnife[FLAG])
            
menu_additem(iMenuformatin("%s %s"eKnife[NAME], g_iKnife[id] == formatin("%L"id"KM_MENU_SELECTED") : formatin("")), eKnife[NAME])
        else
            
menu_additem(iMenuformatin("%s %L"eKnife[NAME], id"KM_MENU_VIP_ONLY"), eKnife[NAME], eKnife[FLAG])
    }
    
    if(
menu_pages(iMenu) > 1)
        
menu_setprop(iMenuMPROP_TITLEformatin("%s%L"szTitleid"KM_MENU_TITLE_PAGE"))
        
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        if(
g_iKnife[id] == iItem)
            
ColorChat(id"%L"id"KM_CHAT_ALREADY")
        else
        {
            
g_iKnife[id] = iItem
            ArrayGetArray
(g_aKnivesiItemg_eKnife[id])
            
            if(
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
                
OnSelectKnife(id)
            
            new 
szName[32], iUnused
            menu_item_getinfo
(iMenuiItemiUnusedszNamecharsmax(szName), .callback iUnused)
            
ColorChat(id"%L"id"KM_CHAT_SELECTED"szName)
        }
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
OnPlayerSpawn(id)
{
    if(
is_user_alive(id) && get_pcvar_num(g_pAtSpawn) && !g_iKnife[id] && g_bFirstTime[id])
    {
        
g_bFirstTime[id] = false
        ShowMenu
(id)
    }
}

public 
OnSelectKnife(id)
{
    
set_pev(idpev_viewmodel2g_eKnife[id][V_MODEL])
    
set_pev(idpev_weaponmodel2g_eKnife[id][P_MODEL])
}

PushKnife(eKnife[Knives])
{
    if(!
eKnife[V_MODEL][0])
        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), DEFAULT_V)
        
    if(!
eKnife[P_MODEL][0])
        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), DEFAULT_P)
        
    
ArrayPushArray(g_aKniveseKnife)
}

bool:is_knife_sound(const szSample[])
    return 
bool:equal(szSample[8], "kni"3)

detect_knife_sound(const szSample[])
{
    static 
iSound
    iSound 
SOUND_NONE
    
    
if(equal(szSample"weapons/knife_deploy1.wav"))
        
iSound SOUND_DEPLOY
    
else if(equal(szSample[14], "hit"3))
        
iSound szSample[17] == 'w' SOUND_HITWALL SOUND_HIT
    
else if(equal(szSample[14], "sla"3))
        
iSound SOUND_SLASH
    
else if(equal(szSample[14], "sta"3))
        
iSound SOUND_STAB
        
    
return iSound
}

use_vault(const id, const iType)
{
    if(!
g_szInfo[id][0])
        return
        
    new 
szData[40]
        
    switch(
iType)
    {
        case 
0:
        {
            
formatex(szDatacharsmax(szData), "%s|%i"g_eKnife[id][NAME], g_iKnife[id])
            
nvault_set(g_iVaultg_szInfo[id], szData)
        }
        case 
1:
        {
            new 
eKnife[Knives], szKnifeName[32], szKnifeNum[8]
            
nvault_get(g_iVaultg_szInfo[id], szDatacharsmax(szData))
            
strtok(szDataszKnifeNamecharsmax(szKnifeName), szKnifeNumcharsmax(szKnifeNum), '|')
            
            new 
iNumber str_to_num(szKnifeNum)
            
ArrayGetArray(g_aKnivesiNumbereKnife)
            
            if(
equali(szKnifeNameeKnife[NAME]) && (eKnife[FLAG] == ADMIN_ALL || get_user_flags(id) & eKnife[FLAG]))
                
g_iKnife[id] = iNumber
        
}
    }
}

play_knife_sound(id, const szSound[])
    
engfunc(EngFunc_EmitSoundidCHAN_WEAPONszSound1.0ATTN_NORM0PITCH_NORM)
    
ColorChat(const id, const szInput[], any:...)
{
    new 
iPlayers[32], iCount 1
    
static szMessage[191]
    
vformat(szMessagecharsmax(szMessage), szInput3)
    
format(szMessage[0], charsmax(szMessage), "%L %s"id id LANG_PLAYER"KM_CHAT_PREFIX"szMessage)
    
    
replace_all(szMessagecharsmax(szMessage), "!g""^4")
    
replace_all(szMessagecharsmax(szMessage), "!n""^1")
    
replace_all(szMessagecharsmax(szMessage), "!t""^3")
    
    if(
id)
        
iPlayers[0] = id
    
else
        
get_players(iPlayersiCount"ch")
    
    for(new 
iiCounti++)
    {
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEg_iSayText_iPlayers[i])
            
write_byte(iPlayers[i])
            
write_string(szMessage)
            
message_end()
        }
    }



This doesnt work, it doesnt save the skin. I tried it.

OciXCrom 10-30-2017 09:23

Re: Knife Models
 
I tried it too and it works.

panipani 11-01-2017 21:12

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2557569)
I tried it too and it works.

when i join the server and i write /knife it says that ive choosen the knife i had last map. But im not having it on me, im having the normal knife.

DevilBoy.eXe 11-02-2017 10:15

Re: Knife Models
 
What about damage cvar?

OciXCrom 11-02-2017 14:07

Re: Knife Models
 
The plugin focuses only on knife models. If I add damage, then people will ask to add gravity, speed, etc. There's no point of adding damage when everyone can change their knife model at any time.

Supergirl 12-09-2017 15:16

Re: Knife Models
 
I suggest you to add CT/TE knives, and for this, I mean: when you type /knife, it will open a menu with 2 options: CT knives and TE knives, so you can choose different knives for both teams (I know you can change them anytime, but it would still be nice, in my opinion) and save our choice by SteamID (as panipani said it is buggy).
Thank you for reading this.

highcoder 06-04-2018 17:25

Re: Knife Models
 
Hi OciXCrom,

I will report an bug. I define a flag for one knife, but all the knives are VIP. All the knives under the flagged knife are VIP. Could you please fix the problem?

OciXCrom 06-04-2018 17:42

Re: Knife Models
 
Show your KnifeModels.ini file content.

highcoder 06-04-2018 17:58

Re: Knife Models
 
The KnifeModels.ini file is below.


Code:

[M9 Bayonet]
V_MODEL = models/bayonet/v_knife.mdl
P_MODEL = models/bayonet/p_knife.mdl

[Karambit]
V_MODEL = models/karambit/v_knife.mdl
P_MODEL = models/karambit/p_knife.mdl
FLAG = b

[Huntsman]
V_MODEL = models/huntsman/v_knife.mdl
P_MODEL = models/huntsman/p_knife.mdl
FLAG = m

[Default]
V_MODEL = models/v_knife.mdl
P_MODEL = models/p_knife.mdl


OciXCrom 06-05-2018 07:05

Re: Knife Models
 
Try moving the default knife on top. Are you using the latest version of the plugin?

// Edit: nevermind, I saw what the problem is. Fixed. Download the new version (v2.1.1).

highcoder 06-05-2018 08:22

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2595383)
Try moving the default knife on top. Are you using the latest version of the plugin?

// Edit: nevermind, I saw what the problem is. Fixed. Download the new version (v2.1.1).

Thanks for your reply and update. I will try the plugin in the day.

highcoder 06-05-2018 15:12

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2595383)
Try moving the default knife on top. Are you using the latest version of the plugin?

// Edit: nevermind, I saw what the problem is. Fixed. Download the new version (v2.1.1).

Thanks for your reply and update again. I tried the plugin and not see a problem with the flag. The first written knife to KnifeModels.ini is the default knife. Is this a problem? Because in the source file shown the default knife directory.

OciXCrom 06-05-2018 15:40

Re: Knife Models
 
It's not a problem. I would actually recommend you to leave the first knife to be the default one.

highcoder 06-05-2018 15:55

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2595483)
It's not a problem. I would actually recommend you to leave the first knife to be the default one.

There is no need to change the default knife directory in the source file. Is not it?

warps013 06-05-2018 16:24

Re: Knife Models
 
Hi OciXcrom, sweet coding there, I really liked it! I was hoping... is there a way to replace guns models to player models? I know it would be different since chooseteam, but I would like to choose player models from a menu :) away from choosteam

OciXCrom 06-05-2018 18:12

Re: Knife Models
 
Quote:

Originally Posted by highcoder (Post 2595484)
There is no need to change the default knife directory in the source file. Is not it?

Don't change anything in the .sma file.

OciXCrom 06-05-2018 18:14

Re: Knife Models
 
Quote:

Originally Posted by warps013 (Post 2595487)
Hi OciXcrom, sweet coding there, I really liked it! I was hoping... is there a way to replace guns models to player models? I know it would be different since chooseteam, but I would like to choose player models from a menu :) away from choosteam

Thanks. There's probably a plugin like that made already. You can search for it. I don't feel like doing it.

highcoder 06-06-2018 02:18

Re: Knife Models
 
Quote:

Originally Posted by OciXCrom (Post 2595503)
Don't change anything in the .sma file.

Okay, thanks for your reply and update. Have a nice day!

HamletEagle 06-10-2018 09:56

Re: Knife Models
 
1.
PHP Code:

switch(detect_knife_sound(szSample))
    {
        case 
SOUND_DEPLOY: if(g_eKnife[id][DEPLOY_SOUND][0]) { play_knife_sound(idg_eKnife[id][DEPLOY_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HIT: if(g_eKnife[id][HIT_SOUND][0]) { play_knife_sound(idg_eKnife[id][HIT_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_HITWALL: if(g_eKnife[id][HITWALL_SOUND][0]) { play_knife_sound(idg_eKnife[id][HITWALL_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_SLASH: if(g_eKnife[id][SLASH_SOUND][0]) { play_knife_sound(idg_eKnife[id][SLASH_SOUND][0]); return FMRES_SUPERCEDE; }
        case 
SOUND_STAB: if(g_eKnife[id][STAB_SOUND][0]) { play_knife_sound(idg_eKnife[id][STAB_SOUND][0]); return FMRES_SUPERCEDE; }
    } 

This is pretty bad for readability. Way too many things on one line. IMO writting code in one line is ok only when you have one single instruction, like:
PHP Code:

if(!something) return 

2.Consider using ItemDeploy instead of CurWeapon.
3.
PHP Code:

else if(equal(szKey"DEPLOY_SOUND"))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    copy
(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
    
precache_sound(szValue)
}
else if(
equal(szKey"HIT_SOUND"))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    copy
(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
    
precache_sound(szValue)
}
else if(
equal(szKey"HITWALL_SOUND"))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    copy
(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
    
precache_sound(szValue)
}
else if(
equal(szKey"SLASH_SOUND"))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    copy
(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
    
precache_sound(szValue)
}
else if(
equal(szKey"STAB_SOUND"))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    copy
(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
    
precache_sound(szValue)


could be shortened to something like this:
PHP Code:

else 
                    {
                        
eKnife[HAS_CUSTOM_SOUND] = true
                        precache_sound
(szValue)
                        
                        if(
equal(szKey"DEPLOY_SOUND"))
                        {
                            
copy(eKnife[DEPLOY_SOUND], charsmax(eKnife[DEPLOY_SOUND]), szValue)
                        }
                        else if(
equal(szKey"HIT_SOUND"))
                        {
                            
copy(eKnife[HIT_SOUND], charsmax(eKnife[HIT_SOUND]), szValue)
                        }
                        else if(
equal(szKey"HITWALL_SOUND"))
                        {
                            
copy(eKnife[HITWALL_SOUND], charsmax(eKnife[HITWALL_SOUND]), szValue)
                        }
                        else if(
equal(szKey"SLASH_SOUND"))
                        {
                            
copy(eKnife[SLASH_SOUND], charsmax(eKnife[SLASH_SOUND]), szValue)
                        }
                        else if(
equal(szKey"STAB_SOUND"))
                        {
                            
copy(eKnife[STAB_SOUND], charsmax(eKnife[STAB_SOUND]), szValue)
                        }
                    }
                } 

to avoid duplicated code.
(could also use a switch and check for specific characters instead of using if and equal, but not very important)

Be consistent with naming conventions: you have things like play_knife_sound, detect_knife_sound and then things like ColorChat, PushKnife, etc. Use one style.

OciXCrom 06-11-2018 09:21

Re: Knife Models
 
Quote:

Originally Posted by HamletEagle (Post 2596238)
...

1. The code would look quite duplicated if it's in multiple lines. I'd rather have it like this. I added some indendation to make it more readable.

2. Done.

3. Not exactly like that, because it doesn't need to precache a sound every time. I changed it however so it's no longer duplicated.

PHP Code:

static const szModelArg[] = "_MODEL"
static const szSoundArg[] = "_SOUND"

if(contain(szKeyszModelArg))
    
precache_model(szValue)
else if(
contain(szKeyszSoundArg))
{
    
eKnife[HAS_CUSTOM_SOUND] = true
    precache_sound
(szValue)


4. Done.

HamletEagle 06-11-2018 17:27

Re: Knife Models
 
After a very fast check it looks fine.

CrAzY MaN 06-12-2018 01:18

Re: Knife Models
 
Congrats OciXCorn for the approval!

OciXCrom 06-12-2018 07:29

Re: Knife Models
 
Thanks. It's nice to see that at least one approver is still alive.

OciXCrom 06-30-2018 10:40

Re: Knife Models [XP System Support!]
 
https://img.shields.io/badge/update-...2018-green.svg
  • Added support for OciXCrom's Rank System.
  • This will allow you to make specific knives available only for players who reached a specific level in the rank system.

https://i.imgur.com/Ni54An2.png

xeloxded 06-30-2018 21:37

Re: Knife Models [XP System Support]
 
What do I need to change to instead of using Knife models but Player models? Thanks, nice plugin btw
nice plugin btw, another question, Instead of showing LEVEL: 1 how can I show Rank: XX?

HamletEagle 07-01-2018 06:25

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by xeloxded (Post 2600219)
What do I need to change to instead of using Knife models but Player models? Thanks, nice plugin btw
nice plugin btw, another question, Instead of showing LEVEL: 1 how can I show Rank: XX?

You are asking for a totally different plugin.

OciXCrom 07-01-2018 07:51

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by xeloxded (Post 2600219)
What do I need to change to instead of using Knife models but Player models? Thanks, nice plugin btw
nice plugin btw, another question, Instead of showing LEVEL: 1 how can I show Rank: XX?

Like HamletEagle said, player models are totally irrelevant to this thread. I may make such a plugin soon though.
You can change the text from the language file - data/lang/KnifeModels.txt

Supergirl 07-01-2018 14:48

Re: Knife Models [XP System Support]
 
Nice updates! Gonna test it soon. But... Since you did not answer, do you feel like doing this? Great job.

Quote:

Originally Posted by Supergirl (Post 2565283)
I suggest you to add CT/TE knives, and for this, I mean: when you type /knife, it will open a menu with 2 options: CT knives and TE knives, so you can choose different knives for both teams (I know you can change them anytime, but it would still be nice, in my opinion) and save our choice by SteamID (as panipani said it is buggy).
Thank you for reading this.


OciXCrom 07-01-2018 15:00

Re: Knife Models [XP System Support]
 
Having different knives for both teams bothers me because when the player switches team, the knife should be removed. I'll see what I can do.

xeloxded 07-01-2018 15:01

Re: Knife Models [XP System Support]
 
I mean I need to change Level: 1 to Rank: Newbie, how to do so?


All times are GMT -4. The time now is 07:37.

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