Question about Timers and also TextLabels for onduty admins not working
#1

I have a timer that starts when the player connects which saves his stats every 5 minutes incase the server crashes,
Does this timer automaticly stop when the player disconnects?

Or does this need to get added at OnPlayerDisconnect? And how?
Here's the code:

SetTimerEx("UpdatePlayerStats", 300000, 1, "i", playerid);


2nd Issue:

I want to have text labels when an administrator is onduty.. However every player (admin or regular player) has 'Onduty administrator' above his head for some reason..

Here's the code:

pawn Код:
new Text3D:admintext[MAX_PLAYERS];
new Text3D:modtext[MAX_PLAYERS];



if (strcmp("/onduty", cmdtext, true, 7) == 0)
    {
        if (PlayerInfo[playerid][pAdmin] > 0)
        {
            if (AdminDuty[playerid] == 1)
            {
                SendClientMessage(playerid, COLOR_RED, "You are already onduty.");
            }
            else if (AdminDuty[playerid] == 0)
            {
                if (IsHidden[playerid] == 0)
                {
                    //SendClientMessage(playerid, COLOR_LIGHTBLUE, "You are now onduty.");
                    AdminDuty[playerid] = 1;
                    new name[MAX_PLAYER_NAME+1];
                    new string[64+MAX_PLAYER_NAME+1];
                    GetPlayerName(playerid, name, sizeof(name));
                    GetAdminTitle(playerid);
                    format(string, sizeof(string), "%s %s (ID %d) has gone onduty.", AdminTitle[playerid], name, playerid);
                    SendClientMessageToAll(COLOR_DARKCYAN, string);
                    if (PlayerInfo[playerid][pAdmin] == 1 || PlayerInfo[playerid][pAdmin] == 2)
                    {
                        modtext[playerid] = Create3DTextLabel("Onduty Moderator", COLOR_LIGHTBLUE, 30.0, 40.0, 50.0, 40.0, 0);
                        Attach3DTextLabelToPlayer(modtext[playerid], playerid, 0.0, 0.0, 0.7);
                    }
                    else if (PlayerInfo[playerid][pAdmin] == 3 || PlayerInfo[playerid][pAdmin] == 4 || PlayerInfo[playerid][pAdmin] == 5)
                    {
                        admintext[playerid] = Create3DTextLabel("Onduty Administrator", COLOR_LIGHTBLUE, 30.0, 40.0, 50.0, 40.0, 0);
                        Attach3DTextLabelToPlayer(admintext[playerid], playerid, 0.0, 0.0, 0.7);
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_RED, "You cannot go onduty whilst you are hidden from the administrators list!");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Your moderator/admistrator level is not high enough to go onduty!");
        }
        return 1;
    }
   
    if (strcmp("/offduty", cmdtext, true, 8) == 0)
    {
        if (PlayerInfo[playerid][pAdmin] > 0)
        {
            if (AdminDuty[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_RED, "You are already offduty.");
            }
            else if (AdminDuty[playerid] == 1)
            {
                //SendClientMessage(playerid, COLOR_LIGHTBLUE, "You are now offduty.");
                AdminDuty[playerid] = 0;
                new name[MAX_PLAYER_NAME+1];
                new string[64+MAX_PLAYER_NAME+1];
                GetPlayerName(playerid, name, sizeof(name));
                GetAdminTitle(playerid);
                format(string, sizeof(string), "%s %s (ID %d) is no longer onduty.",AdminTitle[playerid], name, playerid);
                SendClientMessageToAll(COLOR_DARKCYAN, string);
                Delete3DTextLabel(modtext[playerid]);
                Delete3DTextLabel(admintext[playerid]);
                DeletePlayer3DTextLabel(playerid, PlayerText3D:admintext[playerid]);
                DeletePlayer3DTextLabel(playerid, PlayerText3D:modtext[playerid]);
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Your moderator/admistrator level is not high enough to go offduty!");
        }
        return 1;
    }
Reply
#2

I don't think it would be necessary for you to use a KillTimer function (as that is the function you need to kill timers) at OnPlayerDisconnect.

Also, for your 3dtextlabel, make it only show when admins are on duty.

pawn Код:
if (PlayerInfo[playerid][pAdmin] == 1 || PlayerInfo[playerid][pAdmin] == 2 && AdminDuty[playerid] == 1)
Reply
#3

Quote:
Originally Posted by Mionee
Посмотреть сообщение
I don't think it would be necessary for you to use a KillTimer function (as that is the function you need to kill timers) at OnPlayerDisconnect.

Also, for your 3dtextlabel, make it only show when admins are on duty.

pawn Код:
if (PlayerInfo[playerid][pAdmin] == 1 || PlayerInfo[playerid][pAdmin] == 2 && AdminDuty[playerid] == 1)
Ahh, yes! I made it only check for admin level, and not onduty!

However, that still doesn't explain how level 0 (normal player) and my trial moderators (level 1) also got the Admin tag. Do you see what I did wrong?
Reply
#4

I don't understand why it'd do that. I can't seem to spot any visible errors in your code, I'll ask around for you though.
Reply
#5

Where do I put the:

new Text3D:admintext[MAX_PLAYERS];
new Text3D:modtext[MAX_PLAYERS];


All the way on the top right, not in the function itself?

And also, when you use /onduty, your AdminDuty is always 1, so it shouldn't have to check for that in the if..
Really confused as to why it's not working :X
Reply
#6

You put both those defines at the top of your script. I re-wrote your command using ZCMD. I really recommend you to use that instead of strcmp. I can't write functions in strcmp, but perhaps you can take snippets from my code. The following hasn't been tested but compiles.

pawn Код:
#include <a_samp>
#include <zcmd>

new Text3D:admintext[MAX_PLAYERS];
new Text3D:modtext[MAX_PLAYERS];

new pAdmin[MAX_PLAYERS]; // admin variable
new pAduty[MAX_PLAYERS]; // aduty variable

CMD:aduty(playerid, params[])
{
    if(pAdmin[playerid] > 0)
    {
        if(pAduty[playerid] == 0)
        {
            pAduty[playerid] = 1;
            SendClientMessage(playerid, -1, "You have gone on admin duty!");

            if(pAdmin[playerid] > 0)
            {
                modtext[playerid] = Create3DTextLabel("Onduty Moderator", COLOR_LIGHTBLUE, 30.0, 40.0, 50.0, 40.0, 0);
                Attach3DTextLabelToPlayer(modtext[playerid], playerid, 0.0, 0.0, 0.7);
            }
            else if(pAdmin[playerid] > 3)
            {
                admintext[playerid] = Create3DTextLabel("Onduty Administrator", COLOR_LIGHTBLUE, 30.0, 40.0, 50.0, 40.0, 0);
                Attach3DTextLabelToPlayer(admintext[playerid], playerid, 0.0, 0.0, 0.7);
            }
        }
        else if(pAduty[playerid] == 1)
        {
            pAduty[playerid] = 0;

            DeletePlayer3DTextLabel(playerid, admintext[playerid]);
            DeletePlayer3DTextLabel(playerid, modtext[playerid]);

            SendClientMessage(playerid, -1, "You have gone off admin duty!");
        }
    }
    else SendClientMessage(playerid, -1, "You're not an administrator.");
    return 1;
}
Reply
#7

I use dcmd, it seems similar..
Testing it now


EDIT: /onduty works, however /offduty doesn't delete the tags
Reply
#8

Quote:
Originally Posted by AnthonyTimmers
Посмотреть сообщение
I have a timer that starts when the player connects which saves his stats every 5 minutes incase the server crashes,
Does this timer automaticly stop when the player disconnects?
Nope, nothing happens by itself
pawn Код:
// OnPlayerConnect
SetPVarInt(playerid, "tUpdate", SetTimerEx("UpdatePlayerStats", 300000, 1, "i", playerid));
// OnPlayerDisconnect
KillTimer(GetPVarInt(playerid, "tUpdate"));
Reply
#9

Thanks, I put it in..


Anyone know how to get rid of the tags?

Edit: Still random people get it the tag.. and the removing doesn't work either.

DeletePlayer3DTextLabel(playerid, admintext[playerid]);
DeletePlayer3DTextLabel(playerid, modtext[playerid]);

Does anyone know how to delete the text? Cause this doesn't work ^
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)