[Include] OnPlayerKnifePlayer - OPKP.inc
#1

OnPlayerKnifePlayer

Basically, as the title suggests this detects basic knifing between two players. It has one call-back which can be found below.

OnPlayerKnifePlayer
pawn Код:
forward OnPlayerKnifePlayer(playerid, targetid);
playerid - The player knifing the other player.
i - The player being knifed.

pawn Код:
StopStab(playerid, targetid);
Stops a player from stabbing the targetID given.

Basically this gets called when a player knifes another player. I have not tested if it gets called if the other player is desynced, - how-ever it should work, - note that it won't fix desync problems.

There should be no false detections as there are numerous checks such as which weapon they have, - their animation, - how close they are, etc, how-ever if you do find any false detections please share.

I've also added the option of OnPlayerKnifePlayer being sent multiple times. Basically, - you can use
#define MULTIPLE_KNIFE_SEND for it to be called more than once(depends on how long it takes to knife/if any of the player's are lagging, or not). - Of-course don't define anything, and it will only be called once. This should work 100% with NPC's.

This script is based on WhiteTiger's script which can be found here,
https://sampforum.blast.hk/showthread.php?tid=199636

Downloads:
- Download(- Shows the .inc file in browser) - Click here.

Example code:
pawn Код:
#include a_samp
#include opkp

public OnPlayerKnifePlayer(playerid, targetid)
{
     SendClientMessage(targetid, -1, "You have been knifed.");
     return 1;
}
NEW UPDATE: Now you can simply stop a player from stabbing someone by returning 0 in OnPlayerKnifePlayer!

Example:
pawn Код:
public OnPlayerKnifePlayer(playerid, targetid)
{
    if(GetPlayerTeam(playerid) == GetPlayerTeam(targetid))
    {
          return 0;
    }
    return 1;
}
Make sure 1 is returned when you want the stab to occur.
Reply
#2

That's cool that people are still looking at some stuff I made a while ago (pre-0.3d), however, I think now you can make this have much better detection by just using OnPlayerGiveDamage, something like:

pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    if(amount > 100 && weaponid == 4) { }
}
Reply
#3

Quote:
Originally Posted by Whitetiger
Посмотреть сообщение
That's cool that people are still looking at some stuff I made a while ago, however, I think now you can make this have much better detection by just using OnPlayerGiveDamage, something like:

pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    if(amount > 100 && weaponid == 4) { }
}
Well that would decrease accuracy especially considering hackers, how-ever that is possible and maybe I'll make a version using that method
Reply
#4

aww stupidy moment lolz
Reply
#5

Quote:
Originally Posted by DaTa[X]
Посмотреть сообщение
OnPlayerGiveDamage is not called when using knife !!!!
are u for real?
Reply
#6

How does that decrease accuracy? As if yours can't be spoofed, (it can.) if anything it improves accuracy. You could still add distance, and animation checks if you wanted, but both are redundant.
Reply
#7

Maybe you can improve this. If you knife someone from behind the damage says 0 (zero) and the killed guy gets desynced. I build a fix for that. Just call a respawn on the same position for the player.
Its good if you use:

//Call this after the zero damage event with the knife. I got some problems with calling this directly so i used a small timerdelay and put that in a "public".
Код:
new Float:X,Float:Y,Float:Z,Float:Angle;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerFacingAngle(playerid,Angle);
SetSpawnInfo(playerid, 0, GetPlayerSkin(playerid), X,Y,Z, Angle, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
The Player will be spawned without weapons, maybe you store them every time he get a new gun and give them back some time after the Spawn.

Maybe you can upgrade that to:
OnPlayerKnifePlayer(playerid,targetid,Float:damage ,bool:instantkill) // Instantkill if it cause a zero damage and begins the desync.
OnPlayerKnifeRespawn(playerid) // called on spawn after the player got fixed against desync.
Reply
#8

Quote:
Originally Posted by Whitetiger
Посмотреть сообщение
How does that decrease accuracy? As if yours can't be spoofed, (it can.) if anything it improves accuracy. You could still add distance, and animation checks if you wanted, but both are redundant.
That is true, - how-ever I am assuming that the damage value won't be over 100 if the other player is desynced, how-ever I'd have to confirm this.

Quote:
Originally Posted by LadyNyuuu
Посмотреть сообщение
Maybe you can improve this. If you knife someone from behind the damage says 0 (zero) and the killed guy gets desynced. I build a fix for that. Just call a respawn on the same position for the player.
Its good if you use:

//Call this after the zero damage event with the knife. I got some problems with calling this directly so i used a small timerdelay and put that in a "public".
Код:
new Float:X,Float:Y,Float:Z,Float:Angle;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerFacingAngle(playerid,Angle);
SetSpawnInfo(playerid, 0, GetPlayerSkin(playerid), X,Y,Z, Angle, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
The Player will be spawned without weapons, maybe you store them every time he get a new gun and give them back some time after the Spawn.

Maybe you can upgrade that to:
OnPlayerKnifePlayer(playerid,targetid,Float:damage ,bool:instantkill) // Instantkill if it cause a zero damage and begins the desync.
OnPlayerKnifeRespawn(playerid) // called on spawn after the player got fixed against desync.
Will be taken into consideration.
Reply
#9

great, good work. It'll be much better if you update it with the given suggestions
Reply
#10

lol nice work . Just a few easy suggestions:

- "i" isn't a suitable parameter name since it's mostly used for loops and whatnot. Something like "targetid" would be much better.

- "GetPlayerTargetPlayerEx" is not needed since GetPlayerTargetPlayer returns "INVALID_PLAYER_ID" when the player isn't aiming at anybody.

- "CallLocalFunction" should be used instead of "CallRemoteFunction", so the callback is not called in other loaded scripts.

- "Called" should be static, as it's only used by that script. On another note, some scripts also have a variable named "Called". You should change it to "g_iCalled" (my opinion though).
Reply
#11

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
lol nice work . Just a few easy suggestions:

- "i" isn't a suitable parameter name since it's mostly used for loops and whatnot. Something like "targetid" would be much better.

- "GetPlayerTargetPlayerEx" is not needed since GetPlayerTargetPlayer returns "INVALID_PLAYER_ID" when the player isn't aiming at anybody.

- "CallLocalFunction" should be used instead of "CallRemoteFunction", so the callback is not called in other loaded scripts.

- "Called" should be static, as it's only used by that script. On another note, some scripts also have a variable named "Called". You should change it to "g_iCalled" (my opinion though).
Updated.
Reply
#12

"Called" variable could actually be a static boolean because it just handles 2 values and also, I haven't seen any hooking done over your OnPlayerUpdate callback.
Reply
#13

Quote:
Originally Posted by Lordzy
Посмотреть сообщение
"Called" variable could actually be a static boolean because it just handles 2 values and also, I haven't seen any hooking done over your OnPlayerUpdate callback.
I usually do use booleans but I didn't really think about using it(or I forgot about it).

EDIT: I guess I wasn't really thinking right when I made this. I've updated it. Thanks for the feedback.
Reply
#14

Fixed \ Updated the download link. It should work properly now.
Reply
#15

Quote:
Originally Posted by Whitetiger
Посмотреть сообщение
pawn Код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
    if(amount > 100 && weaponid == 4) { }
}
I don't get how this include is any different than that ^?

And please don't tell me accuracy because i've looked over your code and there is exactly nothing at all that makes it better than how Whitetiger wrote it.
Reply
#16

Cool!
Reply
#17

Lol, theres alot of things you can do to improve this, did you even check if the player actually died?
Reply
#18

This isn't a syncing include(atleast as of now). It only checks for knifing enviorment / situation. This should be about 90 % accurate. How-ever, as long as no hacks / spoofs are used it should never be called outside of a rough knifing situation.

More checks can be added, how-ever this should work fine enough without modification.
Reply
#19

Quote:
Originally Posted by Turn
Посмотреть сообщение
I don't get how this include is any different than that ^?

And please don't tell me accuracy because i've looked over your code and there is exactly nothing at all that makes it better than how Whitetiger wrote it.
As far as I know it won't even detect it if the player gets desynced. This can also be easily spoofed / exploited more than the current code.
Reply
#20

It will detect if the player is desynced because it's using OnPlayerGiveDamage not TakeDamage.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)