[Tutorial] Death System
#1

Iformation;
This is a basic system that pretty much put's a player in injured mode, and if their shot again whilst in 'injured' mode it sends them directly to the hospital.

Code;
pawn Код:
#include <a_samp>

enum pInfo {
   pInjured,
}
new Players[MAX_PLAYERS][pInfo];

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    if(health < 15.0)
    {
        TogglePlayerControllable(playerid, 0);
        ApplyAnimation(playerid,"CRACK","crckidle2",1,0,0, 0,0,0);
        Players[playerid][pInjured] = 1;
    }
    if(Players[playerid][pInjured] == 1)
    {
        SetPlayerHealth(playerid, 75);
        SetPlayerPos(playerid, 2035.3583,-1412.8423,16.9922);
        TogglePlayerControllable(playerid, 1);
        SendClientMessage(playerid, -1, "You've been injured, and respawned at the hospital");
        Players[playerid][pInjured] = 0;
    }
    return 1;
}
Breakdown;
Код:
#include <a_samp>
This include a_samp for the default SAMP functions for your gamemode, and makes things like TogglePlayerControlable(), and SetPlayerPos work.

Код:
enum pInfo {
   pInjured,
}
new Players[MAX_PLAYERS][pInfo];
This is an enumerator for your player info. An enumerator just translates numbers into words for ease of use, with that being said the new Players[MAX_PLAYERS][pInfo] is an array. (If you're not sure what's an array ****** or SAMP wiki is your friend.)
https://sampforum.blast.hk/showthread.php?tid=318307

Код:
    new Float:health;
    GetPlayerHealth(playerid,health);
    if(health < 15.0)
    {
        TogglePlayerControllable(playerid, 0);
        ApplyAnimation(playerid,"CRACK","crckidle2",1,0,0, 0,0,0);
        Players[playerid][pInjured] = 1;
    }
The float defines the user health, and GetPlayerHealth checks for their HP then after if the users health is 15.0 or lower then it applies the hut animation, and makes it where the user cannot get out of the anim by toggling his power to control his character, and it also sets the enum value of the pInjured to 1 or yes.

Код:
    if(Players[playerid][pInjured] == 1)
    {
        SetPlayerHealth(playerid, 75);
        SetPlayerPos(playerid, 2035.3583,-1412.8423,16.9922);
        TogglePlayerControllable(playerid, 1);
        SendClientMessage(playerid, -1, "You've been injured, and respawned at the hospital");
        Players[playerid][pInjured] = 0;
This checks if the player is injured when they take damage if it's true, and their injured then it sets them to the hospital, and their HP up to 75.
Reply
#2

It is very basic. And it is explained. Not bad not bad
Reply
#3

But when compiling i get an error.
Код:
error 025: function heading differs from prototype
And this is the line of error
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
Reply
#4

Update your SA-MP includes.
Reply
#5

Quote:
Originally Posted by Micko123
Посмотреть сообщение
But when compiling i get an error.
Код:
error 025: function heading differs from prototype
And this is the line of error
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
Download the most latest samp server package, and replace a_samp.inc as it works fine for me;
Reply
#6

I downloaded latest samp server from sa-mp.com and replaced all includes. Still have error -_-
Reply
#7

Quote:
Originally Posted by Micko123
Посмотреть сообщение
I downloaded latest samp server from sa-mp.com and replaced all includes. Still have error -_-
Eh no idea then mate. Try using it on a blank .pwn w/ the new packages if it works then you should be able to narrow down your problem.
Reply
#8

Its done. It was problem with YSI\y_ini . One guy sent me all includes and it worked. Thanks guys
Reply
#9

Quote:
Originally Posted by Micko123
Посмотреть сообщение
Its done. It was problem with YSI\y_ini . One guy sent me all includes and it worked. Thanks guys
No prob
Reply
#10

If you're gonna give your players weapons that deal more than 15.0 damage, since that's your threshold for getting into the injured state, your death system will fail. Imagine a player is left with 16.0HP and gets shot by a player using a sniper rifle which deals about 49.0 damage. OnPlayerTakeDamage is going to get called AFTER the player receives the damage which means it is reverted and not prevented. Of course, if it is intended that a player can die instantly without getting into the injured state this system does its job.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)