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


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

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