Advertisement
Guest User

Untitled

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