SA-MP Forums Archive
One player booleans. - 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: One player booleans. (/showthread.php?tid=424714)



One player booleans. - arjanforgames - 23.03.2013

Hello. I got a problem in my server.

If I create a boolean for example (top of my script):

pawn Код:
new bool:testboolean;
and then,

pawn Код:
public OnPlayerConnect(playerid)
{
    testboolean = false;
    return 1;
}
Im using ZCMD so I create the command with their system.
Then I have down at the bottom of my script:

pawn Код:
CMD:test(playerid, params[])
{
    testboolean = true;
    return 1;
}

Then after I die it will do:

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(testboolean == true)
    {
        SendClientMessage(playerid, COLOR_RED, "TRUE");
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "FALSE");
    }
    return 1;
}



Now if I die it will say False.
Then when I type "/test" and die it will say True.

But when my friend is logged in and I do "/test" and he dies as well he also gets True.

How can I set "personal" booleans? So only one player will be affected by it.

Please help.


Re: One player booleans. - Rock - 23.03.2013

pawn Код:
new bool:testboolean[ MAX_PLAYERS ];

testboolean[ playerid ] = true;



Respuesta: One player booleans. - Parka - 23.03.2013

pawn Код:
new bool:testboolean[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    testboolean[playerid] = false;
    return 1;
}

CMD:test(playerid, params[])
{
    testboolean[playerid]  = true;
    return 1;
}



public OnPlayerSpawn(playerid)
{
    if(testboolean[playerid] == true)
    {
        SendClientMessage(playerid, COLOR_RED, "TRUE");
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "FALSE");
    }
    return 1;
}



Re: One player booleans. - Misiur - 23.03.2013

Use char-arrays to not waste your resources.


Re: One player booleans. - arjanforgames - 23.03.2013

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Use char-arrays to not waste your resources.
Im a beginning scripter so I'll use this:

pawn Код:
new bool:testboolean[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    testboolean[playerid] = false;
    return 1;
}

CMD:test(playerid, params[])
{
    testboolean[playerid]  = true;
    return 1;
}



public OnPlayerSpawn(playerid)
{
    if(testboolean[playerid] == true)
    {
        SendClientMessage(playerid, COLOR_RED, "TRUE");
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "FALSE");
    }
    return 1;
}
Thanks all for the help!
It worked!


Re: One player booleans. - Misiur - 23.03.2013

Being beginner doesn't mean you can't form some good habits. All you have to do is

pawn Код:
new bool:testboolean[MAX_PLAYERS];
//changes into
new bool:testboolean[MAX_PLAYERS char];

//every
testboolean[playerid]
//changes into
testboolean{playerid}
That's all you need. (keep in mind that without understanding what this does, you should use it only for boolean arrays).


Re: One player booleans. - arjanforgames - 23.03.2013

Yeah so what would I use this?
Could you explain?


Re: One player booleans. - arjanforgames - 23.03.2013

Sorry for the double post but how can I let this show for only ONE player.

pawn Код:
forward Map1Loaded();
public Map1Loaded()
{
    for( new i = 0; i < MAX_PLAYERS; i ++ )
    {
        TextDrawHideForPlayer(i, LoadingMap1);
        TextDrawHideForPlayer(i, Map1Name);
        TextDrawHideForPlayer(i, StripesMap1);
        ShowPlayerDialog(i, DIALOG_TEAMSELECT, DIALOG_STYLE_LIST, "Choose your team", "Spetsnaz\nBlack Ops", "Choose", "");
        SetPlayerPos(i, 1565.1692, -3558.5388, 52.3151);
        SetCameraBehindPlayer(i);
        TogglePlayerControllable(i, 1);
       
    }
}


This is what calls the Map1Loaded:

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if( newkeys & KEY_YES )
    {
        ShowPlayerDialog(playerid, DIALOG_CHOOSEGAME, DIALOG_STYLE_LIST, "Choose your gamemode...", "Team Deathmatch\nSearch and Destroy [SOON]\n-----------------------\n == Go to lobby ==", "Choose", "");
    }
    return 1;
}
Then if they choose Team Deathmatch:

pawn Код:
if(response)
    {
    switch(dialogid)
        {
            case DIALOG_CHOOSEGAME:
            {
                switch(listitem)
                {
                    case 0:
                    {
                        TogglePlayerControllable(playerid, 0);
                        SetPlayerCameraPos(playerid, 1471.0837, -3464.1860, 61.6439);
                        SetPlayerCameraLookAt(playerid, 1576.0729, -3625.4319, 3.4897);
                        TextDrawShowForPlayer(playerid, LoadingMap1);
                        TextDrawShowForPlayer(playerid, Map1Name);
                        TextDrawShowForPlayer(playerid, StripesMap1);
                        SetTimer("Map1Loaded", 7000, 0);
                    }
                    case 1:
                    {
                        ShowPlayerDialog(playerid, DIALOG_CHOOSEGAME, DIALOG_STYLE_LIST, "Choose your gamemode...", "Team Deathmatch\nSearch and Destroy [SOON]\n-----------------------\n == Go to lobby ==", "Choose", "");
                    }
                    case 2:
                    {
                        ShowPlayerDialog(playerid, DIALOG_CHOOSEGAME, DIALOG_STYLE_LIST, "Choose your gamemode...", "Team Deathmatch\nSearch and Destroy [SOON]\n-----------------------\n == Go to lobby ==", "Choose", "");
                    }
                    case 3:
                    {
                        SetPlayerPos(playerid, 2009.4140, 1017.8990, 994.4680);
                    }
                }
            }
        }
    }

But at the end if the player gets the dialog of choosing his team other players get it also.
How to fix this?