SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 21/06/2020, 07:43 PM   #1
_GHT_MarK445
Huge Clucker
 
Join Date: Oct 2010
Posts: 303
Reputation: 11
Default damage problem

Hi guys,

I have this code:
Code:
	if(Player[damagedid][TrainingType] > 0 || FillingNeed[damagedid] == true)
	{
		if(Player[playerid][Team] == 0)
		{
			new Float:health;
			GetPlayerHealth(damagedid, health);
		    SetPlayerHealth(playerid, -amount);
		    SetPlayerHealth(damagedid, health+amount);
		    ShowPlayerMessageBox(playerid, "Info", "It is permitted to harm players while they are performing this action.", 0, 5000);
		}
	}
Basically what i want is, that if the PLAYERID punches DAMAGEDID, the damage, that PLAYERID would cause, would decrease from his health, not from DAMAGEDID (his would still be the same).

I hope i am understandable enough. The problem is, that when PLAYERID hits DAMAGEDID, he instantly dies (PLAYERID).

Is there any way how to solve this problem?
_GHT_MarK445 is offline   Reply With Quote
Old 21/06/2020, 07:49 PM   #2
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,077
Reputation: 126
Default Re: damage problem

You are setting the health value below 0 so the player dies
pawn Code:
SetPlayerHealth(playerid, -amount);
__________________
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!


Undead Wasteland Roleplay - 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.
Discord - Website
jasperschellekens is offline   Reply With Quote
Old 21/06/2020, 08:22 PM   #3
_GHT_MarK445
Huge Clucker
 
Join Date: Oct 2010
Posts: 303
Reputation: 11
Default Re: damage problem

So if i do this:
Code:
SetPlayerHealth(playerid, amount);
The "amount" will be constantly updating due to how many HP should he as he would be loosing HP have?

Basicaly:
I will punch you, i will loose that desired amount of HP, for eg. 2.
_GHT_MarK445 is offline   Reply With Quote
Old 21/06/2020, 08:28 PM   #4
jasperschellekens
High-roller
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Holland
Posts: 1,077
Reputation: 126
Default Re: damage problem

This is how it should be used:
pawn Code:
new Float: HP;
GetPlayerHealth(playerid, HP);
SetPlayerHealth(playerid, HP-amount);

Basically this:
pawn Code:
SetPlayerHealth(playerid, -amount);

Will set the player health to minus the amount of damage done. Let's say you hit someone, idk howmuch it is precise but let's say 5. You will be setting the health of the player to -5 which is lower than 0, so he dies.

You want to get the current health minus the amount like I did in the example on top of this post.

So in your case:
pawn Code:
SetPlayerHealth(playerid, health - amount); // Health minus damage amount
__________________
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!


Undead Wasteland Roleplay - 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.
Discord - Website
jasperschellekens is offline   Reply With Quote
Old 22/06/2020, 07:58 PM   #5
_GHT_MarK445
Huge Clucker
 
Join Date: Oct 2010
Posts: 303
Reputation: 11
Default Re: damage problem

So pretty much this:
Code:
			new Float:HPvictim, Float:HPattacker;
			GetPlayerHealth(playerid, HPattacker);
			GetPlayerHealth(damagedid, HPvictim);
		    SetPlayerHealth(playerid, HPattacker-amount);
		    SetPlayerHealth(damagedid, HPvictim+amount);
Will give the attacker damage he makes to victim, and keep the victims health the same, as it was a nano-second before attack?
_GHT_MarK445 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
How can i block on foot damage to vehicle? (Fist damage) SmileyGOD Scripting Help 2 17/01/2020 09:20 PM
weapon-config self damage and weaponized vehicle damage Chyakka Scripting Help 6 13/12/2018 04:28 PM
Damage problem. TroS Scripting Help 6 09/07/2018 05:01 PM
Problem with damage HNIC Scripting Help 8 29/01/2018 07:21 PM
Problem - Damage Petry Scripting Help 2 07/08/2015 04:53 PM


All times are GMT. The time now is 08:48 AM.


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