SA-MP Forums Archive
Player not receiving prompt - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player not receiving prompt (/showthread.php?tid=660581)



Player not receiving prompt - Maheegan - 07.11.2018

When a player killed by another player is killed by another normal player they should get a prompt to call 112 for the police but it's not working. Could someone take a look at this piece of code and give me some suggestions on what could be the problem ?

Code:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
    {
        pInfo[killerid][pKills]++;
        if(!(IsACop(killerid) || IsAMember(killerid) || pInfo[playerid][pJailed] > 0 || pInfo[playerid][pAJailed] > 0 || Iter_Contains(Paintp, playerid) || pInfo[killerid][pMember] == 8 || vwp[playerid] == pInfo[playerid][pMember] || pInfo[playerid][pDuel] < INVALID_PLAYER_ID || (Event_Pos[0] == 0.0 && IsPlayerInRangeOfPoint(playerid, 140.0, Event_Pos[0], Event_Pos[1], Event_Pos[2]))))
        {
            pInfo[playerid][aVar][64] = killerid, pInfo[playerid][aSpam][7] = gtm+60;
            format(stmsg[playerid], 110, "Ai fost omorat de %s, ai 60 de secunde la dispozitie sa-l reclami folosind /call 112.", GetName(killerid));
            SendClientMessage(playerid, 0x60BF61FF, stmsg[playerid]);
        }
        return 1;
}



Re: Player not receiving prompt - cSharp - 07.11.2018

Have you heard about something called "readable code"? Your code really isn't readable. It's like reading Python.


if(!(IsACop(killerid) || IsAMember(killerid) || pInfo[playerid][pJailed] > 0 || pInfo[playerid][pAJailed] > 0 || Iter_Contains(Paintp, playerid) || pInfo[killerid][pMember] == 8 || vwp[playerid] == pInfo[playerid][pMember] || pInfo[playerid][pDuel] < INVALID_PLAYER_ID || (Event_Pos[0] == 0.0 && IsPlayerInRangeOfPoint(playerid, 140.0, Event_Pos[0], Event_Pos[1], Event_Pos[2]))))

That query itself is just, you can't read that out in your mind and understand "OK, so if this query where killerid isnt a cop, or a member, or in jail, or in admin jail, or in paintball, OR a member again, OR is in another world, OR is in a duel; is true, AND the query of where the event position is 0 and playerid is in range of that event, do this".

You do the math yourself, you resolve this issue yourself now that you know the proper way to write several if statement.


Re: Player not receiving prompt - KinderClans - 07.11.2018

Quote:
Originally Posted by Maheegan
View Post
Code:
        if(!(IsACop(killerid) || IsAMember(killerid) || pInfo[playerid][pJailed] > 0 || pInfo[playerid][pAJailed] > 0 || Iter_Contains(Paintp, playerid) || pInfo[killerid][pMember] == 8 || vwp[playerid] == pInfo[playerid][pMember] || pInfo[playerid][pDuel] < INVALID_PLAYER_ID || (Event_Pos[0] == 0.0 && IsPlayerInRangeOfPoint(playerid, 140.0, Event_Pos[0], Event_Pos[1], Event_Pos[2]))))
Never seen so many checks even in Airport Security TV show.


Re: Player not receiving prompt - Ermanhaut - 07.11.2018

First of all:
Did you meant to do this?
Code:
if(!(IsACop(killerid) || IsAMember(killerid) || pInfo[playerid][pJailed] > 0 || pInfo[playerid][pAJailed] > 0 || Iter_Contains(Paintp, playerid) || pInfo[killerid][pMember] == 8 || vwp[playerid] == pInfo[playerid][pMember] || pInfo[playerid][pDuel] < INVALID_PLAYER_ID || (Event_Pos[0] == 0.0 && IsPlayerInRangeOfPoint(playerid, 140.0, Event_Pos[0], Event_Pos[1], Event_Pos[2]))))
The function will be executed if any of this checks returns false.

If you did, then try to debug your code on your own, let me give you and exemple:
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
    {
            // pInfo[killerid][pKills]++;
            if(!IsACop(killerid)) return print("1");
            else if(!IsAMember(killerid)) return print("2");
            else if(!pInfo[playerid][pJailed] > 0) return print("3");
            else if(!pInfo[playerid][pAJailed] > 0) return print("4");
            else if(!Iter_Contains(Paintp, playerid)) return print("5");
            else if(!pInfo[killerid][pMember] == 8) return print("6");
            else if(!vwp[playerid] == pInfo[playerid][pMember]) return print("7");
            else if(!pInfo[playerid][pDuel] < INVALID_PLAYER_ID) return print("8");
            else if(!(Event_Pos[0] == 0.0 && IsPlayerInRangeOfPoint(playerid, 140.0, Event_Pos[0], Event_Pos[1], Event_Pos[2]))) return print("9");
            else return print("10");
            // {  Forget about the function for one sec
            //      pInfo[playerid][aVar][64] = killerid, pInfo[playerid][aSpam][7] = gtm+60;
            //      format(stmsg[playerid], 110, "Ai fost omorat de %s, ai 60 de secunde la dispozitie sa-l reclami folosind /call 112.", GetName(killerid));
            //      SendClientMessage(playerid, 0x60BF61FF, stmsg[playerid]);
            // }
            return 1;
}
Try to compile it and see wich number is printed in the console, then resolve your bugs.
If it doesn't compile, read the code and figure out the error yourself because all i did was try to make your code a little bit better.