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 07-01-2018 15:26

Re: Knife Models [XP System Support]
 
Ugh, why would you want to do that? It's much easier for people to know the required level number instead of remembering all of the the rank names. I'll add an option in the next update though.

xeloxded 07-01-2018 15:55

Re: Knife Models [XP System Support]
 
Well, I mean its more beauty to look at Ranks instead of a flat number.. Waiting for that, thank you

OciXCrom 07-02-2018 09:35

Re: Knife Models [XP System Support]
 
https://img.shields.io/badge/update-...2018-green.svg
  • Added a cvar to save the selected knife via SteamID after leaving the server (km_save_choice 1).
  • Added an option in the .ini file to display the rank name instead of the level number when using the rank system (SHOW_RANK = 1).
  • Added an option to set a sound when selecting the knife from the menu.

Supergirl 07-02-2018 11:39

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by OciXCrom (Post 2600373)
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.

I think I got you, but maybe I didn't explain clearly my thoughts: the knife wouldn't be removed. Instead, it would just change when the player switches team. Let's say that player X has knife Y on CT side. If he switches to TE side, it will automatically change to his knife on TE side (both team knives would be saved by SteamID, instead of just "the one" as you added in last update today). Although I don't play CS: GO anymore, I think the idea came from it (because you can choose 2 different skins for the 2 different teams). For this to be made, I think it must have some "TEAM" parameter (some knives would be allowed only for TEs and some only for CTs, because in doing so, people would be able to put the same weapon skin with different gloves for the 2 teams, I don't know, just thinking).
Thank you for your work. This is incredible! :)

xeloxded 07-02-2018 13:47

Re: Knife Models [XP System Support]
 
Still shows LEVEL = 2
Quote:

[Test]
V_MODEL = models/v_knife.mdl
P_MODEL = models/p_knife.mdl
LEVEL = 2
SHOW_RANK = 1

OciXCrom 07-02-2018 14:07

Re: Knife Models [XP System Support]
 
@Supergirl - you're right. I'll make separate parameters for both teams and you'll be able to have a different knife depending on which team you are.

@xeloxdex - you probably didn't fully update the plugin. Make sure you download and recompile the .sma file and replace the .amxx one. I tested it multiple times and it works perfectly.

xeloxded 07-02-2018 14:08

Re: Knife Models [XP System Support]
 
Yeah, I did everything, not sure what I did wrong...

Not sure what I did but managed to make it work, now it fully works.

xeloxded 07-02-2018 22:33

Re: Knife Models [XP System Support]
 
When I switch to another weapon, it wont save my knife...

OciXCrom 07-03-2018 08:06

Re: Knife Models [XP System Support]
 
Oops! Fixed, sorry about that. Update only crx_knife_models.sma/amxx.

Supergirl 07-03-2018 10:05

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by OciXCrom (Post 2600598)
@Supergirl - you're right. I'll make separate parameters for both teams and you'll be able to have a different knife depending on which team you are.

Take your time. Once again, thank you and good work!
Edit - Having some thoughts... why not having more than custom knives for both teams: why not having default knives for both teams (for this I mean when you enter the server instead of the "Default" knife, it will have 2 "Default" knives, one for TE and one for CT)? Is it possible to manage the plugin to do so?

xeloxded 07-03-2018 13:39

Re: Knife Models [XP System Support]
 
I got a bug, if you are CT then choose a custom knife and then you switch to TT, it will reset to your default CS knife but with your custom knife selected on menu

Edit: This does only happen because on Deathrun mode you only have a Knife as TT, it wont refresh, but if you give a TT a weapon it will give you your desired model.
Another suggestion is that Save selection has to be via Nick too, its useless if you are using your Rank System with Nick save.

Supergirl 07-03-2018 17:32

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by xeloxded (Post 2600793)
I got a bug, if you are CT then choose a custom knife and then you switch to TT, it will reset to your default CS knife but with your custom knife selected on menu

Edit: This does only happen because on Deathrun mode you only have a Knife as TT, it wont refresh, but if you give a TT a weapon it will give you your desired model.
Another suggestion is that Save selection has to be via Nick too, its useless if you are using your Rank System with Nick save.

The thing is (in my perspective): why would you want to save anything by nick? That doesn't make any sense to me. Isn't that even dangerous? I mean, anybody can join the server, pick your name and achieve the next rank or loose the current.

xeloxded 07-03-2018 17:43

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by Supergirl (Post 2600841)
The thing is (in my perspective): why would you want to save anything by nick? That doesn't make any sense to me. Isn't that even dangerous? I mean, anybody can join the server, pick your name and achieve the next rank or loose the current.


Ya, also SteamID is so easy to spoof on 2k18, IP is also risky, so yeah, it depends A LOT on each server, on my side, I have a pretty decent register system so yeah, Nick is secure for everyone.

OciXCrom 07-04-2018 08:36

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by Supergirl (Post 2600739)
Edit - Having some thoughts... why not having more than custom knives for both teams: why not having default knives for both teams (for this I mean when you enter the server instead of the "Default" knife, it will have 2 "Default" knives, one for TE and one for CT)? Is it possible to manage the plugin to do so?

Not sure how I'm going to do this, but I'll see what I can do. I feel like the plugin's code is going to get a lot complicated.

Quote:

Originally Posted by xeloxded (Post 2600793)
I got a bug, if you are CT then choose a custom knife and then you switch to TT, it will reset to your default CS knife but with your custom knife selected on menu

Edit: This does only happen because on Deathrun mode you only have a Knife as TT, it wont refresh, but if you give a TT a weapon it will give you your desired model.

Yup, just tested with a plugin that removes weapons on spawn, same thing happened. This is actually a bug from the hamsandwich module, looks like the function doesn't get called quickly enough to detect that the weapon was removed. Fixed (update the .sma file).

@HamletEagle - I'm switching back to using CurWeapon instead of Ham_Deploy because of this problem. I experienced something simillar in another plugin. I'll need to use a task in order to prevent it, but that doesn't feel right, so I prefer CurWeapon.

Quote:

Originally Posted by xeloxded (Post 2600793)
Another suggestion is that Save selection has to be via Nick too, its useless if you are using your Rank System with Nick save.

Better not mention that you're using a non-steam server here.

Supergirl 07-04-2018 22:01

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by OciXCrom (Post 2600944)
Not sure how I'm going to do this, but I'll see what I can do. I feel like the plugin's code is going to get a lot complicated.

No hurries, mate! :)

HamletEagle 07-07-2018 05:55

Re: Knife Models [XP System Support]
 
Quote:

Yup, just tested with a plugin that removes weapons on spawn, same thing happened. This is actually a bug from the hamsandwich module, looks like the function doesn't get called quickly enough to detect that the weapon was removed. Fixed (update the .sma file).

@HamletEagle - I'm switching back to using CurWeapon instead of Ham_Deploy because of this problem. I experienced something simillar in another plugin. I'll need to use a task in order to prevent it, but that doesn't feel right, so I prefer CurWeapon.
What bug are you talking about? Can you post a simple plugin that reproduces the said bug?
Also know that hamsandwich module can't have bugs, it just hooks functions from the game dll.

OciXCrom 07-07-2018 08:07

Re: Knife Models [XP System Support]
 
Actually, I just tested it again and I think the problem is from fakemeta, not hamsandwich. Here's the code that won't work:

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun>
#include <hamsandwich>

#if !defined m_pPlayer
    #define m_pPlayer 41
#endif

#define V_MODEL "models/iplaydr/v_knife20.mdl"
#define P_MODEL "models/iplaydr/p_knife20.mdl"

public plugin_init()
{
    
register_plugin("PluginName""1.0""OciXCrom")
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
    
RegisterHam(Ham_Item_Deploy"weapon_knife""OnKnifeDeploy"1)
    
//register_event("CurWeapon", "OnKnifeDeploy", "be", "1=1", "2=29")
}

public 
plugin_precache()
{
    
precache_model(V_MODEL)
    
precache_model(P_MODEL)
}

public 
OnPlayerSpawn(id)
{
    if(
is_user_alive(id))
    {
        
strip_user_weapons(id)
        
give_item(id"weapon_knife")
    }
}    

public 
OnKnifeDeploy(iEnt)
{
    new 
id pev(iEntpev_owner)
    
//new id = get_pdata_cbase(iEnt, 41, 5)
    
client_print(0print_chat"id is %i"id)
    
set_pev(idpev_viewmodel2V_MODEL)
    
set_pev(idpev_weaponmodel2P_MODEL)


This happens only if the weapons are removed on spawn.
The same code will work without problems if we use the CurWeapon event instead.

With the testing I just did, I found that using pev(iEnt, pev_owner) to get the player's id returns 0 which is why the models isn't set. It returns the correct id however if the weapons aren't removed on spawn.

Getting the id with get_pdata_cbase(iEnt, 41, 5) returns the correct value and the model is set.

HamletEagle 07-07-2018 13:29

Re: Knife Models [XP System Support]
 
Then there is no bug. pev_owner is not set at that point, this is why you must use m_pPlayer offset to retrieve the player index.
So please switch back to ItemDeploy and use m_pPlayer instead of pev_owner.

OciXCrom 07-07-2018 15:06

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by HamletEagle (Post 2601702)
Then there is no bug. pev_owner is not set at that point, this is why you must use m_pPlayer offset to retrieve the player index.
So please switch back to ItemDeploy and use m_pPlayer instead of pev_owner.

Done.

PS: if you want to have a look and approve this one as well, since it uses pretty much the same code.

CzechPeter 07-11-2018 12:17

Re: Knife Models [XP System Support]
 
Code:

"L 07/11/2018 - 18:15:16: [AMXX] Run time error 10: native error (native "clamp")
L 07/11/2018 - 18:15:16: [AMXX]    [0] yb983cxt.sma.p::use_vault (line 677)
L 07/11/2018 - 18:15:16: [AMXX]    [1] yb983cxt.sma.p::ReadData (line 452)
L 07/11/2018 - 18:15:16: [AMXX] Displaying debug trace (plugin "crx_ranksystem.amxx", version "unknown)"

Please help :(

OciXCrom 07-11-2018 17:04

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by CzechPeter (Post 2602969)
Code:

"L 07/11/2018 - 18:15:16: [AMXX] Run time error 10: native error (native "clamp")
L 07/11/2018 - 18:15:16: [AMXX]    [0] yb983cxt.sma.p::use_vault (line 677)
L 07/11/2018 - 18:15:16: [AMXX]    [1] yb983cxt.sma.p::ReadData (line 452)
L 07/11/2018 - 18:15:16: [AMXX] Displaying debug trace (plugin "crx_ranksystem.amxx", version "unknown)"

Please help :(

Why did you post this here? Look in which plugin the error is.

CzechPeter 07-12-2018 03:21

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by OciXCrom (Post 2603039)
Why did you post this here? Look in which plugin the error is.

Yeah sorry. :D

OciXCrom 07-13-2018 08:43

Re: Knife Models [XP System Support]
 
https://img.shields.io/badge/update-...2018-green.svg
  • Added an option for the skins to require a certain amount of XP.

negat1we 07-27-2018 07:14

Re: Knife Models [XP System Support]
 
L 07/18/2018 - 02:38:24: [AMXX] Displaying debug trace (plugin "crx_knife_models.amxx", version "2.5")
L 07/18/2018 - 02:38:24: [AMXX] Run time error 4: index out of bounds
L 07/18/2018 - 02:38:24: [AMXX] [0] crx_knife_models.sma::RefreshKnifeModel (line 410)
L 07/18/2018 - 02:38:24: [AMXX] [1] crx_knife_models.sma::OnSelectKnife (line 406)

OciXCrom 07-27-2018 08:10

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by negat1we (Post 2606398)
L 07/18/2018 - 02:38:24: [AMXX] Displaying debug trace (plugin "crx_knife_models.amxx", version "2.5")
L 07/18/2018 - 02:38:24: [AMXX] Run time error 4: index out of bounds
L 07/18/2018 - 02:38:24: [AMXX] [0] crx_knife_models.sma::RefreshKnifeModel (line 410)
L 07/18/2018 - 02:38:24: [AMXX] [1] crx_knife_models.sma::OnSelectKnife (line 406)

It should be fixed now.

Lyklor 07-30-2018 03:37

Re: Knife Models [XP System Support]
 
The knife model turns back to default one when i switch weapons, why? This was not happening in older versions. Thx btw.

OciXCrom 07-30-2018 08:21

Re: Knife Models [XP System Support]
 
It works fine for me, just tested it. Make sure you downloaded the latest version (2.5.1), because there was such a bug in the previous version. If the bug still occurs, see if it works like this:

PHP Code:

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

native crxranks_get_max_levels()
native crxranks_get_rank_by_level(levelbuffer[], len)
native crxranks_get_user_level(id)
native crxranks_get_user_xp(id)

new const 
g_szNatives[][] =
{
    
"crxranks_get_max_levels",
    
"crxranks_get_rank_by_level",
    
"crxranks_get_user_level",
    
"crxranks_get_user_xp"
}

#if !defined m_pPlayer
    #define m_pPlayer 41
#endif

#if defined client_disconnected
    #define client_disconnect client_disconnected
#endif

#define PLUGIN_VERSION "2.5.1"
#define DEFAULT_V "models/v_knife.mdl"
#define DEFAULT_P "models/p_knife.mdl"
#define DELAY_ON_CONNECT 2.5
#define MAX_SOUND_LENGTH 128
#define MAX_AUTHID_LENGTH 35

#if !defined MAX_NAME_LENGTH
    #define MAX_NAME_LENGTH 32
#endif

#if !defined MAX_PLAYERS
    #define MAX_PLAYERS 32
#endif

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

enum _:Knives
{
    
NAME[MAX_NAME_LENGTH],
    
V_MODEL[MAX_SOUND_LENGTH],
    
P_MODEL[MAX_SOUND_LENGTH],
    
DEPLOY_SOUND[MAX_SOUND_LENGTH],
    
HIT_SOUND[MAX_SOUND_LENGTH],
    
HITWALL_SOUND[MAX_SOUND_LENGTH],
    
SLASH_SOUND[MAX_SOUND_LENGTH],
    
STAB_SOUND[MAX_SOUND_LENGTH],
    
SELECT_SOUND[MAX_SOUND_LENGTH],
    
FLAG,
    
LEVEL,
    
bool:SHOW_RANK,
    
bool:HAS_CUSTOM_SOUND,
    
XP
}

new Array:
g_aKnives,
    
bool:g_bFirstTime[MAX_PLAYERS 1],
    
bool:g_bRankSystem,
    
bool:g_bGetLevel,
    
bool:g_bGetXP,
    
g_eKnife[MAX_PLAYERS 1][Knives],
    
g_szAuth[MAX_PLAYERS 1][MAX_AUTHID_LENGTH],
    
g_iKnife[MAX_PLAYERS 1],
    
g_iCallback,
    
g_pAtSpawn,
    
g_pSaveChoice,
    
g_iSaveChoice,
    
g_iKnivesNum,
    
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")
    
    
RegisterHam(Ham_Spawn"player""OnPlayerSpawn"1)
    
register_forward(FM_EmitSound,    "OnEmitSound")
    
register_event("CurWeapon""OnSelectKnife""be""1=1""2=29")
    
    
register_clcmd("say /knife""ShowMenu")
    
register_clcmd("say_team /knife""ShowMenu")
    
    
g_iCallback menu_makecallback("CheckKnifeAccess")
    
g_pAtSpawn register_cvar("km_open_at_spawn""0")
    
g_pSaveChoice register_cvar("km_save_choice""0")
}

public 
plugin_precache()
{
    if(
LibraryExists("crxranks"LibType_Library))
        
g_bRankSystem true
        
    g_aKnives 
ArrayCreate(Knives)
    
ReadFile()
}

public 
plugin_cfg()
{
    
g_iSaveChoice get_pcvar_num(g_pSaveChoice)
    
    if(
g_iSaveChoice)
        
g_iVault nvault_open("KnifeModels")
}

public 
plugin_natives()
    
set_native_filter("native_filter")
    
public 
native_filter(const szNative[], idiTrap)
{
    if(!
iTrap)
    {
        static 
i
        
        
for(0sizeof(g_szNatives); i++)
        {
            if(
equal(szNativeg_szNatives[i]))
                return 
PLUGIN_HANDLED
        
}
    }
    
    return 
PLUGIN_CONTINUE
}
    
public 
plugin_end()
{
    
ArrayDestroy(g_aKnives)
    
    if(
g_iSaveChoice)
        
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], iMaxLevels
        
new eKnife[Knives], bool:bCustom
        
        
if(g_bRankSystem)
            
iMaxLevels crxranks_get_max_levels()
        
        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)
                        
                        
eKnife[V_MODEL][0] = EOS
                        eKnife
[P_MODEL][0] = EOS
                        eKnife
[DEPLOY_SOUND][0] = EOS
                        eKnife
[HIT_SOUND][0] = EOS
                        eKnife
[HITWALL_SOUND][0] = EOS
                        eKnife
[SLASH_SOUND][0] = EOS
                        eKnife
[STAB_SOUND][0] = EOS
                        eKnife
[SELECT_SOUND][0] = EOS
                        eKnife
[FLAG] = ADMIN_ALL
                        eKnife
[HAS_CUSTOM_SOUND] = false
                        
                        
if(g_bRankSystem)
                        {
                            
eKnife[LEVEL] = 0
                            eKnife
[SHOW_RANK] = false
                            eKnife
[XP] = 0
                        
}
                    }
                    else continue
                }
                default:
                {
                    
strtok(szDataszKeycharsmax(szKey), szValuecharsmax(szValue), '=')
                    
trim(szKey); trim(szValue)
                    
bCustom true
                    
                    
if(equal(szKey"FLAG"))
                        
eKnife[FLAG] = read_flags(szValue)
                    else if(
equal(szKey"LEVEL") && g_bRankSystem)
                    {
                        
eKnife[LEVEL] = clamp(str_to_num(szValue), 0iMaxLevels)
                        
                        if(!
g_bGetLevel)
                            
g_bGetLevel true
                    
}
                    else if(
equal(szKey"SHOW_RANK") && g_bRankSystem)
                        
eKnife[SHOW_RANK] = _:clamp(str_to_num(szValue), falsetrue)
                    else if(
equal(szKey"XP") && g_bRankSystem)
                    {
                        
eKnife[XP] = _:clamp(str_to_num(szValue), 0)
                        
                        if(!
g_bGetXP)
                            
g_bGetXP true
                    
}
                    else if(
equal(szKey"V_MODEL"))
                        
copy(eKnife[V_MODEL], charsmax(eKnife[V_MODEL]), szValue)
                    else if(
equal(szKey"P_MODEL"))
                        
copy(eKnife[P_MODEL], charsmax(eKnife[P_MODEL]), szValue)
                    else 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)
                    else if(
equal(szKey"SELECT_SOUND"))
                    {
                        
bCustom false
                        copy
(eKnife[SELECT_SOUND], charsmax(eKnife[SELECT_SOUND]), szValue)
                    }
                    else continue
                    
                    static const 
szModelArg[] = "_MODEL"
                    
static const szSoundArg[] = "_SOUND"
                    
                    
if(contain(szKeyszModelArg) != -1)
                        
precache_model(szValue)
                    else if(
contain(szKeyszSoundArg) != -1)
                    {
                        
precache_sound(szValue)
                        
                        if(
bCustom)
                            
eKnife[HAS_CUSTOM_SOUND] = true
                    
}
                }
            }
        }
        
        if(
g_iKnivesNum)
            
PushKnife(eKnife)
        
        
fclose(iFilePointer)
    }
}

public 
client_authorized(id)
{
    
g_bFirstTime[id] = true
    ArrayGetArray
(g_aKnives0g_eKnife[id])
    
g_iKnife[id] = 0
    
    
if(g_iSaveChoice)
    {
        
get_user_authid(idg_szAuth[id], charsmax(g_szAuth[]))
        
set_task(DELAY_ON_CONNECT"LoadData"id)
    }
}

public 
client_disconnect(id)
{
    if(
g_iSaveChoice)
        
UseVault(idtrue)
}

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

public 
ShowMenu(id)
{
    static 
eKnife[Knives]
    new 
szTitle[128], szItem[128], iLeveliXP
    formatex
(szTitlecharsmax(szTitle), "%L"id"KM_MENU_TITLE")

    if(
g_bGetLevel)
        
iLevel crxranks_get_user_level(id)
    
    if(
g_bGetXP)
        
iXP crxranks_get_user_xp(id)
        
    new 
iMenu menu_create(szTitle"MenuHandler")
    
    for(new 
iFlags get_user_flags(id), ig_iKnivesNumi++)
    {
        
ArrayGetArray(g_aKnivesieKnife)
        
copy(szItemcharsmax(szItem), eKnife[NAME])
        
        if(
g_bRankSystem)
        {
            if(
eKnife[LEVEL] && iLevel eKnife[LEVEL])
            {
                if(
eKnife[SHOW_RANK])
                {
                    static 
szRank[32]
                    
crxranks_get_rank_by_level(eKnife[LEVEL], szRankcharsmax(szRank))
                    
format(szItemcharsmax(szItem), "%s %L"szItemid"KM_MENU_RANK"szRank)
                }
                else
                    
format(szItemcharsmax(szItem), "%s %L"szItemid"KM_MENU_LEVEL"eKnife[LEVEL])
            }
            
            if(
eKnife[XP] && iXP eKnife[XP])
                
format(szItemcharsmax(szItem), "%s %L"szItemid"KM_MENU_XP"eKnife[XP])
        }
        
        if(
eKnife[FLAG] != ADMIN_ALL && !(iFlags eKnife[FLAG]))
            
format(szItemcharsmax(szItem), "%s %L"szItemid"KM_MENU_VIP_ONLY")
            
        if(
g_iKnife[id] == i)
            
format(szItemcharsmax(szItem), "%s %L"szItemid"KM_MENU_SELECTED")
        
        
menu_additem(iMenuszItemeKnife[NAME], eKnife[FLAG], g_iCallback)
    }
    
    if(
menu_pages(iMenu) > 1)
    {
        
formatex(szItemcharsmax(szItem), "%s%L"szTitleid"KM_MENU_TITLE_PAGE")
        
menu_setprop(iMenuMPROP_TITLEszItem)
    }
        
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
MenuHandler(idiMenuiItem)
{
    if(
iItem != MENU_EXIT)
    {
        
g_iKnife[id] = iItem
        ArrayGetArray
(g_aKnivesiItemg_eKnife[id])
        
        if(
is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
            
RefreshKnifeModel(id)
        
        new 
szName[MAX_NAME_LENGTH], iUnused
        menu_item_getinfo
(iMenuiItemiUnusedszNamecharsmax(szName), .callback iUnused)
        
CC_SendMessage(id"%L %L"id"KM_CHAT_PREFIX"id"KM_CHAT_SELECTED"szName)
        
        if(
g_eKnife[id][SELECT_SOUND][0])
            
PlayKnifeSound(idg_eKnife[id][SELECT_SOUND])
    }
    
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
LoadData(id)
    
UseVault(idfalse)

public 
CheckKnifeAccess(idiMenuiItem)
    return ((
g_iKnife[id] == iItem) || !HasKnifeAccess(idiItem)) ? ITEM_DISABLED ITEM_ENABLED

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)
    
RefreshKnifeModel(id)

RefreshKnifeModel(const 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:HasKnifeAccess(const id, const iKnife)
{        
    static 
eKnife[Knives]
    
ArrayGetArray(g_aKnivesiKnifeeKnife)
    
    if(
g_bRankSystem)
    {
        if(
eKnife[LEVEL] && crxranks_get_user_level(id) < eKnife[LEVEL])
            return 
false
            
        
if(eKnife[XP] && crxranks_get_user_xp(id) < eKnife[XP])
            return 
false
    
}
        
    if(
eKnife[FLAG] != ADMIN_ALL && !(get_user_flags(id) & eKnife[FLAG]))
        return 
false
        
    
return true
}

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

DetectKnifeSound(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
}

UseVault(const id, const bool:bSave)
{
    if(
bSave)
    {
        static 
szData[4]
        
num_to_str(g_iKnife[id], szDatacharsmax(szData))
        
nvault_set(g_iVaultg_szAuth[id], szData)
    }
    else
    {
        static 
iKnife
        iKnife 
nvault_get(g_iVaultg_szAuth[id])
        
        if(
iKnife g_iKnivesNum)
            
iKnife 0
        
        
if(iKnife && HasKnifeAccess(idiKnife))
        {
            
g_iKnife[id] = iKnife
            
            
if(is_user_alive(id) && get_user_weapon(id) == CSW_KNIFE)
                
RefreshKnifeModel(id)
        }
    }
}

PlayKnifeSound(const id, const szSound[])
    
engfunc(EngFunc_EmitSoundidCHAN_AUTOszSound1.0ATTN_NORM0PITCH_NORM


Lyklor 07-31-2018 08:20

Re: Knife Models [XP System Support]
 
Worked thanks! I'm using it on Xash3D, idk but maybe that's why the newest version wasn't working? Anyway it's working now!

EDIT

I found out that when i reconnect to the server, my selected knife model is shown as SELECTED on the menu but the model and sounds is reverted to default one.

Btw, it would be cool if you can add a draw animation on knife selection. Just an suggestion!

OciXCrom 07-31-2018 08:44

Re: Knife Models [XP System Support]
 
I fixed both issues now, download the plugin again (only the .sma file) and recompile. I also added a protection for the server not to crash if a model set in the .ini file doesn't exist.

About the animation - I like the idea, but I'm not sure if all models have the same animation ids. I'll have a look and add it if it's possible.

@HamletEagle - sorry, but yet again I switched back to CurWeapon. The guy above is a clear example that the hamsandwich method simply doesn't work properly. I had 2 other people say the same thing in another forum and it worked for them when I sent them a CurWeapon version. I don't know when and why this is happening, but it's clearly a problem. I'm pretty sure it's happening only on Linux.

HamletEagle 08-04-2018 10:15

Re: Knife Models [XP System Support]
 
Quote:

@HamletEagle - sorry, but yet again I switched back to CurWeapon. The guy above is a clear example that the hamsandwich method simply doesn't work properly. I had 2 other people say the same thing in another forum and it worked for them when I sent them a CurWeapon version. I don't know when and why this is happening, but it's clearly a problem. I'm pretty sure it's happening only on Linux.
Anecdotal evidence is just that, nothing more.
Ham_Item_Deploy is just a hook for Deploy(), which is where game sets models. That's literally how it's done inside game, there is no reason for it not to work, except really outdated game binaries. Using Ham_Item_Deploy to set models it's really not a new or fancy thing.
Example:
https://github.com/s1lentq/ReGameDLL...n_ak47.cpp#L55
If you insist that there is an issue find a way to reproduce it and get some debug logs, which should tell if the forward is even called, if the owner is retrieved sucessfully and so on.

I'm sorry but I'll have to unapprove if you wish to stick with CurWeapon, as this is not optimal.


Edit: I looked at your old code and it is wrong.
PHP Code:

new id get_pdata_cbase(iEntm_pPlayer

You forgot the linux extra offset:
PHP Code:

new id get_pdata_cbase(iEntm_pPlayer4

which explains why the "bug" was noticed only under linux. The extra offset is 5 only for players and grenades.

OciXCrom 08-04-2018 10:34

Re: Knife Models [XP System Support]
 
Blah, silly me, totally forgot that the offset argument even exists. :mrgreen:
I'll switch it back *again* in a few hours.

negat1we 09-01-2018 10:06

Re: Knife Models [XP System Support]
 
i have a problem with knife models. when i enter on my server i don't have selected item, is default but in menu is selected.

OciXCrom 09-01-2018 10:23

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by negat1we (Post 2613186)
i have a problem with knife models. when i enter on my server i don't have selected item, is default but in menu is selected.

Fixed.

negat1we 09-03-2018 18:15

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by OciXCrom (Post 2613193)
Fixed.

i put 3 skins with FLAG and i change map or i exit and enter on server is not save my skin.
He put default skin in menu.

( Knife / awp plugins skins flag problem )

OciXCrom 09-04-2018 08:07

Re: Knife Models [XP System Support]
 
Did you enable the skin saving option?

negat1we 09-04-2018 10:01

Re: Knife Models [XP System Support]
 
yes, but only skins with flag is not saving.

moresa 09-14-2018 21:12

Re: Knife Models [XP System Support]
 
the sounds didn't work for me

OciXCrom 09-15-2018 15:47

Re: Knife Models [XP System Support]
 
Quote:

Originally Posted by moresa (Post 2615262)
the sounds didn't work for me

What did you write in the .ini exactly? Did you add "sound/" before the sound name?

Elit59 11-20-2018 10:54

Re: Knife Models [XP System Support]
 
GJ :)

C00LSH33P 12-22-2018 19:05

Re: Knife Models [XP System Support]
 
1. Does everybody else in the server sees what skin(p_model) you currently using?
2. Is the model change update in realtime?

Sorry if been asked before.


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

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