Problem with sending hit contract message on death
#1

Hey,

I'm currently scripting a Hit Contract system, and its going quite well except for one thing. When the player is killed by a bounty hunter, they receive the money and a message is sent, but it doesn't work.

Here is the code for it,

pawn Код:
if( hasHit[playerid] == true && gTeam[ killerid ] == TEAM_CIV_BOUNTY )
    {
        new
            str[128];

        format(str, sizeof(str), "[HIT] %s[%d] has been killed by Bounty Hunter %s[%d] for $%d", GetName(playerid), playerid, GetName(killerid), killerid, hitAmount[playerid]);
        SendClientMessageToAll(SERVER_MESSAGE, str);

        GivePlayerMoney(killerid, hitAmount[playerid]);
        hasHit[playerid] = false;
        hitAmount[playerid] = 0;
        SetPlayerScore(killerid, GetPlayerScore(killerid) + 2);
    }
How am I able to fix this?

Thanks,

FunnyBear
Reply
#2

Under what function did you place this code?
Reply
#3

Quote:
Originally Posted by Death1300
Посмотреть сообщение
Under what function did you place this code?
I placed the function under, OnPlayerDeath

And here is the bounty command,

pawn Код:
CMD:bounty(playerid, params[])
{

    if( gTeam [ playerid ] == TEAM_CIV_BOUNTY )
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} Bounty Hunters cannot place hits on other people");

    new
        id,
        amount;

    if( sscanf(params, "ui", id, amount))
        return SendUsageError( playerid, "/bounty [Name/ID] [Amount]" );

    if ( id == INVALID_PLAYER_ID )
        return InvalidPlayerError( playerid );

    if( id == playerid)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} You cannot place a Bounty Hit on yourself");

    if( hasHit[id] == true)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} This player already has a hit on them");

    if( amount <  1500)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} Minimum hit amount is $1,500");

    if( amount >  1000000)
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} Maximum hit amount is $1,000,000");

    if( GetPlayerMoney( playerid ) < amount )
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR:{FFFFFF} You do not have enough money to pay for the bounty");

    hasHit[id] = true;
    hitAmount[id] = amount;

    new
        str[128],
        str1[128];

    format(str, sizeof(str), "[HIT] A $%d hit has been placed on you. Beware!", amount);
    SendClientMessage(id, RED, str);
    GameTextForPlayer(id, "~r~HIT BOUNTY ~y~PLACED~r~ON YOU", 6000, 3);

    format(str1, sizeof(str1), "[HIT] You have placed a $%d hit on %s[%d]", amount, GetName(id), id);
    SendClientMessage(playerid, RED, str1);
    GivePlayerMoney(playerid, -amount);
    return 1;
}
Reply
#4

i don't see anything wrong w your code, can you show me full OnPlayerDeath function ?
Reply
#5

What is wrong? You said message is sent and money is given. I see no problem in the code.
Reply
#6

The bounty command works fine when I place a hit on someone, but when I actually go to kill them, the function is not called.
Reply
#7

Did you assign a value to the variable gTeam properly?
Reply
#8

Try putting the code at the begin of OnPlayerDeath

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( hasHit[playerid] == true && gTeam[ killerid ] == TEAM_CIV_BOUNTY )
    {
        new
            str[128];

        format(str, sizeof(str), "[HIT] %s[%d] has been killed by Bounty Hunter %s[%d] for $%d", GetName(playerid), playerid, GetName(killerid), killerid, hitAmount[playerid]);
        SendClientMessageToAll(SERVER_MESSAGE, str);

        GivePlayerMoney(killerid, hitAmount[playerid]);
        hasHit[playerid] = false;
        hitAmount[playerid] = 0;
        SetPlayerScore(killerid, GetPlayerScore(killerid) + 2);
    }
    // The rest of your OnPlayerDeath code
    return 1;
}
Reply
#9

Quote:
Originally Posted by Facerafter
Посмотреть сообщение
Try putting the code at the begin of OnPlayerDeath

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( hasHit[playerid] == true && gTeam[ killerid ] == TEAM_CIV_BOUNTY )
    {
        new
            str[128];

        format(str, sizeof(str), "[HIT] %s[%d] has been killed by Bounty Hunter %s[%d] for $%d", GetName(playerid), playerid, GetName(killerid), killerid, hitAmount[playerid]);
        SendClientMessageToAll(SERVER_MESSAGE, str);

        GivePlayerMoney(killerid, hitAmount[playerid]);
        hasHit[playerid] = false;
        hitAmount[playerid] = 0;
        SetPlayerScore(killerid, GetPlayerScore(killerid) + 2);
    }
    // The rest of your OnPlayerDeath code
    return 1;
}
Yes, because there might be a return in the rest of the code, so it'll skip these.
Reply
#10

Yes it works, thanks guys
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)