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

Command registration not always working.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RSTFS
Junior Member
Join Date: Jan 2016
Old 01-12-2016 , 19:18   Command registration not always working.
Reply With Quote #1

I accidentally posted this in the wrong section, and after 3 days it still hasn't been moved/deleted so I'm posting it again.
This code works, it just gives a glock to a player:
Code:
public void OnPluginStart(){
	RegConsoleCmd("sm_glock", GiveGlock);
}

public Action GiveGlock(int client, int args){
	if(IsPlayerAlive(client)){
		GivePlayerItem(client, "weapon_glock", 0);
	}
	return Plugin_Handled;
}
However, when I do anything related to removing weapons that the client already has, the command does not register. For example, this code does not work:
Code:
public void OnPluginStart(){
	RegConsoleCmd("sm_glock", GiveGlock);
}

public Action GiveGlock(int client, int args){
	if(IsPlayerAlive(client)){
		RemovePlayerItem(client, GetPlayerWeaponSlot(client, 0));         //This is the only line changed.
		GivePlayerItem(client, "weapon_glock", 0);
	}
	return Plugin_Handled;
}
0 warnings or errors during compilation. Same issue when I add anything about deleting the weapon edict.
RSTFS is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-12-2016 , 19:20   Re: Command registration not always working.
Reply With Quote #2

The registration is working. Something else is happening. Check the Sourcemod error logs on the server.
__________________

Last edited by ddhoward; 01-12-2016 at 19:20.
ddhoward is offline
RSTFS
Junior Member
Join Date: Jan 2016
Old 01-12-2016 , 19:50   Re: Command registration not always working.
Reply With Quote #3

Ah, trying to remove something from an already empty item slot breaks things, I should have caught that.
RSTFS is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-12-2016 , 20:00   Re: Command registration not always working.
Reply With Quote #4

You should pass the entity returned by GetPlayerWeaponslot() through IsValidEntity() before you run it through RemovePlayerItem().

Something like this:

PHP Code:
if(IsPlayerAlive(client)){
        if(
IsValidEntity(GetPlayerWeaponSlot(client0)) {
            
RemovePlayerItem(clientGetPlayerWeaponSlot(client0));
        }
        
GivePlayerItem(client"weapon_glock"0);
    } 
__________________

Last edited by ddhoward; 01-12-2016 at 20:01.
ddhoward is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-13-2016 , 02:37   Re: Command registration not always working.
Reply With Quote #5

Quote:
Originally Posted by ddhoward View Post
You should pass the entity returned by GetPlayerWeaponslot() through IsValidEntity() before you run it through RemovePlayerItem().

Something like this:

PHP Code:
if(IsPlayerAlive(client)){
        if(
IsValidEntity(GetPlayerWeaponSlot(client0)) {
            
RemovePlayerItem(clientGetPlayerWeaponSlot(client0));
        }
        
GivePlayerItem(client"weapon_glock"0);
    } 
No, just check for -1 being returned (as the doc says), if you get an ent index back it is going to be valid.
__________________
asherkin 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 00:29.


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