SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/05/2020, 04:06 PM   #1
ChandraLouis
Banned
 
Join Date: Mar 2013
Location: Indonesia
Posts: 438
Reputation: 37
Default Player is not taking damage and Anti Team Kill doesn't work

This is the code:

OnPlayerTakeDamage
pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{  
    new Float:HP;
    GetPlayerHealth(playerid, HP);
    if(pTeam[playerid] && pTeam[issuerid] == TEAM_POLICE)
    {
        SetPlayerHealth(playerid, HP);
        GameTextForPlayer(issuerid, "~b~DON'T ATTACK TEAM MATE", 2000, 4);
    }
    // Civillian Attack Each Other //
    else if(pTeam[issuerid] && pTeam[playerid] == TEAM_CIVILLIAN)
    {
        SetPlayerHealth(playerid, HP-amount);
    }
    // Civillian Attack Police //
    else if(pTeam[issuerid] == TEAM_CIVILLIAN && pTeam[playerid] == TEAM_POLICE)
    {
        SetPlayerHealth(playerid, HP-amount);
    }
    else if(pTeam[issuerid] == TEAM_POLICE && pTeam[playerid] == TEAM_CIVILLIAN)
    {
        // Not Innocent //
        if(GetPlayerWantedLevel(playerid) >= 6 && pTeam[playerid] == TEAM_CIVILLIAN)
        {
            SetPlayerHealth(playerid, HP-amount);
        }
    }
    // Innocent //
    else if(GetPlayerWantedLevel(playerid) == 0 && pTeam[playerid] == TEAM_CIVILLIAN)
    {
        SetPlayerHealth(playerid, HP);
        GameTextForPlayer(issuerid, "~b~DON'T INNOCENT", 2000, 4);
    }
    return 1;
}

OnPlayerSpawn (Set team)
pawn Code:
if(pTeam[playerid] == TEAM_POLICE)
    {
        pTeam[playerid] = TEAM_POLICE;
    }
    else if(pTeam[playerid] == TEAM_CIVILLIAN)
    {
        pTeam[playerid] = TEAM_CIVILLIAN;
    }
ChandraLouis is offline   Reply With Quote
Old 15/05/2020, 04:54 PM   #2
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 485
Reputation: 37
Default Re: Player is not taking damage and Anti Team Kill doesn't work

"GetPlayerHealth and GetPlayerArmour will return the old amounts of the player before this callback." Taken from the wiki.
I would then imagine if the player has 100 HP, every SetPlayerHealth(playerid, HP); would set him back to 100 again.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone is offline   Reply With Quote
Old 15/05/2020, 04:58 PM   #3
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,168
Reputation: 165
Default Re: Player is not taking damage and Anti Team Kill doesn't work

What have you done to try debugging it?
__________________
Undead Wasteland Roleplay | Visit website
The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
jasperschellekens is offline   Reply With Quote
Old 15/05/2020, 05:03 PM   #4
GameOvr
Huge Clucker
 
GameOvr's Avatar
 
Join Date: Jun 2018
Posts: 296
Reputation: 9
Default Re: Player is not taking damage and Anti Team Kill doesn't work

Actually you dont have to do this stuff for anti team kill
SetPlayerTeam covers it all
pawn Code:
//make other teams also like this in OnPlayerSpawn
    if(pTeam[playerid] == TEAM_POLICE)
    {
        pTeam[playerid] = TEAM_POLICE;
        SetPlayerTeam(playerid, pTeam[playerid]);
    }
    else if(pTeam[playerid] == TEAM_CIVILLIAN)
    {
        pTeam[playerid] = TEAM_CIVILLIAN;
        SetPlayerTeam(playerid, pTeam[playerid]);
    }

And remove all your codes in OnPlayerTakeDamage

This will make players in same team unable to kill each other! And they can kill players on other teams

EDIT: If a solution we give you worked, make a reply by telling that the solution worked. Else other guys will bump the thread unnecessarily and it will be a help for others who is looking for the same answer
__________________
GameOvr is offline   Reply With Quote
Old 15/05/2020, 05:10 PM   #5
ChandraLouis
Banned
 
Join Date: Mar 2013
Location: Indonesia
Posts: 438
Reputation: 37
Default Re: Player is not taking damage and Anti Team Kill doesn't work

Quote:
Originally Posted by GameOvr View Post
Actually you dont have to do this stuff for anti team kill
SetPlayerTeam covers it all
pawn Code:
//make other teams also like this in OnPlayerSpawn
    if(pTeam[playerid] == TEAM_POLICE)
    {
        pTeam[playerid] = TEAM_POLICE;
        SetPlayerTeam(playerid, pTeam[playerid]);
    }
    else if(pTeam[playerid] == TEAM_CIVILLIAN)
    {
        pTeam[playerid] = TEAM_CIVILLIAN;
        SetPlayerTeam(playerid, pTeam[playerid]);
    }

And remove all your codes in OnPlayerTakeDamage

This will make players in same team unable to kill each other! And they can kill players on other teams
What if they are civillians. Also i have
pawn Code:
SetPlayerTeam(playerid, pTeam[playerid]);
under OnPlayerSpawn
ChandraLouis is offline   Reply With Quote
Old 15/05/2020, 06:13 PM   #6
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,168
Reputation: 165
Default Re: Player is not taking damage and Anti Team Kill doesn't work

You might want to take a look here:
https://wiki.sa-mp.com/wiki/SetPlayerTeam

It contain useful information for your case
__________________
Undead Wasteland Roleplay | Visit website
The year is 1996. San Andreas is a wasteland ruled by the undead. the once so glorius landscape of San Andreas, is now a shattered decayed place that is only a vague memory of the world as we used to know it.
jasperschellekens is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Player not taking damage? Polaroid Scripting Help 4 29/04/2019 02:46 PM
Player not taking damage TokicMajstor Scripting Help 5 03/02/2019 09:08 AM
Player's armour refills to 100 when taking damage Matical Scripting Help 4 16/06/2016 08:19 AM
Player not taking Damage? Zex Tan Bug Reports 5 21/08/2013 08:44 AM
Will this work? (Anti team kill) (rep++) iOmar Scripting Help 6 06/05/2012 04:53 AM


All times are GMT. The time now is 11:47 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.