My anti team kill works when I attack my enemy
#1

What the hell. It only works when I attack my enemy.
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(hitid == gTeam[playerid] || hitid == GetPlayerTeam(playerid))
    {
        GameTextForPlayer(playerid, "~r~Do not teamkill!", 1000, 5);
        return 0;
    }
    return 1;
}
There is nothing wrong, right? My gTeam's and my SetPlayerTeam's aren't bugged at all. I am just surprised when I sometimes attack my enemy then boom! "DO NOT TEAM KILL!"
Reply
#2

Hope this helps
Код:
public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
    if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
    { // Then
        if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
        { // Then
            SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).

            SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".

            GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
        }

        else // Another team killed the player
        {
            SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".

            GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
        }
    }

    SendDeathMessage(  killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).

    return 1; // This means the callback is executed succesfully.
}
REP ME IF I HELPED
Reply
#3

You are definitely not comparing betw3en YOUR team and the guy who is being shot what you are doing is comparing between your team and the shot player id not his gTeam.

sorry for spalling mistkaes on phone r8 now.
Reply
#4

Quote:
Originally Posted by rockhopper
Посмотреть сообщение
Hope this helps
Код:
public OnPlayerDeath( playerid, killerid, reason ) // This is called when a player deaths.
{
    if ( killerid != INVALID_PLAYER_ID ) // If the killerid are NOT an invalid player
    { // Then
        if ( GetPlayerTeam( killerid ) == GetPlayerTeam( playerid ) ) // If killerid's team == playerid's team ( who has been killed )
        { // Then
            SetPlayerHealth( killerid, -1 ); // Kills the killer ( Setting the health to -1 ).

            SendClientMessage( killerid, -1, "No teamkilling." ); // Sends a message to the killer with a white colour ( -1 ), with the message " No teamkilling. ".

            GivePlayerMoney( killerid, - 5000 ); // Take $5000 from the killerid, because teamkilling,
        }

        else // Another team killed the player
        {
            SendClientMessage( killerid, -1, "Nice shot!" ); // Sends a message to the killer with a white colour ( -1 ) with the message "Nice Shot! ".

            GivePlayerMoney( killerid, 5000 ); // Gives the killerid $5000.
        }
    }

    SendDeathMessage(  killerid, playerid, reason ); // Sends a death message about the killerid is killing the player, with the reason ( At the middle right of your game, can be toggled by pressing F9 ).

    return 1; // This means the callback is executed succesfully.
}
REP ME IF I HELPED
No, I am not looking for this, I mean when you shot a player he/she will not be damaged.

Quote:

You are definitely not comparing betw3en YOUR team and the guy who is being shot what you are doing is comparing between your team and the shot player id not his gTeam.

sorry for spalling mistkaes on phone r8 now.

Okay, let me try it
Reply
#5

So, simply edit your check?

pawn Код:
// FROM:
if(hitid == gTeam[playerid] || hitid == GetPlayerTeam(playerid))
// TO:
if(GetPlayerTeam(playerid) == GetPlayerTeam(hitid))
Reply
#6

Exactly what iZn posted above.
Reply
#7

And to avoid some bugs (hittype can be vehicle or object, not only player) check if hittype is BULLET_HIT_TYPE_PLAYER before you check the team of hitid.
Reply
#8

just remove SetPlayerHealth
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)