Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI\y_ini>
- #include <zcmd>
- #include <YSI\y_inline>
- #define Callback:%0(%1) forward %0(%1); public %0(%1)
- #define DIALOGO_REGISTRO (1)
- #define DIALOGO_INGRESO (2)
- #define DIALOGO_NORMAL (3)
- #define rutaUsuarios "/Cuentas/%s.ini"
- #define blanco "{FDFDFE}"
- #define azul "{0256FD}"
- #define verde "{06FA1F}"
- #define rojo "{FF0000}"
- enum datosdeUsuario
- {
- cLlave[34],
- cDinero,
- cAsesinatos,
- cMuertes,
- invisible,
- score,
- cAdmin,
- cVip,
- cRegistrado
- }
- new cuentas[MAX_PLAYERS][datosdeUsuario];
- new pColor;
- main(){}
- public OnGameModeInit()
- {
- if(!fexist("/cuentas"))
- {
- printf("El directorio \"cuentass\" de Scriptfiles no existe, debe crearla antes de prender el servidor.");
- SendRconCommand("exit");
- }
- else
- {
- printf("cuentas cargadas correctamente.");
- }
- return 1;
- }
- public OnGameModeExit()
- {
- for(new i=0;i<MAX_PLAYERS;i++)
- {
- if(IsPlayerConnected(i) && fexist(Checarcuentas(i)))
- {
- Guardarcuentas(i);
- SendClientMessageEx(-1,-1,"Las cuentass fueron guardadas correctamente.");
- printf("cuentass guardadas correctamente.");
- }
- }
- y_inline();
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- ReiniciarDatos(playerid);
- if(fexist(Checarcuentas(playerid)))
- {
- INI_ParseFile(Checarcuentas(playerid),"LoadUser_%s",.bExtra = true, .extra = playerid);
- ShowPlayerDialog(playerid,DIALOGO_INGRESO,DIALOG_STYLE_PASSWORD,"{FFFFFF}Inicio de sesion","{FFFFFF}Escribe en el siguiente campo tu contraseña para poder iniciar sesion.","Aceptar","");
- }
- else
- {
- ShowPlayerDialog(playerid,DIALOGO_REGISTRO,DIALOG_STYLE_INPUT,"{FFFFFF}Registro de cuentas","{FFFFFF}Escriba la contraseña que desea para registrar su cuentas.","Aceptar","");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- if(fexist(Checarcuentas(playerid)))
- {
- Guardarcuentas(playerid);
- SendClientMessage(playerid,-1,"Sus datos fueron guardados.");
- printf("La cuenta \"%s\" fue guardada correctamente.",Nombre(playerid));
- }
- return 1;
- }
- public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
- {
- if(dialogid == DIALOGO_REGISTRO)
- {
- if(!response)return SetTimerEx("KickearJugador",1000,false,"i",playerid) && ShowPlayerDialog(playerid,DIALOGO_NORMAL,DIALOG_STYLE_MSGBOX,"{FFFFFF}Expulsado","{FFFFFF}Fuistes expulsado por evadir el Registro.","Aceptar","");
- if(response)
- {
- if(!strlen(inputtext))return ShowPlayerDialog(playerid,DIALOGO_REGISTRO,DIALOG_STYLE_INPUT,"{FFFFFF}Registro de cuentas","{FFFFFF}Escriba la contraseña que desea para registrar su cuentas.","Aceptar","");
- new pw[34];
- format(pw,sizeof(pw),"%s",inputtext);
- cuentas[playerid][cLlave] = pw;
- new INI:File = INI_Open(Checarcuentas(playerid));
- INI_SetTag(File,"data");
- INI_WriteString(File,"Contraseña",inputtext);
- INI_Close(File);
- cuentas[playerid][cAdmin] = 0;
- cuentas[playerid][cVip] = 0;
- cuentas[playerid][cDinero] = 0;
- cuentas[playerid][cRegistrado] = 1;
- SendClientMessageEx(playerid,-1,"%s ahora estas registrado en el servidor.",Nombre(playerid));
- }
- }
- if(dialogid == DIALOGO_INGRESO)
- {
- if(!response)return SetTimerEx("KickearJugador",1000,false,"i",playerid) && ShowPlayerDialog(playerid,DIALOGO_NORMAL,DIALOG_STYLE_MSGBOX,"{FFFFFF}Expulsado","{FFFFFF}Fuistes expulsado por intentar evadir contraseña.","Aceptar","");
- if(response)
- {
- if(strcmp(inputtext,cuentas[playerid][cLlave], true) == 0)
- {
- INI_ParseFile(Checarcuentas(playerid),"LoadUser_%s",.bExtra = true, .extra = playerid);
- SendClientMessage(playerid,-1,"Has ingresado a tu cuentas correctamente.");
- }
- else return SetTimerEx("KickearJugador",1000,false,"i",playerid) && ShowPlayerDialog(playerid,DIALOGO_NORMAL,DIALOG_STYLE_MSGBOX,"{FFFFFF}Expulsado","{FFFFFF}Fuistes expulsado por ingresar una contraseña incorrecta.","Aceptar","");
- }
- }
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if(GetPlayerMoney(playerid) != cuentas[playerid][cDinero])
- {
- ResetPlayerMoney(playerid);
- GivePlayerMoney(playerid,cuentas[playerid][cDinero]);
- }
- if(GetPlayerScore(playerid) != cuentas[playerid][score])
- {
- SetPlayerScore(playerid,cuentas[playerid][score]);
- }
- return 1;
- }
- Callback:LoadUser_data(playerid,name[],value[])
- {
- INI_String("Contraseña",cuentas[playerid][cLlave],34);
- INI_Int("Dinero",cuentas[playerid][cDinero]);
- INI_Int("Asesinatos",cuentas[playerid][cAsesinatos]);
- INI_Int("Muertes",cuentas[playerid][cMuertes]);
- INI_Int("Admin",cuentas[playerid][cAdmin]);
- INI_Int("Vip",cuentas[playerid][cVip]);
- return 1;
- }
- Callback:KickearJugador(playerid)
- {
- Kick(playerid);
- return 1;
- }
- stock Nombre(playerid)
- {
- new uNombre[32];
- GetPlayerName(playerid,uNombre,100);
- return uNombre;
- }
- stock Checarcuentas(playerid)
- {
- new cuenta[146];
- format(cuenta,sizeof(cuenta),rutaUsuarios,Nombre(playerid));
- return cuenta;
- }
- stock Guardarcuentas(playerid)
- {
- new INI:File = INI_Open(Checarcuentas(playerid));
- INI_SetTag(File,"data");
- INI_WriteString(File,"Contraseña",cuentas[playerid][cLlave]);
- INI_WriteInt(File,"Dinero",cuentas[playerid][cDinero]);
- INI_WriteInt(File,"Asesinatos",cuentas[playerid][cAsesinatos]);
- INI_WriteInt(File,"Muertes",cuentas[playerid][cMuertes]);
- INI_WriteInt(File,"Admin",cuentas[playerid][cAdmin]);
- INI_WriteInt(File,"Vip",cuentas[playerid][cVip]);
- INI_WriteInt(File,"Registrado",cuentas[playerid][cRegistrado]);
- INI_Close(File);
- }
- stock ReiniciarDatos(playerid)
- {
- cuentas[playerid][cDinero] = 0;
- cuentas[playerid][cAsesinatos] = 0;
- cuentas[playerid][cMuertes] = 0;
- cuentas[playerid][cAdmin] = 0;
- cuentas[playerid][cVip] = 0;
- cuentas[playerid][cRegistrado] = 0;
- }
- CMD:invisible(playerid, params[])
- {
- if(cuentas[playerid][invisible] == 1)
- {
- return SendClientMessage(playerid, -1,""rojo"» "blanco"Ya estas en modo invisible.");
- }
- pColor = GetPlayerColor(playerid);
- SetPlayerColor(playerid, 0xFFFFFF00);
- GameTextForPlayer(playerid, "~g~Invisible",3000,3);
- cuentas[playerid][invisible] = 1;
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- LinkVehicleToInterior(GetPlayerVehicleID(playerid),GetPlayerInterior(playerid));
- }
- return 1;
- }
- CMD:visible(playerid, params[])
- {
- if(cuentas[playerid][invisible] == 0)
- {
- return SendClientMessage(playerid, -1,""rojo"» "blanco"Ya estas en modo visible.");
- }
- SetPlayerColor(playerid, pColor);
- GameTextForPlayer(playerid, "~b~Visible",3000,3);
- cuentas[playerid][invisible] = 0;
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- LinkVehicleToInterior(GetPlayerVehicleID(playerid),GetPlayerInterior(playerid));
- }
- return 1;
- }
- CMD:darvida(playerid, params[])
- {
- if(! esadmin(playerid, 2)) return 1;
- new player1, Float:vida;
- if(CheckSplit(params, "uf", player1, vida))
- {
- return SendClientMessage(playerid, -1, "» "verde"Modo de uso: "blanco"/DARVIDA [ID] [CANTIDAD DE VIDA]") &&
- SendClientMessage(playerid, -1, "» "verde"Funcion: "blanco"Brindar vida a un jugador especifico.");
- }
- if(! checarconeccion(playerid, player1)) return 1;
- if(! checarnivel(playerid, player1)) return 1;
- SendClientMessageEx(playerid,-1,"» "azul"Fijaste la vida de %s a %02.f.", Nombre(player1), vida);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(player1 != playerid)
- {
- SendClientMessageEx(player1,-1,"» "verde"El administrador %s fijo tu vida en: "blanco"%02.f"verde".", Nombre(playerid), vida);
- PlayerPlaySound(player1,1057,0.0,0.0,0.0);
- }
- SetPlayerHealth(player1, vida);
- return 1;
- }
- CMD:fijarscore(playerid, params[])
- {
- if(! esadmin(playerid, 3)) return 1;
- new player1;
- if(CheckSplit(params, "ud", player1, score))
- {
- return SendClientMessage(playerid, -1, "» "verde"Modo de uso: "blanco"/FIJARSCORE [ID] [CANTIDAD SCORE]") &&
- SendClientMessage(playerid, -1, "» "verde"Funcion: "blanco"Fijar el score a un jugador especifico.");
- }
- if(! checarconeccion(playerid, player1)) return 1;
- if(! checarnivel(playerid, player1)) return 1;
- SendClientMessageEx(playerid,-1,"» "azul"Fijaste el score de %s en %d.",Nombre(player1),score);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(player1 != playerid)
- {
- SendClientMessageEx(player1,-1,"» "verde"El administrador %s fijo tu score en: "blanco"%d"verde".", Nombre(playerid), score);
- PlayerPlaySound(player1,1057,0.0,0.0,0.0);
- }
- cuentas[player1][score] = score;
- SetPlayerScore(player1,cuentas[player1][score]);
- return 1;
- }
- CMD:darskin(playerid, params[])
- {
- if(! esadmin(playerid, 3)) return 1;
- new player1, skin;
- if(CheckSplit(params, "ud", player1, skin))
- {
- return SendClientMessage(playerid, -1, "» "verde"Modo de uso: "blanco"/DARSKIN [ID] [ID DE SKIN]") &&
- SendClientMessage(playerid, -1,"» "verde"Funcion: "blanco"Cambiar el skin a un jugador especifico.");
- }
- if(! checarconeccion(playerid, player1)) return 1;
- if(! checarnivel(playerid, player1)) return 1;
- if(skin < 0 || skin > 299)
- {
- return SendClientMessage(playerid, -1, ""rojo"» "blanco"ID de Skin invalido (0-299).");
- }
- SendClientMessageEx(playerid,-1,"» "azul"Fijaste el skin de %s a %d.", Nombre(player1), skin);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(player1 != playerid)
- {
- SendClientMessageEx(player1,-1,"» "verde"El administrador %s cambio tu skin por el skin ID: "blanco"%d"verde".", Nombre(playerid), skin);
- PlayerPlaySound(player1,1057,0.0,0.0,0.0);
- }
- SetPlayerSkin(player1, skin);
- return 1;
- }
- CMD:darchaleco(playerid, params[])
- {
- if(! esadmin(playerid, 2)) return 1;
- new player1, Float:chaleco;
- if(CheckSplit(params, "uf", player1, chaleco))
- {
- return SendClientMessage(playerid, -1, "» "verde"Modo de uso: "blanco"/DARCHALECO [ID] [CANTIDAD DE CHALECO]") &&
- SendClientMessage(playerid, -1, "» "verde"Funcion: "blanco"Brindar armadura a un jugador especifico.");
- }
- if(! checarconeccion(playerid, player1)) return 1;
- if(! checarnivel(playerid, player1)) return 1;
- SendClientMessageEx(playerid,-1,"» "azul"Fijaste el chaleco de %s a %02.f.", Nombre(player1), chaleco);
- PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
- if(player1 != playerid)
- {
- SendClientMessageEx(player1,-1,"» "verde"El administrador %s fijo tu chaleco en: "blanco"%02.f"verde".", Nombre(playerid), chaleco);
- PlayerPlaySound(player1,1057,0.0,0.0,0.0);
- }
- SetPlayerArmour(player1, chaleco);
- return 1;
- }
- CMD:ip(playerid, params[])
- {
- if(! esadmin(playerid, 1)) return 1;
- new player1;
- if(CheckSplit(params, "u", player1))
- {
- return SendClientMessage(playerid, -1, "» "verde"Modo de uso: "blanco"/IP [ID]") &&
- SendClientMessage(playerid, -1, "» "verde"Funcion: "blanco"Ver la IP de un jugador.");
- }
- if(! checarconeccion(playerid, player1)) return 1;
- if(! checarnivel(playerid, player1)) return 1;
- new tmp3[50];
- GetPlayerIp(player1,tmp3,50);
- SendClientMessageEx(playerid,-1,"» "verde"Nombre: "blanco"%s "verde"IP: "blanco"%s.", Nombre(player1), tmp3);
- return 1;
- }
- stock checarconeccion(playerid, playerid2)
- {
- if(! IsPlayerConnected(playerid2))
- {
- SendClientMessage(playerid,-1,""rojo"» "blanco"No esta conectado.");
- return 0;
- }
- return 1;
- }
- stock esadmin(playerid, level)
- {
- if(IsPlayerAdmin(playerid)) return 1;
- if(cuentas[playerid][cAdmin] < level)
- {
- SendClientMessage(playerid,-1,""rojo"» "blanco"No eres administrador.");
- return 0;
- }
- return 1;
- }
- stock checarnivel(playerid, playerid2)
- {
- if(cuentas[playerid][cAdmin] < cuentas[playerid2][cAdmin])
- {
- SendClientMessage(playerid,-1,""rojo"» "blanco"El jugador especificado posee mayor nivel que tu.");
- return 0;
- }
- return 1;
- }
- stock CheckSplit(string[], format[], {Float,_}:...)
- {
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'f':
- {
- setarg(paramPos, 0, _:floatstr(string[stringPos]));
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- ie = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- ie = (ie * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(ie))
- {
- setarg(paramPos, 0, ie);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- ie = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, ie))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
- SendClientMessageEx(const iPlayer, const iColor, const szFormat[], { Float, _ }: ...)
- {
- new iArgs = (numargs() - 3) << 2;
- if(iArgs)
- {
- static s_szBuf[144], s_iAddr1, s_iAddr2;
- #emit ADDR.PRI szFormat
- #emit STOR.PRI s_iAddr1
- for(s_iAddr2 = s_iAddr1 + iArgs, iArgs += 12; s_iAddr2 != s_iAddr1; s_iAddr2 -= 4)
- {
- #emit LOAD.PRI s_iAddr2
- #emit LOAD.I
- #emit PUSH.PRI
- }
- #emit CONST.PRI s_szBuf
- #emit PUSH.S szFormat
- #emit PUSH.C 144
- #emit PUSH.PRI
- #emit PUSH.S iArgs
- #emit SYSREQ.C format
- #emit LCTRL 4
- #emit LOAD.S.ALT iArgs
- #emit ADD.C 4
- #emit ADD
- #emit SCTRL 4
- return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, s_szBuf) : SendClientMessageToAll(iColor, s_szBuf);
- }
- return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, szFormat) : SendClientMessageToAll(iColor, szFormat);
- }
Advertisement
Add Comment
Please, Sign In to add comment