SA-MP Forums Archive
Why does this happen... Please help - 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: Why does this happen... Please help (/showthread.php?tid=355969)



Why does this happen... Please help - Euan Hughes - 01.07.2012

Well i have been trying to create a vip system where if you get VIP it lasts for 30 days well its fine if you get VIP and the log out and log back in you still have it until the time is up..

But..

If i restart the server it says Your vip has expired and it should not have.. And i dont have VIP no more... I think it it something to do with gettime()

Please help me

pawn Код:
new VIPexpire;
This is in my player stats enum

pawn Код:
VipExpiredTime
This is under save player data

pawn Код:
dini_IntSet(string, "VipExpiredTime", Player[playerid][VipExpiredTime]);
This is on register player

pawn Код:
dini_IntSet(string, "VipExpiredTime", Player[playerid][VipExpiredTime]);
This is under on player login attempt

pawn Код:
Player[playerid][VipExpiredTime] = dini_Int(string, "VipExpiredTime");
pawn Код:
command(changeviplevel, playerid, params[])
{
    new level, id, string[128], string2[128];
    if(sscanf(params, "ud", id, level))
    {
        if(Player[playerid][AdminLevel] >= 5)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /changeviplevel [playerid] [level]");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 5)
        {
            if(level > 4 ) return SendClientMessage(playerid, RED, "Avaliable levels 1 - 4");
            if(IsPlayerConnectedEx(id))
            {
                Player[id][VipRank] = level;
                VIPexpire = gettime() + 2592000;

                format(string, sizeof(string), "%s's VIP level has been changed to %d, by %s.", GetName(id), level, GetName(playerid));
                format(string2, sizeof(string2), "%s's VIP level has been changed to %d by %s.", GetName(id), level, GetName(playerid));
                for(new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnectedEx(i) && Player[i][VipRank] >= 1)
                    {
                        SendClientMessage(i, YELLOW, string);
                        SetPlayerColor(id, YELLOW);
                    }
                    if(level == 0)
                    {
                        SendClientMessage(i, YELLOW, string2);
                        SetPlayerColor(id, WHITE);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, WHITE, "That player is not connected or isn't logged in.");
            }
        }
    }
    return 1;
}
This is under on player login

pawn Код:
if(gettime() > VIPexpire && Player[playerid][VipRank] != 0)
            {
                Player[playerid][VipExpiredTime] = 1;
            }
           
            if(Player[playerid][VipExpiredTime] == 1)
            {
                SendClientMessage(playerid, RED, "Your VIP has expired to by it again go to www.DBullet-Gaming.tk");
                Player[playerid][VipRank] = 0;
                Player[playerid][VipExpiredTime] = 0;
            }
If you need any more code just ask

Please help

Thanks


Respuesta: Why does this happen... Please help - PHudson - 01.07.2012

I think the problem is you aren't using gettime function correctly.
I recommend you to visit this page: https://sampwiki.blast.hk/wiki/Gettime


Re: Respuesta: Why does this happen... Please help - Vince - 01.07.2012

Quote:
Originally Posted by PHudson
Посмотреть сообщение
I think the problem is you aren't using gettime function correctly.
I recommend you to visit this page: https://sampwiki.blast.hk/wiki/Gettime

It's weird that your compiler doesn't send a warning for skipping three params ("hour, minute, second") when you use gettime.
Have you even bothered to read the page you linked to yourself?


Re: Why does this happen... Please help - Euan Hughes - 01.07.2012

I just added gettime like that page said and even when i restart the server it still says my VIP has expired and it actually makes my vip level nothing..

Please help

Thanks


Re: Why does this happen... Please help - Ricop522 - 02.07.2012

Use this!

pawn Код:
new expireDays = (86400*days)+gettime();

// Example, I want the vip expire in 30 days.

dini_IntSet(account, "donatorExpire", (86400*30)+gettime());


// Checking if already pass 30 days

new atualTimer = dini_Int(account, "donatorExpire");
if( atualTimer < gettime() ){
   // Your donator is out!
}
else {
   new iRandomTime = (atualTimer-gettime())+gettime();                
   format(string, 128, "Your donator will expire in %d days", timec(iRandomTime));
}



/// End of gm

stock timec(timestamp, compare = -1) {
    if (compare == -1) {
        compare = gettime();
    }
    new
        n,
        // on the following line, I have removed the need for the diff() function.
        // if you want to use the diff() function in pawn, replace the following with:
        // Float:d = diff(timestamp, compare),
        Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
        returnstr[32];
    if (d < 60) {
        format(returnstr, sizeof(returnstr), "< 1 minuto");
        return returnstr;
    } else if (d < 3600) { // 3600 = 1 hour
        n = floatround(floatdiv(d, 60.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "minuto");
    } else if (d < 86400) { // 86400 = 1 day
        n = floatround(floatdiv(d, 3600.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "hora");
    } else if (d < 2592000) { // 2592000 = 1 month
        n = floatround(floatdiv(d, 86400.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "dia");
    } else if (d < 31536000) { // 31536000 = 1 year
        n = floatround(floatdiv(d, 2592000.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "mкs");
    } else {
        n = floatround(floatdiv(d, 31536000.0), floatround_floor);
        format(returnstr, sizeof(returnstr), "ano");
    }
    if (n == 1) {
        format(returnstr, sizeof(returnstr), "1 %s", returnstr);
    } else {
        format(returnstr, sizeof(returnstr), "%d %ss", n, returnstr);
    }
    return returnstr;
}
I hope this is useful for you


Re: Why does this happen... Please help - Euan Hughes - 02.07.2012

Where should i put this

Thanks


Re: Why does this happen... Please help - Tee - 02.07.2012

pawn Код:
command(changeviplevel, playerid, params[])
{
    new level, id, string[128], string2[128];
    if(sscanf(params, "ud", id, level))
    {
        if(Player[playerid][AdminLevel] >= 5)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /changeviplevel [playerid] [level]");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 5)
        {
            if(level > 4 ) return SendClientMessage(playerid, RED, "Avaliable levels 1 - 4");
            if(IsPlayerConnectedEx(id))
            {
                Player[id][VipRank] = level;
                Player[id][VipExpiredTime] = gettime() + 2592000;

                format(string, sizeof(string), "%s's VIP level has been changed to %d, by %s.", GetName(id), level, GetName(playerid));
                format(string2, sizeof(string2), "%s's VIP level has been changed to %d by %s.", GetName(id), level, GetName(playerid));
                for(new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnectedEx(i) && Player[i][VipRank] >= 1)
                    {
                        SendClientMessage(i, YELLOW, string);
                        SetPlayerColor(id, YELLOW);
                    }
                    if(level == 0)
                    {
                        SendClientMessage(i, YELLOW, string2);
                        SetPlayerColor(id, WHITE);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, WHITE, "That player is not connected or isn't logged in.");
            }
        }
    }
    return 1;
}
pawn Код:
if(gettime() > Player[playerid][VipExpiredTime] && Player[playerid][VipRank] != 0)
            {
                Player[playerid][VipExpiredTime] = 1;
            }

            if(Player[playerid][VipExpiredTime] == 1)
            {
                SendClientMessage(playerid, RED, "Your VIP has expired to by it again go to www.DBullet-Gaming.tk");
                Player[playerid][VipRank] = 0;
                Player[playerid][VipExpiredTime] = 0;
            }
You were using a global variable to save the expire time, which would reset when the server restarts. Try the code I've placed above.