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

GetPlayerWeaponSlot always resolving to -1


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pricetx
Junior Member
Join Date: Jan 2013
Old 06-27-2013 , 13:30   GetPlayerWeaponSlot always resolving to -1
Reply With Quote #1

I have a script for HL2MP which removes weapons from players when they spawn, and additionally removes weapons from the map when it loads.

This worked fine up until some point in May.

For the last hour or so i've been debugging my script and I have found that the line
Code:
owner = GetPlayerWeaponSlot(client, 1);
will always resolve to -1. I have checked that the "client" variable was valid (on my last test, it was "2").

I am running the latest dev build of sourcemod, and the latest version of the HL2MP server.

I'll include a link to the script in it's current state below.

https://gravitygunonly.com/hl2mp_removeweapons_v2.sp

Thanks!

Pricetx

Last edited by Pricetx; 06-27-2013 at 13:30.
Pricetx is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 06-27-2013 , 14:03   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #2

You could use smlib instead.

PHP Code:
if (/* remove weapon ? */) {
    
Client_RemoveWeapon(clientweaponToRemove);

__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 06-27-2013 , 14:33   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #3

I am doing the same thing in my script, however, I did use SMLIB . Instead of making my plugin dependent of something else, I just used the code from the Client_RemoveAllWeapons stock.

This code will remove all the weapons a client has when they spawn:
PHP Code:
new iOffset FindDataMapOffs(iClient"m_hMyWeapons") - 4;

    for (new 
i48i++)
    {
        
iOffset += 4;

        new 
iWeapon GetEntDataEnt2(iClientiOffset);
        
        if (
iWeapon <= 0) continue;

        if (
RemovePlayerItem(iClientiWeapon)) AcceptEntityInput(iWeapon"Kill");
    } 

Last edited by Marcus_Brown001; 06-27-2013 at 14:34.
Marcus_Brown001 is offline
Pricetx
Junior Member
Join Date: Jan 2013
Old 06-27-2013 , 17:51   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #4

Thanks for the solutions so far guys, although I will admit that I have extremely little experience with SourcePawn, so if I were to go with either of your ideas it would probably take me a while to get something functional.

That being said, does anybody actually know why GetPlayerWeaponSlot is always returning -1 on hl2mp despite a valid player and weapon slot ID being provided?

Thanks,

Pricetx
Pricetx is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 06-27-2013 , 18:03   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #5

We just have to assume that its the wrong id or that the function just does not support hl2dm (anymore?) I guess. Maybe loop through a few numbers and print the values to chat to see if the ids changed, otherwise some update probably broke the function.
Doodil is offline
NouveauJoueur
SourceMod Donor
Join Date: May 2009
Old 06-29-2013 , 03:27   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #6

Quote:
Originally Posted by Pricetx View Post
That being said, does anybody actually know why GetPlayerWeaponSlot is always returning -1

GetPlayerWeaponSlot is broken since last update.

If you want your code to work change :

Code:
                CreateTimer(0.3, TimerRemoveWeapons, client);
to

Code:
                CreateTimer(3.0, TimerRemoveWeapons, client);
Anything below 2.0 will fail.
F.ck Riot ... (What has league of legends to do with this ? You tell me !)
__________________
NouveauJoueur is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 06-29-2013 , 05:18   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #7

Any timer below two will fail for what? I have a timer set for 0.5 when a player spawns to remove the weapons and mine has had zero issues.
Marcus_Brown001 is offline
NouveauJoueur
SourceMod Donor
Join Date: May 2009
Old 06-29-2013 , 05:32   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #8

Quote:
Originally Posted by Marcus_Brown001 View Post
Any timer below two will fail for what? I have a timer set for 0.5 when a player spawns to remove the weapons and mine has had zero issues.
Read the post title. Based on your post i'll give you a few hints to help you understand :

GetPlayerWeaponSlot
GetPlayerWeaponSlot != StripWeapons

You might want to read the quote that precede my first answer :

Quote:
That being said, does anybody actually know why GetPlayerWeaponSlot is always returning -1
The title is about GetPlayerWeaponSlot, the question quoted is about GetPlayerWeaponSlot, the answer is about GetPlayerWeaponSlot, I let you guess what will fail if you create a timer below 2 seconds after the player get his weapons. I know it can be confusing and hard to answer, so i'll give you another hint : GetPlayerWeaponSlot.
__________________

Last edited by NouveauJoueur; 06-29-2013 at 05:33.
NouveauJoueur is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 06-29-2013 , 06:20   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #9

I didn't know where you were getting the TimerRemoveWeapon from (only just now opened the mod to look at it). A simpler and less condescending answer would have both sufficed and been more sought after by the way.
Marcus_Brown001 is offline
Pricetx
Junior Member
Join Date: Jan 2013
Old 07-02-2013 , 22:43   Re: GetPlayerWeaponSlot always resolving to -1
Reply With Quote #10

Quote:
Originally Posted by NouveauJoueur View Post
GetPlayerWeaponSlot is broken since last update.

If you want your code to work change :

Code:
                CreateTimer(0.3, TimerRemoveWeapons, client);
to

Code:
                CreateTimer(3.0, TimerRemoveWeapons, client);
Anything below 2.0 will fail.
F.ck Riot ... (What has league of legends to do with this ? You tell me !)
That particular section of code was working before, but I gave it a shot anyway and changed it to 3.0. Unfortunately, it still returns -1, even when set to 3.0.

On a different note; i'm not very familiar with how SourceMod actually works. With GetPlayerWeaponSlot being broken with HL2DM at the moment, is that something that only Valve can fix, or is it something with the GetPlayerWeaponSlot function within SourceMod itself?

Last edited by Pricetx; 07-02-2013 at 22:46.
Pricetx is offline
Reply


Thread Tools
Display Modes

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 16:39.


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