Guest User

Untitled

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