SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 23/08/2019, 08:21 AM   #1
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Blocking damages in certain checks

Ok so, i'm dealing with this since 2 weeks without resolving anything and i don't know what else do to.

Basically i'm using OnPlayerGiveDamage to block damages in certain circumstances like when a player is jailed or when a cop shoot an innocent.

This seems to work with weapons but not with fist. I have tried add GetPlayerWeapon(playerid) == 0 but resolved anything.

pawn Code:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
{
    if(damagedid != INVALID_PLAYER_ID && playerid != INVALID_PLAYER_ID)
    {
        GetPlayerHealth(damagedid, php);
        GetPlayerArmour(damagedid, parm);

        /* -- Disable Damage In Jail -- */
        if(Player[playerid][Jailed] || Player[damagedid][Jailed]) return 0;
        /* ---------------------------- */

        /* -- Prevent LEOs Randomly Attacking Innocents -- */
        if(ReturnPlayerClass(playerid) == CLASS_LAW && ReturnPlayerClass(damagedid) == CLASS_CIVILIAN && !ReturnWantedLevel(damagedid) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
        {
            if(GetPlayerWeapon(playerid) == 0) return 0;
           
            SetPlayerHealth(damagedid, php);
            if(parm > 0) SetPlayerArmour(damagedid, parm);

            TogglePlayerControllable(playerid, 0);

            InformPlayer(playerid, 5000, "~w~Don't ~r~attack ~w~innocent civilians! (White blips) ~n~~n~Please read ~y~/pc ~w~for more info about player colors.");
           
            SetTimerEx("UnFreezePlayer", 3000, false, "i", playerid);
            return 0;
        }  
        /* ----------------------------------------------- */

        /* -- Anti Random DM -- */
        if(ReturnPlayerClass(playerid) == CLASS_CIVILIAN && ReturnPlayerClass(damagedid) == CLASS_CIVILIAN && !ReturnWantedLevel(damagedid) && !ReturnPlayerBounty(damagedid))
        {
            if(GetPlayerWeapon(playerid) == 0) return 0;

            SetPlayerHealth(damagedid, php);
            if(parm > 0) SetPlayerArmour(damagedid, parm);

            TogglePlayerControllable(playerid, 0);
                   
            InformPlayer(playerid, 5000, "~w~Don't ~r~randomly attack ~w~innocent civilians. ~n~~n~Please read ~y~/pc ~w~for more info about player colors.");
                   
            SetTimerEx("UnFreezePlayer", 3000, false, "i", playerid);
            return 0;
        }
        /* -------------------- */         
    }
    return 1;
}

Also another strange problem, if i'm a civilian (doesn't matter if i have a wanted level or not) and i attack CLASS_LAW player (cop) i get the "Don't randomly attack innocent civilians" message, when it shouldn't be like this.

Any tips on how to finally fix this trolling code? Maybe some tips also are appreciated.

Basically i want block damages when:

Player is jailed (so if both players are in same cell even if they punch each other they don't get damage).
A cop cannot attack an innocent civilian (With wanted level of 0)
A civilian cannot attack another innocent civilian (wanted level of 0).

This is what i tried to, but doesn't work.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 23/08/2019, 08:59 AM   #2
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,119
Reputation: 68
Default Re: Blocking damages in certain checks

Code is unreachable by that returns, that's why you don't get that "Don't randomly attack..." message.

add OnPlayerTakeDamage to prevent damage from a fist and melee attacks.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 23/08/2019, 11:38 AM   #3
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: Blocking damages in certain checks

No, i get the message but damage doesn't get blocked with fist only.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 24/08/2019, 10:25 AM   #4
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: Blocking damages in certain checks

Bump.
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 26/08/2019, 02:25 PM   #5
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: Blocking damages in certain checks

Nobody?
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 26/08/2019, 02:34 PM   #6
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,119
Reputation: 68
Default Re: Blocking damages in certain checks

prevent fist damage in OnPlayerTakeDamage, not in OnPlayerGiveDamage.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 26/08/2019, 04:34 PM   #7
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: Blocking damages in certain checks

Should i use GetPlayerWeapon check for all melee weapons in TakeDamage?
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 26/08/2019, 06:32 PM   #8
Markski
Big Clucker
 
Markski's Avatar
 
Join Date: Apr 2015
Location: La Plata, Argentina
Posts: 101
Reputation: 17
Default Re: Blocking damages in certain checks

OnPlayerGiveDamage does not work for fist because that callback's return is only relevant for Lag Compensation. Fist fighting is not lag compensated. The callback WILL be called, but the game will completely disregard wether you return 0 or 1. If the punch lands on the victim's screen, then it lands.

Return 0 on OnPlayerTakeDamage if player weapon is = 0/fist , that should probably work.

If it does not, then try having it add the health amount lost back to the player. Don't do this on OnPlayerGiveDamage, since it'll heal the player no matter wether the punch landed or not on the victim's screen.
Markski is offline   Reply With Quote
Old 27/08/2019, 05:02 PM   #9
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 533
Reputation: 18
Default Re: Blocking damages in certain checks

Ok i did in this way. I didn't touch the OnPlayerGiveDamage code (that's for weapons) and made this on OnPlayerTakeDamage:

pawn Code:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(issuerid != INVALID_PLAYER_ID)
    {
        /* -- Disable Damage In Jail -- */
        if(Player[issuerid][Jailed] || Player[playerid][Jailed]) return 0;
        /* ---------------------------- */
           
        /* -- Disable Drive-by When No Driver In The Vehicle -- */
        if(GetPlayerState(issuerid) == PLAYER_STATE_PASSENGER)
        {
            new iVehicle = GetPlayerVehicleID(issuerid);

            if(GetVehicleDriver(iVehicle) == INVALID_PLAYER_ID) return InformPlayer(issuerid, 5000, "You cannot drive-by without a driver."), 0;
        }      
        /* ---------------------------------------------------- */

        /* -- Prevent LEO Attacking Innocents -- */
        if(ReturnPlayerClass(issuerid) == CLASS_LAW && ReturnPlayerClass(playerid) == CLASS_CIVILIAN && !ReturnWantedLevel(playerid) && IsAMeleeWeapon(GetPlayerWeapon(issuerid)))
        {
            TogglePlayerControllable(issuerid, 0);

            InformPlayer(issuerid, 5000, "~w~Don't ~r~attack ~w~innocent civilians! (White blips) ~n~~n~Please read ~y~/pc ~w~for more info about player colors.");
           
            SetTimerEx("UnFreezePlayer", 3000, false, "i", issuerid);
            return 0;
        }      
        /* ------------------------------------- */

        /* -- Prevent Innocents Being Attacked -- */
        if(ReturnPlayerClass(issuerid) == CLASS_CIVILIAN && ReturnPlayerClass(playerid) == issuerid && !ReturnWantedLevel(playerid) && IsAMeleeWeapon(GetPlayerWeapon(issuerid)))
        {
            TogglePlayerControllable(issuerid, 0);
                   
            InformPlayer(issuerid, 5000, "~w~Don't ~r~randomly attack ~w~innocent civilians. ~n~~n~Please read ~y~/pc ~w~for more info about player colors.");
                   
            SetTimerEx("UnFreezePlayer", 3000, false, "i", issuerid);
            return 0;
        }      
        /* -------------------------------------- */
    }
    return 1;
}

Is this correct?
__________________


Discord | Play Now | Website

Add your server to favourites and join our Discord.
Symon is offline   Reply With Quote
Old 28/08/2019, 07:06 AM   #10
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,765
Reputation: 840
Default Re: Blocking damages in certain checks

OnPlayerTakeDamage or OnPlayerGiveDamage doesn't deal with return values, you'll have to create a custom damage system, which is a lot of work or you can use weapon-config.inc
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix 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
Checks people around cuemur Scripting Help 1 08/01/2014 02:52 AM
Need a little help with some player checks mickos Scripting Help 7 02/01/2013 06:13 PM
can anyone checks? iBot Scripting Help 3 17/11/2012 03:09 AM
Checks Machida Help Archive 4 20/08/2011 01:16 AM
How to do these Key Checks? Bcklup Help Archive 4 09/07/2010 07:59 AM


All times are GMT. The time now is 03:33 PM.


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