Need help with this small problem.
#1

I'm a bit confused here. I'm attempting to implement a "Talent" for my server, which is named Second Chance. This is what it's suppose to do: When you die, you will spawn at your death location with 50 health. Then the next death, you will spawn at the "normal" spawn. Then after that, you will then again spawn at the death location. I'm trying to find a way to not make it so you spawn at your death location EVERY death. So I've created a variable, and tried to implement it. But it just doesn't seem to work for me.

Help is appreciated. Here's my current variable, and code.

pawn Код:
//Global Variables
new Float:sx, Float:sy, Float:sz;
//
new revive[MAX_PLAYERS];
--------------

// Under  OnPlayerSpawn.
if(PlayerInfo[playerid][pTalent] == 4)
    {
        if(revive[playerid] == 1)
        {
            revive[playerid] = 0;
            SetPlayerPos(playerid, sx, sy, sz);
            SetPlayerHealth(playerid, 50);
            SendClientMessage(playerid,COLOR_GREEN, "(Second Chance Talent): You will now respawn at your death location with 50 health.");
        }
    }

// Under OnPlayerDeath

if(PlayerInfo[playerid][pTalent] == 4)
    {
        if(revive[playerid] == 1)
        {
            revive[playerid] = 0;
        }
        revive[playerid] = 1;
        GetPlayerPos(playerid, sx, sy, sz);
    }
I'm really confused as to what to do next.
Reply
#2

Did you set the variable to false (" 0 ") in onplayerconnect and onplayerdisconnect?..
Reply
#3

pawn Код:
if(revive[playerid] == 1)
        {
            revive[playerid] = 0;
        }
        revive[playerid] = 1;
If revive == 1, then set it to 0. BUT, you then go on to set it to 1 no matter what. It should be:

pawn Код:
if(revive[playerid] == 1) revive[playerid] = 0;
else revive[playerid] = 1;
No?
Reply
#4

So you're saying.
pawn Код:
if(PlayerInfo[playerid][pTalent] == 4)
    {
        if(revive[playerid] == 1) revive[playerid] = 0;
        else revive[playerid] = 1;
        GetPlayerPos(playerid, sx, sy, sz);
    }
has a chance to work? Would I remove the variable from onplayerspawn?
Reply
#5

If my head is working correctly, which I think it is, then yes, remove the revive = 0 under OnPlayerSpawn too.
Reply
#6

I'll be damned, it worked. Could you explain to me what I was doing wrong? I still don't really understand.
Reply
#7

I'll give you some pseudo code.

pawn Код:
if(variable == 0)
{
    variable = 1;
}
variable = 0;
When you begin reading, that code is checking to see if variable equals 0. If it does, then it will set variable to equal 1. Outside of the if-statement is another statement that's setting variable to equal 0.

See the problem? You're checking to see if the variable equals something, then you're setting it. However, you then set it to ANOTHER value even after you just ran a check on it.

The code "if(variable == 0)" will only be called if the value of variable EQUALS 0. Which, in the code given, will always be the case.

Take this code, as another example:

pawn Код:
while(variable == 0)
{
    if(variable == 0)
    {
        variable = 1;
    }
    variable = 0;
}
There's a never ending loop. The code is constantly setting variable equal to 0, even though it just set it to equal 1. That loop will NEVER stop and will actually just hang the server.

I hope that makes more sense. I'm tired as hell and can't think of another way to describe the issue.
Reply
#8

I understand my mistake, sort of. I'll try to avoid it in the future, and read it several times to try and understand.

I appreciate your help, and enjoy the reputation (Which I don't spread often.)
Reply
#9

Quote:
Originally Posted by rangerxxll
Посмотреть сообщение
I understand my mistake, sort of. I'll try to avoid it in the future, and read it several times to try and understand.

I appreciate your help, and enjoy the reputation (Which I don't spread often.)



4 char.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)