Raised This Month: $32 Target: $400
 8% 

Knife Models [XP System & Skills Support]


Post New Thread Reply   
 
Thread Tools Display Modes
panipani
Member
Join Date: Oct 2017
Old 10-30-2017 , 00:34   Re: Knife Models
Reply With Quote #51

Quote:
Originally Posted by OciXCrom View Post
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.
panipani is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 10-30-2017 , 09:23   Re: Knife Models
Reply With Quote #52

I tried it too and it works.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
panipani
Member
Join Date: Oct 2017
Old 11-01-2017 , 21:12   Re: Knife Models
Reply With Quote #53

Quote:
Originally Posted by OciXCrom View Post
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.
panipani is offline
DevilBoy.eXe
Member
Join Date: Mar 2017
Location: Romania
Old 11-02-2017 , 10:15   Re: Knife Models
Reply With Quote #54

What about damage cvar?
__________________

DevilBoy.eXe is offline
Send a message via Yahoo to DevilBoy.eXe Send a message via Skype™ to DevilBoy.eXe
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 11-02-2017 , 14:07   Re: Knife Models
Reply With Quote #55

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Supergirl
Member
Join Date: Jul 2016
Old 12-09-2017 , 15:16   Re: Knife Models
Reply With Quote #56

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.

Last edited by Supergirl; 12-10-2017 at 10:50.
Supergirl is offline
highcoder
Member
Join Date: Jun 2018
Old 06-04-2018 , 17:25   Re: Knife Models
Reply With Quote #57

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?
highcoder is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-04-2018 , 17:42   Re: Knife Models
Reply With Quote #58

Show your KnifeModels.ini file content.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
highcoder
Member
Join Date: Jun 2018
Old 06-04-2018 , 17:58   Re: Knife Models
Reply With Quote #59

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
highcoder is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-05-2018 , 07:05   Re: Knife Models
Reply With Quote #60

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).
__________________

Last edited by OciXCrom; 06-05-2018 at 07:13.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 00:43.


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