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

[CSGO] Issue with cstrike's CS_WeaponIDToLoadoutSlot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hacker13dev
New Member
Join Date: Feb 2023
Old 04-19-2023 , 13:01   [CSGO] Issue with cstrike's CS_WeaponIDToLoadoutSlot
Reply With Quote #1

Hi, I've beeen lately having a little problem with cstrike's function CS_WeaponIDToLoadoutSlot introduced in SM 1.12 build 6997
https://github.com/alliedmodders/sou...881c83c5d51e81
https://sourcemod.dev/#/cstrike/func...DToLoadoutSlot

SourceMod Version: 1.12.0.7016
Metamod:Source version 1.12.0-dev+1167 (Doesn't work with stable etiher)

Code:
public void OnClientPostAdminCheck(int client)
{
    SDKHook(client, SDKHook_WeaponCanUse, OnWeaponCanUse);
}

public Action OnWeaponCanUse(int client, int weapon)
{
    int def = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
    CSWeaponID csweapon = CS_ItemDefIndexToID(def);
    if(!CS_IsValidWeaponID(csweapon)) return Plugin_Continue;

    int slot = CS_WeaponIDToLoadoutSlot(csweapon);
    PrintToChatAll("slot val: %d", slot);

    return Plugin_Continue;
}


The issue is that, based on my testing, CS_WeaponIDToLoadoutSlot(csweapon); always keeps returning 0. I'm unsure if there's a problem with the code or if the function isn't fully functional yet.

Last edited by Hacker13dev; 04-19-2023 at 13:13.
Hacker13dev is offline
L4D2Noob
AlliedModders Donor
Join Date: Mar 2020
Location: Moscow
Old 04-30-2023 , 17:03   Re: [CSGO] Issue with cstrike's CS_WeaponIDToLoadoutSlot
Reply With Quote #2

If the CS_WeaponIDToLoadoutSlot function always returns 0, this may be due to incorrect usage of the function or an error in its implementation.

First, make sure you are passing the arguments correctly to the function. The CS_WeaponIDToLoadoutSlot function requires the argument to be a valid CSWeaponID. In your code, csweapon is obtained from m_iItemDefinitionIndex, which may be an invalid def. Make sure you are correctly obtaining m_iItemDefinitionIndex for the specific weapon.

It may also be helpful to check the implementation of the CS_WeaponIDToLoadoutSlot function. It may not be working correctly or require certain conditions to return the correct result. Check the documentation or source code of the function, if possible, to determine how to correctly use it and what conditions it requires for proper operation.
__________________
L4D2Noob is offline
Send a message via ICQ to L4D2Noob Send a message via Skype™ to L4D2Noob
Hacker13dev
New Member
Join Date: Feb 2023
Old 06-14-2023 , 15:15   Re: [CSGO] Issue with cstrike's CS_WeaponIDToLoadoutSlot
Reply With Quote #3

Code:
public Action OnWeaponCanUse(int client, int weapon)
{
	int def = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
	CSWeaponID csweapon = CS_ItemDefIndexToID(def);
    if(!CS_IsValidWeaponID(csweapon)) return Plugin_Continue;

    int slot = CS_WeaponIDToLoadoutSlot(csweapon);
    PrintToChatAll("slot val: %d", slot);
    char wp[32];
    CS_WeaponIDToAlias(csweapon, wp, sizeof(wp));
    PrintToChatAll("%s", wp);

    return Plugin_Continue;
}
In the code above, I check if CS_IsValidWeaponID is true. Given the check and the fact, that CS_WeaponIDToAlias always returns proper weapon name, while CS_WeaponIDToLoadoutSlot remains always 0, I asssume it's about not implementing it correctly or the function not being available yet.

Speaking of the docs, "Returns the loadout slot based on the CSWeaponID. (CS:GO only)" - I pass correct CSWeaponID and should get loadout slot, but I don't.

It'd be nice if someone more advanced could point out my mistake or refactor the code properly.

Last edited by Hacker13dev; 06-14-2023 at 15:16.
Hacker13dev is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:51.


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