Weird OnPlayerGiveDamage bug -
Adamoneoone - 29.06.2018
So I'm trying to setup a system, which involves three people at least.
Let's say there's Player A, B and C
Player A and B are normal players
Player C has started the police officer job.
I've created two vehicles which allow the player to start the police officer job.
When player B for instance, shoots at player A within the range specified (here 20m) he gets 1 wanted level.
This is my code:
PHP код:
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid, bodypart)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(policeofficer[i]==1)
{
if(GetDistanceBetweenPlayers(playerid,i) <= 20) // If the player is near from the police
{
SetPlayerWantedLevel(playerid, 1);
SendClientMessage(playerid, -1, "you have shot someone near a police officer");
}
}
}
return 1;
}
Here is my GetDistanceBetweenPlayers:
PHP код:
forward Float:GetDistanceBetweenPlayers(playerid,targetplayerid);
public Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
return -1.00;
}
GetPlayerPos(playerid,x1,y1,z1);
GetPlayerPos(targetplayerid,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
The bug is whenever a police officer shoots / punches a player with wanted level, the two cars created for the police officer spawn again. So for instace if you punch a player with wanted level 2, there will be 6 exact same cars spawned above eachother (2 already spawned, and 4 more due to the 2 punches)
Any idea
??
Re: Weird OnPlayerGiveDamage bug -
Adamoneoone - 29.06.2018
SORRY for double posting, I fixed the problem.
Re: Weird OnPlayerGiveDamage bug -
CodeStyle175 - 29.06.2018
dont use larp distance function
and there isnt need to create public functions only when its called by timer or threaded query then it should be used
PHP код:
Float:gDisBetPlayers(p1,p2){
new Float:x,Float:z,Float:y;
GetPlayerPos(p1,x,y,z);
return GetPlayerDistanceFromPoint(p2,x,y,z);
}