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

PlayerRunCmdHook crash


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ElectricStalin
Member
Join Date: Apr 2017
Old 10-10-2017 , 14:48   PlayerRunCmdHook crash
Reply With Quote #1

Hi, guys.
Yesterday i had 2 crashes. Hier is one of them: https://crash.limetech.org/noomubm4ssxm
As I understand, problem was in hook OnPlayerRunCmd.
In plugin i have:
Code:
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{	
.....
.....
.....
	if(weapon==GetPlayerWeaponSlot(client, 0))
		scrollWeapon(client);	
.....
.....
.....						
	return Plugin_Continue;
}
This code execute scrollWeapon() on pressing "1".
Why can this crash happen? I am hope for your help.
ElectricStalin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-10-2017 , 15:14   Re: PlayerRunCmdHook crash
Reply With Quote #2

No one can't say, why it crash, if you have just small script to show us...
__________________
Do not Private Message @me
Bacardi is offline
ElectricStalin
Member
Join Date: Apr 2017
Old 10-10-2017 , 15:25   Re: PlayerRunCmdHook crash
Reply With Quote #3

I can show any part of the plugin if necessary.
Code:
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
	if (buttons & IN_USE)
    {
        buttons &= ~IN_USE;
    }
	if ((weapon==GetPlayerWeaponSlot(client, 1)) || (weapon==GetPlayerWeaponSlot(client, 0)))
	{
		if(weapon==GetPlayerWeaponSlot(client, 0))
		{
			scrollWeapon(client);			
		}
		weaponSwapFlag[client] = true;
		printBackpackHud(client); 
	}				
	return Plugin_Continue;
}

void scrollBackpack(int client)
{
	char buffer[40];
	float pos[3];
	pos[0]=backpackPositions[0];
	pos[1]=backpackPositions[1];
	pos[2]=backpackPositions[2];
	int nextWeap=weaponInHand[client]+1;	
	if((nextWeap==backpackSize) || (EntRefToEntIndex(clientsWeapon[client][nextWeap])==0) || (!isWeapon(EntRefToEntIndex(clientsWeapon[client][nextWeap]))))
		nextWeap=1;	
	if(clientsWeapon[client][weaponInHand[client]]!=0)
	{
		dropFlag[client]=true;
		SetEntPropEnt(EntRefToEntIndex(clientsWeapon[client][weaponInHand[client]]), Prop_Send, "m_hOwnerEntity", client);
		CS_DropWeapon(client, EntRefToEntIndex(clientsWeapon[client][weaponInHand[client]]), false, true);
		TeleportEntity(EntRefToEntIndex(clientsWeapon[client][weaponInHand[client]]), pos, NULL_VECTOR, NULL_VECTOR);
		dropFlag[client]=false;
		SetEntPropEnt(EntRefToEntIndex(clientsWeapon[client][nextWeap]), Prop_Send, "m_hOwnerEntity", client);
		EquipPlayerWeapon(client, EntRefToEntIndex(clientsWeapon[client][nextWeap]));
		GetEntityClassname(EntRefToEntIndex(clientsWeapon[client][nextWeap]),buffer,sizeof(buffer));
		TrimString(buffer);
		FakeClientCommand(client, "use %s",buffer);		
		new ammotype = GetEntProp(EntRefToEntIndex(clientsWeapon[client][nextWeap]), Prop_Send, "m_iPrimaryAmmoType"); 
		GivePlayerAmmo(client, weaponReserve(buffer), ammotype); 
		SetEntProp(client, Prop_Send, "m_iAmmo", weaponReserve(buffer), _, ammotype);
	}	
	weaponInHand[client]=nextWeap;	
}
Here are 2 functions. It works good, i cant produce this crash. But when people play on the server, once in a 10-15 games server can suddenly crash.
ElectricStalin is offline
cigzag
AlliedModders Donor
Join Date: Nov 2014
Location: NZ
Old 10-10-2017 , 17:28   Re: PlayerRunCmdHook crash
Reply With Quote #4

No errors in the server logs when it crashes?
cigzag is offline
ElectricStalin
Member
Join Date: Apr 2017
Old 10-10-2017 , 19:42   Re: PlayerRunCmdHook crash
Reply With Quote #5

Yes. Only crash info in accelerator file, I wrote the link in first message.
ElectricStalin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-10-2017 , 23:26   Re: PlayerRunCmdHook crash
Reply With Quote #6

I would say... that is nasty looking script.
If you have knowledge how Action:OnPlayerRunCmd works
__________________
Do not Private Message @me

Last edited by Bacardi; 10-10-2017 at 23:27.
Bacardi is offline
ElectricStalin
Member
Join Date: Apr 2017
Old 10-11-2017 , 05:20   Re: PlayerRunCmdHook crash
Reply With Quote #7

Quote:
Originally Posted by Bacardi View Post
I would say... that is nasty looking script.
If you have knowledge how Action:OnPlayerRunCmd works
Yes, perhaps. Do you mean, that problem is in my function? If so, can you tell me about the weak points?

Quote:
If you have knowledge how Action:OnPlayerRunCmd works
I know, that it calls every tick. I was thinking of moving the function call, but I did not find another way to track pressing "1" if client have a primary weapon in hands.
ElectricStalin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-11-2017 , 10:07   Re: PlayerRunCmdHook crash
Reply With Quote #8

What you try achieved with this ?
Player can carry more than one primary weapon ?
__________________
Do not Private Message @me
Bacardi is offline
ElectricStalin
Member
Join Date: Apr 2017
Old 10-11-2017 , 10:49   Re: PlayerRunCmdHook crash
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
What you try achieved with this ?
Player can carry more than one primary weapon ?
Yes) Player can carry many weapons. In clientsWeapon[][] i store indexes. And player can scroll weapons by pressing "1".
ElectricStalin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-12-2017 , 06:11   Re: PlayerRunCmdHook crash
Reply With Quote #10

You could try first, make use button work as toggle.
(Not sure what you mean about key button "1", server not regognice keyboard buttons.)

PHP Code:
public Action OnPlayerRunCmd(int clientint &buttonsint &impulse,
                            
float vel[3], float angles[3], int &weapon,
                            
int &subtypeint &cmdnumint &tickcountint &seedint mouse[2])
{
    static 
int sbuttons[MAXPLAYERS+1];


    
// pressed
    
if(buttons IN_USE && !(sbuttons[client] & IN_USE))
    {
        
sbuttons[client] = buttons;
        return 
Plugin_Continue;
    }


    
// released
    
if(sbuttons[client] & IN_USE && !(buttons IN_USE))
    {
        
sbuttons[client] = buttons;

        
// Do code here
        
int ent GetEntPropEnt(clientProp_Send"m_hActiveWeapon");

        if(
ent == -1) return Plugin_Continue;

        
char buffer[30];
        
GetEntityClassname(entbuffersizeof(buffer));
        
PrintToServer(buffer);

        return 
Plugin_Continue;
    }


    
// bug ?
    
sbuttons[client] = buttons;

    return 
Plugin_Continue;


... I started to be curious so I try create that bagpack system
__________________
Do not Private Message @me

Last edited by Bacardi; 10-12-2017 at 06:14.
Bacardi 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 16:26.


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