SA-MP Forums Archive
Code not working properly - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Code not working properly (/showthread.php?tid=508260)



Code not working properly - Lajko1 - 21.04.2014

Hello I have this at my command:

pawn Код:
if(Health < 1)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }
It doesn't want to send msg when player dies..?


Re: Code not working properly - JeaSon - 21.04.2014

try this
pawn Код:
new Float:Health;
if(Health < 1)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }



Re: Code not working properly - Cookland - 21.04.2014

new Float:Health;

Post it at the top and it should work fine for you.


Re: Code not working properly - Dignity - 21.04.2014

Where did you put this code?


Re: Code not working properly - Dragon2 - 21.04.2014

Код:
new Float:Health;
if(Health < 0)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }



Re: Code not working properly - Dignity - 21.04.2014

Quote:
Originally Posted by Dragon2
Посмотреть сообщение
Код:
new Float:Health;
if(Health < 0)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }
What makes you think this would work?


Re: Code not working properly - Konstantinos - 21.04.2014

Quote:
Originally Posted by Namer
Посмотреть сообщение
try this
pawn Код:
new Float:Health;
if(Health < 1)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }
Quote:
Originally Posted by Dragon2
Посмотреть сообщение
Код:
new Float:Health;
if(Health < 0)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }
Declaring a variable without any value and checking its value right away makes absolutely no sense. Health will always be 0.0

You must get the player's health first and then check for it.


Re: Code not working properly - Lajko1 - 21.04.2014

pawn Код:
else if(strcmp(x_nr,"heroin",true) == 0)
        {
            new Float:Health;
            GetPlayerHealth(playerid, Health);

            new Float:Armour;
            GetPlayerArmour(playerid, Armour);
           
            if(Pdrug[playerid][Needle] >= 1)
            {
                if(Pdrug[playerid][Heroin] >= 1)
                {
                    if(Pdrug[playerid][Addiction] >= 30)
                    {
                        Pdrug[playerid][Addiction] = 0;
                        Pdrug[playerid][AddictionLv] += 1;
                        SendClientMessage(playerid, -1, "{FFFFFF}Your addiction level has raised, write /addiction to read about drug addiciton levels.");
                    }
                    Pdrug[playerid][Heroin] -= 1;
                    Pdrug[playerid][Addiction] += 10;
                    SetPlayerDrunkLevel (playerid, 50000);
                    SetPlayerWeather(playerid, 9); // foggy - cold..
                    SendClientMessage(playerid, -1, "{FFFFFF}You've used 1 gram of heroin your health points decreased by -40 and armour points raised by +25.");
                    TextDrawShowForPlayer(playerid,Text:Textdraw0);
                    // Animation

                    if(Health < 1)
                    {
                        SendClientMessage(playerid, -1, "{FF6A22}INFO: {FFFFFF}You have died because of drug overdose.");
                    }
                    else if(Health >= 1)
                    {
                        SetPlayerHealth(playerid, Health -40);
                    }
This is almost full code... That part where it says "you have died becaouse of drug overdose.." it's not working.


Re: Code not working properly - mrkiller90 - 21.04.2014

Maybe you have to use the onplayerdead callback instead of if(Health < 1) I dont know


Re: Code not working properly - Lajko1 - 21.04.2014

So where is the problem? Anyone?