Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #######################################################################################
- ### ###
- ### VIP SYSTEM ###
- ### ###
- ### ###
- ### This script are free for edition ###
- ### By: Dry ###
- #######################################################################################
- Functions:
- - IsPlayerVIP(playerid) - Check if player is a VIP.
- - LoadPlayerVIP(playerid) - Load file from Player.
- - SavePlayerVIP(playerid) - Save data from a Player.
- - CreateVipKey(playerid, Key[], Days) - Create a new key.
- - UseVipKey(playerid, Key[]) - Use one KEY for player.
- - RemoveKey(playerid, Key[]) - Remove key file.
- - GetExpirationDays(playerid) - Get expiration days.
- - SetVipForPlayer(playerid, Days) - Set/Renew vip for player.
- - ShowWelcomeMessage(playerid) - Show welcome message in textdraw.
- Commands:
- - CMD:setvip [ID] [DAYS] ( Admin ) // Set vip for player
- - CMD:viphelp ( VIP ) // Info. VIP
- - CMD:vipcode ( Default )// Active the key
- - CMD:newkey ( Admin ) // Create a new key
- - CMD:delkey [KEY] ( Admin ) // Remove a exist key
- - CMD:vips ( Default ) // List of Players VIPs online
- Config:
- #define CHAT_MODEL 3 - Design of the chat
- #define FULL_LIFE 1 - Respawn with Life and Armour full
- #define DEATH_RESPAWN_LOCAL 1 - Respawn in the death position
- Instalation:
- - Create a new folder "vips " in scriptfiles
- - Create two folders inside it:
- * Users
- * Keys
- -Dry ( Lucas ).
- */
- #include <a_samp>
- #include <dof2>
- #include <zcmd>
- #include <sscanf>
- #define ENGINE::%0(%1) stock %0(%1)
- #define Public::%0(%1) forward %0(%1); public %0(%1)
- #define DIALOG_ATIV_KEY 779
- #define DIALOG_MAKE_KEY 779+1
- #define DIALOG_MAKE_DAYS 779+2
- #define DIALOG_CONFIRM 779+3
- //Folder's
- #define VIP_USERS "Vips/Users/%s.ini"
- #define VIP_KEYS "Vips/Keys/%s.ini"
- //Colors
- #define Default 0xDE3A3AFF
- #define Branco 0xFFFFFFFF
- //Config
- #define CHAT_MODEL 3
- #define FULL_LIFE 1
- #define DEATH_RESPAWN_LOCAL 1
- #if DEATH_RESPAWN_LOCAL == 1
- new Float: X[MAX_PLAYERS], Float: Y[MAX_PLAYERS], Float: Z[MAX_PLAYERS], Interior[MAX_PLAYERS];
- #endif
- //Player Definitions
- enum PlayerParams
- {
- bool:VIP,
- dExpiration,
- hExpiration
- };
- new Player[MAX_PLAYERS][PlayerParams];
- new bool:VisibleWelcome[MAX_PLAYERS];
- new Text:DrawWelcome[MAX_PLAYERS][6];
- new TimerDraw[MAX_PLAYERS];
- new cKey[MAX_PLAYERS][128], cDays[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- for ( new playerid = 0; playerid < GetMaxPlayers(); playerid++)
- {
- if ( IsPlayerConnected(playerid))
- {
- LoadPlayerVIP(playerid);
- }
- }
- SetTimer("CheckVipsInGame", 60000, true);
- print("VIP System Loaded");
- return 1;
- }
- Public::CheckVipsInGame()
- {
- for ( new playerid = 0; playerid < GetMaxPlayers(); playerid++)
- {
- if ( IsPlayerConnected(playerid) && IsPlayerVIP(playerid))
- {
- if ( GetExpirationDays(playerid) <= 0)
- {
- SetVipForPlayer(playerid, 0);
- }
- }
- }
- }
- public OnFilterScriptExit()
- {
- for ( new playerid = 0; playerid < GetMaxPlayers(); playerid++) HiddenWelcome(playerid);
- print("VIP System UnLoaded.");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- LoadPlayerVIP(playerid);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- HiddenWelcome(playerid);
- Player[playerid][VIP] = false;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if ( IsPlayerVIP(playerid))
- {
- #if FULL_LIFE == 1
- {
- SetPlayerHealth(playerid, 100.0);
- SetPlayerArmour(playerid, 100.0);
- }
- #endif
- #if DEATH_RESPAWN_LOCAL == 1
- {
- SetPlayerInterior(playerid, Interior[playerid]);
- SetPlayerPos(playerid, X[playerid], Y[playerid], Z[playerid]);
- }
- #endif
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- #if DEATH_RESPAWN_LOCAL == 1
- {
- if ( IsPlayerVIP(playerid))
- {
- GetPlayerPos(playerid, X[playerid], Y[playerid], Z[playerid]);
- Interior[playerid] = GetPlayerInterior(playerid);
- }
- }
- #endif
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if ( IsPlayerVIP(playerid))
- {
- new Name[24];
- GetPlayerName(playerid, Name, 24);
- #if CHAT_MODEL == 1
- {
- new dStr[128];
- format ( dStr, 128, "[%d]%s[V.I.P]: {FFFFFF}%s", playerid, Name, text);
- SendClientMessageToAll(GetPlayerColor(playerid), dStr);
- return 0;
- }
- #endif
- #if CHAT_MODEL == 2
- {
- new dStr[128];
- format ( dStr, 128, "%s[%d][V.I.P]: {FFFFFF}%s", Name, playerid, text);
- SendClientMessageToAll(GetPlayerColor(playerid), dStr);
- return 0;
- }
- #endif
- #if CHAT_MODEL == 3
- {
- new dStr[128];
- format ( dStr, 128, "{F9BD0B}VIP {FFFFFF}%s diz: {FFFFFF}%s", Name, text);
- SendClientMessageToAll(GetPlayerColor(playerid), dStr);
- return 0;
- }
- #endif
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if ( dialogid == DIALOG_ATIV_KEY && response)
- {
- UseVipKey(playerid, inputtext);
- return 1;
- }
- if ( dialogid == DIALOG_MAKE_KEY && response )
- {
- format ( cKey[playerid], 128, inputtext);
- new Str[128];
- format ( Str, sizeof Str, "{FFFFFF}Your VIP KEY: {DE3A3A}%s\n\n{FFFFFF}days from expiration:", cKey[playerid]);
- ShowPlayerDialog(playerid, DIALOG_MAKE_DAYS, DIALOG_STYLE_INPUT, "{FFFFFF}Create a new key", Str, "Create", "Cancel");
- return true;
- }
- if ( dialogid == DIALOG_MAKE_DAYS && response )
- {
- if ( !IsNumeric(inputtext)) return SendClientMessage(playerid, Default, "ERROR");
- cDays[playerid] = strval(inputtext);
- new Str[500];
- format ( Str, sizeof Str, "{FFFFFF}Informations from your new key:\n\nKey: {DE3A3A}%s\n{FFFFFF}Validity: {DE3A3A}%d dias\n\n{FFFFFF}Want to create ? ?", cKey[playerid], cDays[playerid]);
- ShowPlayerDialog(playerid, DIALOG_CONFIRM, DIALOG_STYLE_MSGBOX, "{FFFFFF}Create a new KEY",Str, "Yes", "No");
- return 1;
- }
- if ( dialogid == DIALOG_CONFIRM && response)
- {
- CreateVipKey(playerid, cKey[playerid], cDays[playerid]);
- return 1;
- }
- return 1;
- }
- CMD:ativarvip(playerid)
- {
- ShowPlayerDialog(playerid, DIALOG_ATIV_KEY, DIALOG_STYLE_INPUT, "{FFFFFF}VIP activate", "{FFFFFF}Welcome.\nInsert your key for activate your vip:", "Active", "Exit");
- return 1;
- }
- CMD:newkey(playerid, params[])
- {
- if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Default, "Insufficient permissions");
- ShowPlayerDialog(playerid, DIALOG_MAKE_KEY, DIALOG_STYLE_INPUT, "{FFFFFF}Create a new key", "{FFFFFF}Insert a new VIP KEY:", "Create", "Cancel");
- return 1;
- }
- CMD:viphelp(playerid)
- {
- if ( !IsPlayerVIP(playerid)) return SendClientMessage(playerid, Default, "[Erro]{FFFFFF} You no are VIP");
- new Str[1028]; format ( Str, sizeof Str, "{FFFFFF}VIP informations.\n\nYour VIP expires in: %d days.\n\nRenew your VIP.", GetExpirationDays(playerid));
- ShowPlayerDialog(playerid, 775+1, DIALOG_STYLE_MSGBOX, "{FFFFFF}VIP", Str, "Exit", "");
- return 1;
- }
- CMD:delkey(playerid, params[])
- {
- if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Default, "Insufficient permissions");
- new Key[128];
- if ( sscanf ( params, "s", Key)) return SendClientMessage(playerid, Default, "[Erro]{FFFFFF} Insert one name of the key");
- RemoveKey(playerid, Key);
- return 1;
- }
- CMD:setvip(playerid, params[])
- {
- if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, Default, "Insufficient permissions");
- new Nome, Dias;
- if ( sscanf ( params, "id", Nome, Dias)) return SendClientMessage(playerid, Default, "[Vip] {FFFFFF}Use: /setvip [ID/NAME] [DAYS]");
- SetVipForPlayer(Nome, Dias);
- return 1;
- }
- CMD:vips(playerid)
- {
- new Name[24], Str[128];
- SendClientMessage(playerid, Default, "VIP's Online:");
- for ( new i = 0; i < GetMaxPlayers(); i++)
- {
- if ( IsPlayerConnected(i) && IsPlayerVIP(i))
- {
- GetPlayerName(i, Name, 24);
- format ( Str, sizeof Str, "[V.I.P]{FFFFFF} %s ID: %d", Name, i);
- SendClientMessage(i, Default, Str);
- }
- }
- return 1;
- }
- ENGINE::IsPlayerVIP(playerid)
- {
- if ( Player[playerid][VIP] == false ) return 0;
- return 1;
- }
- ENGINE::LoadPlayerVIP(playerid)
- {
- new Name[24], dStr[128];
- GetPlayerName(playerid, Name, sizeof Name);
- format ( dStr, sizeof dStr, VIP_USERS, Name);
- if ( !DOF2::FileExists(dStr)) return true;
- Player[playerid][VIP] = true;
- Player[playerid][dExpiration] = DOF2::GetInt(dStr, "Day_Expiration");
- Player[playerid][hExpiration] = DOF2::GetInt(dStr, "Hour_Expiration");
- ShowWelcomeMessage(playerid);
- return true;
- }
- ENGINE::SavePlayerVIP(playerid)
- {
- new Name[24], Str[128];
- GetPlayerName(playerid, Name, 24);
- format ( Str, sizeof Str, VIP_USERS, Name);
- if ( !DOF2::FileExists(Str)) DOF2::CreateFile(Str);
- if ( !DOF2::FileExists(Str)) return printf ( "The VIP file %s not created ( unknown folder )", Name);
- DOF2::SetInt(Str, "Day_Expiration", Player[playerid][dExpiration]);
- DOF2::SetInt(Str, "Hour_Expiration", Player[playerid][hExpiration]);
- DOF2::SaveFile();
- return 1;
- }
- ENGINE::CreateVipKey(playerid, Key[], Days)
- {
- new Str[128];
- format ( Str, sizeof Str, VIP_KEYS, Key);
- if ( DOF2::FileExists(Str))
- {
- new Dayss = DOF2::GetInt(Str, "VIP_Days");
- format ( Str, sizeof Str, "[Erro]{FFFFFF} [ %s ] - [ %d days ]",Key, Dayss);
- SendClientMessage(playerid, Default, "[Erro] {FFFFFF}One similar key exists");
- SendClientMessage(playerid, Default, Str);
- return 1;
- }
- if ( Days <= 0) return SendClientMessage(playerid, Default, "[Erro]{FFFFFF} Impossible perform this operation ");
- DOF2::CreateFile(Str);
- DOF2::SetInt(Str, "VIP_Days", Days);
- DOF2::SaveFile();
- format ( Str, sizeof Str, "[VIP]{FFFFFF} [ %s ] - [ %d days ]", Key, Days);
- SendClientMessage(playerid, Default, "[VIP]{FFFFFF} A new key has been created");
- SendClientMessage(playerid, Default, "[VIP]{FFFFFF} Use /ativarvip");
- SendClientMessage(playerid, Default, Str);
- return 1;
- }
- ENGINE::UseVipKey(playerid, Key[])
- {
- new Str[128];
- format ( Str, sizeof Str, VIP_KEYS, Key);
- if ( !DOF2::FileExists(Str))
- {
- SendClientMessage(playerid, Default, "************************************************");
- SendClientMessage(playerid, Default, " KEY does not exist or has already been used");
- SendClientMessage(playerid, Default, "************************************************");
- return 1;
- }
- new Days = DOF2::GetInt(Str, "VIP_Days");
- SetVipForPlayer(playerid, Days);
- DOF2::RemoveFile(Str);
- new Name[24]; GetPlayerName(playerid, Name, 24);
- printf ("The Player %s used the key %s - %d days", Name, Key, Days);
- return 1;
- }
- ENGINE::RemoveKey(playerid, Key[])
- {
- new Str[128];
- format ( Str, sizeof Str, VIP_KEYS, Key);
- if ( !DOF2::FileExists(Str)) return SendClientMessage(playerid, Default, "unknown key");
- DOF2::RemoveFile(Str);
- format (Str, sizeof Str, "[VIP KEY]{FFFFFF} The Key %s has been removed.", Key);
- SendClientMessage(playerid, Default, Str);
- return 1;
- }
- ENGINE::GetExpirationDays(playerid)
- {
- new Days = 0;
- if ( IsPlayerVIP(playerid))
- {
- Days = Player[playerid][dExpiration] - getdate();
- }
- return Days;
- }
- ENGINE::SetVipForPlayer(playerid, Days)
- {
- if ( !IsPlayerConnected(playerid)) return 1;
- if ( Days == 0 )
- {
- new Nome[24], Str[128];
- GetPlayerName(playerid, Nome, 24);
- format ( Str, sizeof Str, VIP_USERS, Nome);
- DOF2::RemoveFile(Str);
- Player[playerid][VIP] = false;
- SendClientMessage(playerid, Default, "[Vip] {FFFFFF}You VIP has been expired!");
- SendClientMessage(playerid, Default, "[Vip] {FFFFFF}Thanks for your help this server.");
- return 1;
- }
- new Str[128];
- if ( Player[playerid][VIP] == true )
- {
- format ( Str, sizeof Str, "[Vip] {FFFFFF}Your VIP has been renewed. ( %d days )", Days);
- Player[playerid][dExpiration] += Days;
- Player[playerid][hExpiration] = gettime();
- }
- else
- {
- format ( Str, sizeof Str, "[Vip] {FFFFFF}Your VIP has been activated. ( %d days )", Days);
- Player[playerid][dExpiration] = getdate() + Days;
- Player[playerid][hExpiration] = gettime();
- }
- Player[playerid][VIP] = true;
- SavePlayerVIP(playerid);
- SendClientMessage(playerid, Default, "[Vip] {FFFFFF}Thanks for buy VIP");
- SendClientMessage(playerid, Default, "[Vip] {FFFFFF}Use: /viphelp for more informations.");
- SendClientMessage(playerid, Default, Str);
- return 1;
- }
- ENGINE::ShowWelcomeMessage(playerid)
- {
- if ( IsPlayerVIP(playerid))
- {
- if ( VisibleWelcome[playerid] == false )
- {
- DrawWelcome[playerid][0] =TextDrawCreate(579.000000, 301.000000, "_");
- TextDrawBackgroundColor (DrawWelcome[playerid][0], 255);
- TextDrawFont (DrawWelcome[playerid][0], 1);
- TextDrawLetterSize (DrawWelcome[playerid][0], 0.500000, 7.199999);
- TextDrawColor (DrawWelcome[playerid][0], -1);
- TextDrawSetOutline (DrawWelcome[playerid][0], 0);
- TextDrawSetProportional (DrawWelcome[playerid][0], 1);
- TextDrawSetShadow (DrawWelcome[playerid][0], 1);
- TextDrawUseBox (DrawWelcome[playerid][0], 1);
- TextDrawBoxColor (DrawWelcome[playerid][0], -1010580690);
- TextDrawTextSize (DrawWelcome[playerid][0], 433.000000, 0.000000);
- DrawWelcome[playerid][1] =TextDrawCreate(579.000000, 301.000000, "_");
- TextDrawBackgroundColor (DrawWelcome[playerid][1], 255);
- TextDrawFont (DrawWelcome[playerid][1], 1);
- TextDrawLetterSize (DrawWelcome[playerid][1], 0.500000, 0.899999);
- TextDrawColor (DrawWelcome[playerid][1], -1);
- TextDrawSetOutline (DrawWelcome[playerid][1], 0);
- TextDrawSetProportional (DrawWelcome[playerid][1], 1);
- TextDrawSetShadow (DrawWelcome[playerid][1], 1);
- TextDrawUseBox (DrawWelcome[playerid][1], 1);
- TextDrawBoxColor (DrawWelcome[playerid][1], -1010580685);
- TextDrawTextSize (DrawWelcome[playerid][1], 433.000000, 0.000000);
- DrawWelcome[playerid][2] =TextDrawCreate(437.000000, 301.000000, "Welcome");
- TextDrawBackgroundColor (DrawWelcome[playerid][2], -1010580736);
- TextDrawFont (DrawWelcome[playerid][2], 2);
- TextDrawLetterSize (DrawWelcome[playerid][2], 0.159999, 0.899999);
- TextDrawColor (DrawWelcome[playerid][2], -1);
- TextDrawSetOutline (DrawWelcome[playerid][2], 0);
- TextDrawSetProportional (DrawWelcome[playerid][2], 1);
- TextDrawSetShadow (DrawWelcome[playerid][2], 1);
- DrawWelcome[playerid][3] =TextDrawCreate(437.000000, 318.000000, "VIP Activated.");
- TextDrawBackgroundColor (DrawWelcome[playerid][3], -1010580736);
- TextDrawFont (DrawWelcome[playerid][3], 2);
- TextDrawLetterSize (DrawWelcome[playerid][3], 0.149999, 0.799999);
- TextDrawColor (DrawWelcome[playerid][3], -1);
- TextDrawSetOutline (DrawWelcome[playerid][3], 0);
- TextDrawSetProportional (DrawWelcome[playerid][3], 1);
- TextDrawSetShadow (DrawWelcome[playerid][3], 1);
- DrawWelcome[playerid][4] =TextDrawCreate(437.000000, 329.000000, "Use: /viphelp");
- TextDrawBackgroundColor (DrawWelcome[playerid][4], -1010580736);
- TextDrawFont (DrawWelcome[playerid][4], 2);
- TextDrawLetterSize (DrawWelcome[playerid][4], 0.149999, 0.799999);
- TextDrawColor (DrawWelcome[playerid][4], -1);
- TextDrawSetOutline (DrawWelcome[playerid][4], 0);
- TextDrawSetProportional (DrawWelcome[playerid][4], 1);
- TextDrawSetShadow (DrawWelcome[playerid][4], 1);
- DrawWelcome[playerid][5] =TextDrawCreate(437.000000, 356.000000, "Your VIP expire in: ... dias");
- TextDrawBackgroundColor (DrawWelcome[playerid][5], -1010580736);
- TextDrawFont (DrawWelcome[playerid][5], 2);
- TextDrawLetterSize (DrawWelcome[playerid][5], 0.149999, 0.799999);
- TextDrawColor (DrawWelcome[playerid][5], -1);
- TextDrawSetOutline (DrawWelcome[playerid][5], 0);
- TextDrawSetProportional (DrawWelcome[playerid][5], 1);
- TextDrawSetShadow (DrawWelcome[playerid][5], 1);
- new Str[128];
- format ( Str, sizeof Str, "Seu VIP expira em: %d dias.", GetExpirationDays(playerid));
- TextDrawSetString(DrawWelcome[playerid][5], Str);
- for ( new t = 0; t < 6; t++) TextDrawShowForPlayer(playerid, DrawWelcome[playerid][t]);
- VisibleWelcome[playerid] = true;
- TimerDraw[playerid] = SetTimerEx("HiddenWelcome", 6000, false, "i", playerid);
- if ( GetExpirationDays(playerid) < 5)
- {
- format ( Str, sizeof Str, "[Vip] {FFFFFF}Your VIP expire in: %d days", GetExpirationDays(playerid));
- SendClientMessage(playerid, Default, Str);
- }
- }
- }
- }
- Public::HiddenWelcome(playerid)
- {
- if ( VisibleWelcome[playerid] == true )
- {
- for ( new t = 0; t < 6; t++) TextDrawDestroy(DrawWelcome[playerid][t]);
- TimerDraw[playerid] = 0;
- VisibleWelcome[playerid] = false;
- }
- }
- ENGINE::IsNumeric(const string[])
- {
- for (new i = 0, j = strlen(string); i < j; i++)
- {
- if (string[i] > '9' || string[i] < '0') return 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement