Guest User

asdasd

a guest
May 2nd, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.24 KB | None | 0 0
  1. /*
  2.  
  3. Gamemode RP creado desde cero - tutorial by Aldys
  4.  
  5. */
  6.  
  7. // - Includes
  8. #include <a_samp>//El include nativo..
  9. #include <YSI\y_ini>//si no tienen este include, pueden descargarlo, es facil de encontrar.
  10. #include <YSI\y_commands>//es mejor que zcmd y es igual
  11. #include <sscanf2>//para hacer comandos con parametros, osea espacios
  12. #include <foreach>// es mejor que el de antes y esta integrado a YSI
  13.  
  14.  
  15. // - IDS Dialogs
  16. #define Registro 0
  17. #define Ingreso 1
  18. #define SSexo 2
  19. #define SEdad 3
  20.  
  21. // - Colores
  22. #define AZUL 0x0000FFFF// todos los colores, los pueden hacer ustedes xD
  23. #define AMARILLO 0xFFFF00FF
  24. #define ROJO 0xFF0000FF
  25. #define VERDE 0x00FF00FF
  26. #define BLANCO 0x00000000
  27. #define NEGRO 0x000000FF
  28. #define GRIS_CLARO 0x00000029
  29. #define Hablar 0xE6E6E6E6//el color que aparece l hablar. Entre mas lejos estas, se ve mas negro
  30. #define Hablar2 0xC8C8C8C8
  31. #define Hablar3 0xAAAAAAAA
  32. #define Hablar4 0x8C8C8C8C
  33. #define Hablar5 0x6E6E6E6E
  34.  
  35. // - Otros
  36. #define Hospital 1178.4025,-1323.0923,14.1183//define las coordenadas del hospital, para donde spawnear cuando moris
  37. #pragma tabsize 0 //quita el famoso "loose identification"
  38. #define Carpeta_Usuarios "Usuarios"//en qué carpeta se guardarán los usuarios, el archivo .ini
  39. #define alm(%0,%1) strmid(%0,%1,0,strlen(%1),strlen(%1)+1)//este es un macro que hize para que sea mas rapido almacenar en strings
  40. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  41. #define NombreJ(%0) Nombre[%0]
  42. // - news
  43. new
  44.    bool:Logueado[MAX_PLAYERS],//Se activará al loguear
  45.    BigEar[MAX_PLAYERS],//es una variable del proxdetector
  46.    Nombre[MAX_PLAYERS][MAX_PLAYER_NAME];//aquí almacenaremos el nombre del jugador.
  47.    new PTuto[MAX_PLAYERS];
  48.  
  49. // - forwards
  50. forward ActualizarCuenta(playerid);//esta callback creada por nosotros, es para que sea mas facil editar el registro/actualización de cuentas
  51. forward Cargar_data(playerid,name[],value[]);//esta callback permite cargar los datos del jugador creados en el archivo INI
  52. forward CargarCuenta(playerid); // le dará el dinero, el nivel y demás..
  53. forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);//proxdetector, es para que solo usuarios cercanos lean algo...
  54. forward Tuto(playerid);
  55. // - Enums
  56. enum Info
  57. {
  58.    Contra[32],
  59.    bool:Tutorial, //almacenará true o false, nada más.
  60.    Dinero,
  61.    Nivel,
  62.    Sexo,
  63.    Edad, // Faltaba esta coma
  64.    Faccion,
  65.    Admin
  66. }; // Y aquí punto y coma
  67.  
  68. new Informacion[MAX_PLAYERS][Info];
  69.  
  70. public OnGameModeInit()
  71. {
  72.     SetGameModeText("El mode");//el mode del SV
  73.     SendRconCommand("hostname GM de 0");//el nombre del SV
  74.     SendRconCommand("mapname el map");//nombre del map
  75.     ManualVehicleEngineAndLights();//esto hara que, al subir a un auto, no se prenda el motor y otras cosas
  76.     ShowPlayerMarkers(0);//esto hara que los jugadores no aparescan en el mapa
  77.     DisableInteriorEnterExits();//borra las entradas/interiores por defecto
  78.     return 1;
  79. }
  80.  
  81. public OnPlayerText(playerid, text[])
  82. {
  83.     new string[128];//los maximos caracteres , tamaño del array, permitidos de cuando hablas, en mi caso 128 porque es la máxima entrada del chatbox
  84.     format(string, sizeof(string), "%s dice: %s",NombreJ(playerid), text);
  85.     ProxDetector(10.0, playerid, string,Hablar,Hablar2,Hablar3,Hablar4,Hablar5);
  86.     return 0;
  87. }
  88.  
  89. public OnPlayerSpawn(playerid)
  90. {
  91.     SetPlayerPos(playerid,1560.3490,-1627.1450,13.5469);//para que le de alguna posicion al entrar
  92.     if(!Logueado[playerid]) return SendClientMessage(playerid,-1,"Logueate mediante el dialogo");//Esto hace que por algun bug, el jugador no pueda entrar sin hacerlo mediante el registro a dialog
  93.     if(!Informacion[playerid][Tutorial])//si todabia no paso el tutorial
  94.     TogglePlayerControllable(playerid,false);//congela al jugador
  95.     SetPlayerPos(playerid,1560.3490,-1627.1450,13.5469);
  96.     ShowPlayerDialog(playerid,SSexo,DIALOG_STYLE_MSGBOX,"{FFFFFF}Seleccionar Sexo","{00FFCC}¿Que Sexo Eres, Masculino o Femenino?","Masculino","Femenino");
  97.     return 1;
  98. }
  99.  
  100. public OnPlayerRequestSpawn(playerid)//esto es muy importante, sirve para que si ponen el boton spawn, no pase nada no spawnee..
  101. {
  102.     return 0;//si ponen 1, el boton spawn va a funcionar y se van a cagar buegeando :/
  103. }
  104.  
  105. public OnPlayerConnect(playerid)
  106. {
  107.     //almacenar nombre
  108.     GetPlayerName(playerid,Nombre[playerid],24);
  109.     //resetear variables
  110.     Logueado[playerid] = false;
  111.     BigEar[playerid] = 0;
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerRequestClass(playerid, classid)
  116. {
  117.     if (!fexist(UbicacionArchivo(playerid)))//chequeas si el archivo existe
  118.     {
  119.         ShowPlayerDialog(playerid, Registro, DIALOG_STYLE_INPUT, "Registro", "Coloque su contraseña para crear su cuenta", "Registrar", "Cancelar");//el dialogo para un usuario nuevo
  120.     }
  121.     else
  122.     {
  123.         INI_ParseFile(UbicacionArchivo(playerid), "Cargar_%s", .bExtra = true, .extra = playerid);//almacena los datos del jugador en su respectivo array, según el archivo a checkear. (.Extra: destino del array)
  124.         ShowPlayerDialog(playerid, Ingreso, DIALOG_STYLE_INPUT, "Ingreso", "Coloque su contraseña para ingresar", "Conectar", "Cancelar");//el dialogo, de cuando ya estas registrado
  125.     }
  126.     //aca pueden poner una camara, para que quede mas lindo
  127.     return 1;
  128. }
  129.  
  130. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  131. {
  132.    //Usaremos switch para mejor procesamiento
  133.     switch(dialogid)
  134.     {
  135.         case Registro:
  136.         {
  137.             if (!strlen(inputtext) || strlen(inputtext) > 32) return ShowPlayerDialog(playerid, Registro, DIALOG_STYLE_INPUT, "Registro", "Mínimo 1 caracter, máximo 32 caracteres", "Continuar", "Salir");//si no introduce ningun texto, el dialogo reaparece
  138.             if (!response) return Kick(playerid);//si pone "cancelar" lo kickea
  139.             alm(Informacion[playerid][Contra],inputtext);
  140.             SetPlayerScore(playerid,1);
  141.             ShowPlayerDialog(playerid, Ingreso, DIALOG_STYLE_INPUT, "Ingreso", "Ingrese su contraseña nuevamente, para ingresar", "Confirmar", "Salir");
  142.             ActualizarCuenta(playerid);
  143.         }
  144.         case Ingreso:
  145.         {  
  146.             if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Ingreso, DIALOG_STYLE_INPUT, "Ingreso", "Por Favor, ingrese alguna contraseña", "Aceptar", "Salir");
  147.             if (!response) return Kick(playerid);//si pone cancelar, lo kickea
  148.             if (!strcmp(inputtext,Informacion[playerid][Contra]))//comparamos las dos strings
  149.             {
  150.                 Logueado[playerid] = true;
  151.                 CargarCuenta(playerid);//carga la cuenta(definiremos esta función más abajo)
  152.             }
  153.             else
  154.             {
  155.                 ShowPlayerDialog(playerid, 100, DIALOG_STYLE_MSGBOX, "Error", "Su contraseña no coincide con su nombre", "Aceptar", "");
  156.                 Kick(playerid);
  157.             }
  158.             return 1;
  159.         }
  160.         case SSexo:
  161.         {
  162.             if(!response)
  163.             {
  164.                 SetPlayerSkin(playerid,93);
  165.                 Informacion[playerid][Sexo] = 2;
  166.             }
  167.             else
  168.             {
  169.                 SetPlayerSkin(playerid,26);
  170.                 Informacion[playerid][Sexo] = 1;
  171.             }
  172.              ShowPlayerDialog(playerid, SEdad, DIALOG_STYLE_INPUT, "Edad", "Escriba solo el número, su edad:", "Seleccionar", "");
  173.         }
  174.         case SEdad:
  175.         {
  176.             if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid, SEdad, DIALOG_STYLE_INPUT, "Edad", "Escriba solo el número, su edad:", "Seleccionar", "");
  177.             if(strval(inputtext) < 18 || strval(inputtext) > 80) ShowPlayerDialog(playerid, SEdad, DIALOG_STYLE_INPUT, "Edad", "Máximo 80, mínimo 18", "Seleccionar", "");
  178.             Informacion[playerid][Edad] = strval(inputtext);
  179.             GameTextForPlayer(playerid,"~w~Registro finalizado.\nPara pasar de pagina precione ~g~ENTER",2000,3);
  180.             SendClientMessage(playerid,-1,"TUTORIAL");
  181.             SendClientMessage(playerid,-1,"Ahora, verá un pequeño tutorial sobre este modo de juego");//modifiquen el tutorial..
  182.             SendClientMessage(playerid,-1,"...");//modifiquen el tutorial..
  183.             SendClientMessage(playerid,-1,"...");//modifiquen el tutorial..
  184.             SendClientMessage(playerid,-1,"...");//modifiquen el tutorial..
  185.             PTuto[playerid] = 1;//activa la variable pTuto
  186.         }
  187.     }
  188.    return 1;
  189. }
  190. public OnPlayerDisconnect(playerid,reason)//este callback hace que al desconectarse, guarde los datos del jugador
  191. {
  192.     if(Logueado[playerid]) ActualizarCuenta(playerid);//actualiza el ini, SOLO si está logueado.
  193.     return 1;
  194. }
  195.  
  196. public OnGameModeExit()
  197. {
  198.     foreach(Player,i)
  199.     {
  200.         if(Logueado[i])
  201.         {
  202.             ActualizarCuenta(i);
  203.         }
  204.     }
  205.     return 1;
  206. }
  207.  
  208. //Este stock retorna el nombre de un jugador.
  209. /*stock NombreJ(playerid)
  210. {
  211.     return Nombre[playerid];
  212. }*/
  213.  
  214. //Este stock retorna la ubicacion del archivo de un jugador.
  215. stock UbicacionArchivo(playerid)
  216. {
  217.     new Ubic[MAX_PLAYER_NAME + 20];
  218.     format(Ubic,sizeof Ubic,""#Carpeta_Usuarios"/%s.ini",NombreJ(playerid));
  219.     return Ubic;
  220. }
  221. stock IsNumeric(string[])
  222. {
  223.     for (new i = 0, j = strlen(string); i < j; i++)
  224.     {
  225.         if (string[i] > '9' || string[i] < '0') return 0;
  226.     }
  227.     return 1;
  228. }
  229. //- Callbacks
  230. public ActualizarCuenta(playerid)
  231. {
  232.     new INI:Arch = INI_Open(UbicacionArchivo(playerid));
  233.     INI_SetTag(Arch,"data");
  234.     INI_WriteString(Arch,"Contraseña",Informacion[playerid][Contra]);
  235.     INI_WriteBool(Arch,"Tutorial",Informacion[playerid][Tutorial]);
  236.     INI_WriteInt(Arch,"Dinero",GetPlayerMoney(playerid));
  237.     INI_WriteInt(Arch,"Nivel",GetPlayerScore(playerid));
  238.     INI_WriteInt(Arch,"Sexo",Informacion[playerid][Sexo]);
  239.     INI_WriteInt(Arch,"Edad",Informacion[playerid][Edad]);
  240.     INI_WriteInt(Arch,"Admin",Informacion[playerid][Admin]);
  241.     INI_WriteInt(Arch,"Faccion",Informacion[playerid][Faccion]);
  242.     INI_Close(Arch); //guarda y actualiza el archivo ini
  243.     return 1;
  244. }
  245.  
  246. public Cargar_data(playerid,name[],value[])
  247. {
  248.     INI_String("Contraseña",Informacion[playerid][Contra],32);
  249.     INI_Bool("Tutorial", Informacion[playerid][Tutorial]);
  250.     INI_Int("Dinero",Informacion[playerid][Dinero]);
  251.     INI_Int("Nivel",Informacion[playerid][Nivel]);
  252.     INI_Int("Sexo",Informacion[playerid][Sexo]);
  253.     INI_Int("Edad",Informacion[playerid][Edad]);
  254.     INI_Int("Admin",Informacion[playerid][Admin]);
  255.     INI_Int("Faccion",Informacion[playerid][Faccion]);
  256.     return 1;
  257. }
  258.  
  259. public CargarCuenta(playerid)
  260. {
  261.     SpawnPlayer(playerid);
  262.     SetPlayerScore(playerid,Informacion[playerid][Nivel]);
  263.     GivePlayerMoney(playerid,Informacion[playerid][Dinero]);
  264.     return 1;
  265. }
  266.  
  267. public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
  268. {
  269.     if(IsPlayerConnected(playerid))
  270.     {
  271.         new Float:posx, Float:posy, Float:posz;
  272.         new Float:oldposx, Float:oldposy, Float:oldposz;
  273.         new Float:tempposx, Float:tempposy, Float:tempposz;
  274.         GetPlayerPos(playerid, oldposx, oldposy, oldposz);
  275.         foreach(Player,i)//cambiamos el loop a foreach
  276.         {
  277.             if(GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i))
  278.             {
  279.                 if(!BigEar[i])
  280.                 {
  281.                     GetPlayerPos(i, posx, posy, posz);
  282.                     tempposx = (oldposx -posx);
  283.                     tempposy = (oldposy -posy);
  284.                     tempposz = (oldposz -posz);
  285.                     if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
  286.                     {  
  287.                         SendClientMessage(i, col1, string);
  288.                     }
  289.                     else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
  290.                     {
  291.                         SendClientMessage(i, col2, string);
  292.                     }
  293.                     else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
  294.                     {
  295.                         SendClientMessage(i, col3, string);
  296.                     }
  297.                     else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
  298.                     {
  299.                         SendClientMessage(i, col4, string);
  300.                     }
  301.                     else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  302.                     {
  303.                         SendClientMessage(i, col5, string);
  304.                     }
  305.                 }
  306.                 else
  307.                 {
  308.                     SendClientMessage(i, col1, string);
  309.                 }
  310.             }
  311.         }
  312.     }
  313.     return 1;
  314. }
  315. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  316. {
  317.     if(PTuto[playerid] >= 1)
  318.     {
  319.         if(newkeys == KEY_SECONDARY_ATTACK)
  320.         {
  321.             Tuto(playerid);
  322.             return 1;
  323.         }
  324.         return 1;
  325.     }
  326.     return 0;
  327. }
  328.  
  329. public Tuto(playerid)
  330. {
  331.     switch(PTuto[playerid])
  332.     {
  333.         case 1:
  334.         {
  335.             SendClientMessage(playerid,-1,"LSPD");
  336.             SendClientMessage(playerid,-1,"se encarga de x cosa");
  337.         }
  338.         case 2:
  339.         {
  340.             SendClientMessage(playerid,-1,"FBI");
  341.             SendClientMessage(playerid,-1,"se encarga de x cosa");
  342.             PTuto[playerid] ++;
  343.         }
  344.         case 3:
  345.         {
  346.             SendClientMessage(playerid,-1,"Tal faccion");
  347.             SendClientMessage(playerid,-1,"se encarga de x cosa");
  348.         }//pueden crear mas partes, yo les doy un elemplo, recuerden que deben poner la variable PTuto con ++, eso hara que se le valla sumando el valor
  349.         case 4:
  350.         {
  351.             SendClientMessage(playerid,-1,"Fin del tutorial");
  352.             SendClientMessage(playerid,-1,"gracias por leerlo");
  353.         }
  354.     }
  355.     ++PTuto[playerid];
  356.     if(PTuto[playerid] >= 4)//cuando termine el tutorial
  357.     {
  358.         Informacion[playerid][Tutorial] = true;
  359.         TogglePlayerControllable(playerid,1);
  360.         PTuto[playerid] = 0;
  361.     }
  362.     return 1;
  363. }
  364.  
  365. public OnPlayerCommandReceived(playerid, cmdtext[])
  366. {
  367.     // esto lo puedes utilizar para muchas cosas como por ejemplo hacer que en la consola aparesca el mensaje que escribiste
  368.     new string[80];
  369.     format(string, sizeof(string), "* %s (ID:%d) has typed: %s", NombreJ(playerid), playerid, cmdtext);
  370.     printf("[Command] %s: %s", NombreJ(playerid), cmdtext); // imprime el comando que escribiste en la consola!
  371.     return 1;
  372. }
  373.  
  374. public OnPlayerCommandPerformed(playerid, cmdtext[], success)
  375. {
  376.     if(!success)
  377.     {
  378.         //lo que quieres que pase si el comando no existe, por ejemplo: SendClientMessage(playerid, 0xFFFFFFFF, "Comando desconocido.");
  379.         return 1;
  380.     }
  381.     return 1;
  382. }
  383.  
  384. //Comandos para admins
  385. CMD:darlider(playerid, params[])
  386. {
  387.     new ID,FACCION;
  388.     if(Informacion[playerid][Admin] < 4) return SendClientMessage(playerid,-1,"No es admin nivel 4!");//el nivel admin desde que lo pueden usar
  389.     if(sscanf(params, "ud", ID,FACCION) )return SendClientMessage(playerid,-1,"Uso: /darfaccion [ID] [FACCION]");//los parametros del comando
  390.     if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,-1,"Jugador o conectado/ID incorrecta");
  391.     Informacion[ID][Faccion] = FACCION;
  392.     return 1;
  393. }
  394.  
  395. CMD:daradmin(playerid, params[])
  396. {
  397.     new ID,ADMIN;
  398.     if(Informacion[playerid][Admin] < 10) return SendClientMessage(playerid,-1,"No es admin nivel 10!");//el nivel admin desde que lo pueden usar
  399.     if(sscanf(params, "ud", ID,ADMIN) )return SendClientMessage(playerid,-1,"Uso: /daradmin [ID] [ADMLEVEL]");
  400.     if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,-1,"Jugador o conectado/ID incorrecta");
  401.     {
  402.        Informacion[ID][Admin] = ADMIN;
  403.        return 1;
  404.     }
  405. }
  406.  
  407. CMD:dardinero(playerid, params[])
  408. {
  409.     new ID,PLATA;
  410.     if(Informacion[playerid][Admin] < 10) return SendClientMessage(playerid,-1,"No es admin nivel 10!");//el nivel admin desde que lo pueden usar
  411.     if(sscanf(params, "ud", ID,PLATA) )return SendClientMessage(playerid,-1,"Uso: /dardinero [ID] [DINERO]");
  412.     if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,-1,"Jugador o conectado/ID incorrecta");
  413.     Informacion[ID][Dinero] = PLATA;
  414.     GivePlayerMoney(ID,PLATA);
  415.     return 1;
  416. }
Advertisement
Add Comment
Please, Sign In to add comment