SA-MP Forums

Go Back   SA-MP Forums > SA-MP > Bug Reports

Reply
 
Thread Tools Display Modes
Old 12/10/2016, 09:30 PM   #1
Runn3R
Huge Clucker
 
Runn3R's Avatar
 
Join Date: Dec 2013
Location: Croatia, Split
Posts: 378
Reputation: 35
Default OnPlayerWeaponShot bug

So i was working on the weapon ammo hack anticheat when i suddenly discover this shit..







smetaka = Serverside Ammo

cmetaka = Clientside Ammo

mind the +1 bcs i decrease it after the message.
Runn3R is offline   Reply With Quote
Old 12/10/2016, 09:45 PM   #2
SickAttack
Godfather
 
Join Date: Dec 2013
Posts: 5,254
Reputation: 751
Default Re: OnPlayerWeaponShot bug

Looks like your dream is crushed.





































Nice find. An alternative would be to detect when a player presses LEFT CLICK.
SickAttack is offline   Reply With Quote
Old 13/10/2016, 08:52 AM   #3
Runn3R
Huge Clucker
 
Runn3R's Avatar
 
Join Date: Dec 2013
Location: Croatia, Split
Posts: 378
Reputation: 35
Default Re: OnPlayerWeaponShot bug

Yeah, but it wouldn't be effective as OnPlayerWeaponShot.
Runn3R is offline   Reply With Quote
Old 15/10/2016, 12:55 PM   #4
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,033
Reputation: 517
Default Re: OnPlayerWeaponShot bug

In terms of the anticheat, if the client ammo is lower than expected, update the serverside ammo to that amount and you should have no issues.

But nice find.
__________________

SERVER.LVCNR.NET:7777
WWW.LVCNR.NET
Threshold is offline   Reply With Quote
Old 06/11/2016, 10:33 PM   #5
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,354
Reputation: 681
Default Re: OnPlayerWeaponShot bug

This has been bugging me too. Now, to clarify, I'm not the best in mathematics, but I've crafted this function to detect when a player is looking backward with their camera:

PHP Code:
stock IsAimingBehind(playerid) {

    static
        
Float:cPosXFloat:cPosYFloat:cPosZ,
        
Float:pPosXFloat:pPosYFloat:pPosZ,
        
Float:cFacAngFloat:pFacAng;

    
GetPlayerPos(playeridpPosXpPosYpPosZ);
    
GetPlayerFacingAngle(playeridpFacAng);
    
GetPlayerCameraPos(playeridcPosXcPosYcPosZ);

    
cFacAng 90 + (atan2((cPosY pPosY), (cPosX pPosX)));

    static
        
Float:cOppFacAng = ((pFacAng 180) ? (pFacAng 180) : (pFacAng 180));

    return ((
cFacAng 90) < cOppFacAng < (cFacAng 90)) || ((cFacAng 90) < cOppFacAng < (cFacAng 90));

The name of the function is a bit ambiguous. It doesn't check if the player is aiming, but that's something that you can easily change.

This function does the following:
  • Calculates the facing angle of the player's camera (Not the player's character)
  • Inverses the calculated vector relative to the facing angle of the player (the character)
  • Checks if that falls within the 180° behind the player

You can use this in a looping timer to keep checking it when the player is holding KEY_HANDBRAKE / KEY_AIM (if KEY_AIM is defined in your script).

This function still needs some tweaking and improvement, but it works and can be used for now. A current improvement that I can think of is the use of GetPlayerCameraFrontVector (?). Also while testing this, I noticed that the aim angle is larger than 90° on each side, so this can be improved too.

(?): At least I think GetPlayerCameraFrontVector replaces the calculations that I've done and if so, probably does them more efficiently.

I would appreciate if someone with more insight into this stuff could and wants to help me improve this function (and also explain the process, as I'm interested in learning too)!

Last edited by AndySedeyn; 06/11/2016 at 11:23 PM.
AndySedeyn is offline   Reply With Quote
Old 06/11/2016, 11:43 PM   #6
SickAttack
Godfather
 
Join Date: Dec 2013
Posts: 5,254
Reputation: 751
Default Re: OnPlayerWeaponShot bug

Quote:
Originally Posted by AndySedeyn View Post
This has been bugging me too. Now, to clarify, I'm not the best in mathematics, but I've crafted this function to detect when a player is looking backward with their camera:

PHP Code:
stock IsAimingBehind(playerid) {

    static
        
Float:cPosXFloat:cPosYFloat:cPosZ,
        
Float:pPosXFloat:pPosYFloat:pPosZ,
        
Float:cFacAngFloat:pFacAng;

    
GetPlayerPos(playeridpPosXpPosYpPosZ);
    
GetPlayerFacingAngle(playeridpFacAng);
    
GetPlayerCameraPos(playeridcPosXcPosYcPosZ);

    
cFacAng 90 + (atan2((cPosY pPosY), (cPosX pPosX)));

    static
        
Float:cOppFacAng = ((pFacAng 180) ? (pFacAng 180) : (pFacAng 180));

    return ((
cFacAng 90) < cOppFacAng < (cFacAng 90)) || ((cFacAng 90) < cOppFacAng < (cFacAng 90));

The name of the function is a bit ambiguous. It doesn't check if the player is aiming, but that's something that you can easily change.

This function does the following:
  • Calculates the facing angle of the player's camera (Not the player's character)
  • Inverses the calculated vector relative to the facing angle of the player (the character)
  • Checks if that falls within the 180° behind the player

You can use this in a looping timer to keep checking it when the player is holding KEY_HANDBRAKE / KEY_AIM (if KEY_AIM is defined in your script).

This function still needs some tweaking and improvement, but it works and can be used for now. A current improvement that I can think of is the use of GetPlayerCameraFrontVector (?). Also while testing this, I noticed that the aim angle is larger than 90° on each side, so this can be improved too.

(?): At least I think GetPlayerCameraFrontVector replaces the calculations that I've done and if so, probably does them more efficiently.

I would appreciate if someone with more insight into this stuff could and wants to help me improve this function (and also explain the process, as I'm interested in learning too)!
That's not going to solve all of your problems. If you face a wall (not aiming behind) and shoot with a Tec9 for example, it won't detect it, nor is OnPlayerWeaponShotCalled.
SickAttack is offline   Reply With Quote
Old 07/11/2016, 07:09 PM   #7
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,354
Reputation: 681
Default Re: OnPlayerWeaponShot bug

I guess the wall can be detected with ColAndreas. Set a point to somewhere in front of the player and see if there's an object between it:

Function from AbyssMorgan's 3DTryg:
PHP Code:
Tryg3DProt:: bool:IsBetweenPlayerToPointIsWall(playerid,Float:x,Float:y,Float:z) {

    new 
Float:xA,Float:yA,Float:zA,Float:xC,Float:yC,Float:zC;
    
GetPlayerPos(playerid,xA,yA,zA);
    
CA_RayCastLine(xA,yA,zA,x,y,z,xC,yC,zC);
    if(
xC == 0.0 || yC == 0.0 || zC == 0.0) return false;
    return 
true;

@Crayder, any better ideas? (I linked this post on his VMs)
AndySedeyn is offline   Reply With Quote
Old 07/11/2016, 07:32 PM   #8
SickAttack
Godfather
 
Join Date: Dec 2013
Posts: 5,254
Reputation: 751
Default Re: OnPlayerWeaponShot bug

It's still not going to work like that... They can be close to a wall and still shoot normal.

Detect the animation, one must be applied.
SickAttack is offline   Reply With Quote
Old 07/11/2016, 07:35 PM   #9
AndySedeyn
High-roller
 
AndySedeyn's Avatar
 
Join Date: Feb 2014
Location: Belgium
Posts: 1,354
Reputation: 681
Default Re: OnPlayerWeaponShot bug

Quote:
Originally Posted by SickAttack View Post
It's still not going to work like that... They can be close to a wall and still shoot normal.

Detect the animation, one must be applied.
Obviously. You can still detect when a player presses the fire button and then perform the checks.
AndySedeyn is offline   Reply With Quote
Old 07/11/2016, 07:37 PM   #10
SickAttack
Godfather
 
Join Date: Dec 2013
Posts: 5,254
Reputation: 751
Default Re: OnPlayerWeaponShot bug

Quote:
Originally Posted by AndySedeyn View Post
Obviously. You can still detect when a player presses the fire button and then perform the checks.
They can also hold the button down.
SickAttack is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ajuda] OnPlayerWeaponShot pWesley Português/Portuguese 2 13/05/2016 03:22 AM
OnPlayerWeaponShot PaulDinam Bug Reports 10 09/01/2015 10:54 PM
OnPlayerWeaponShot Bug NicK_ Bug Reports 2 23/02/2014 01:14 AM
Bug OnPlayerWeaponShot DarkZeroX Scripting Help 2 22/02/2014 03:39 PM


All times are GMT. The time now is 02:01 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.