CeKiT Posted February 15, 2012 Posted February 15, 2012 hola amigos, alguien que me pase un resourse o me enseñe a elavorar un resourse de mensajes random osea q cada "x" cantidad de minutos diga un mensaje! Gracias espero que me ayuden!
Krujitoz Posted February 15, 2012 Posted February 15, 2012 https://community.multitheftauto.com/index.php?p= ... ils&id=186
diegofkda Posted February 15, 2012 Posted February 15, 2012 Primero, debes crear un timer de... pongamosle de 30 segundos. Llevaríamos esto: setTimer ( function () end, 30000, 0 ) --0 de interminable, y 30000 de 30000 milisegundos Ahora, entre function () y end (que es donde decimos 'dentro de la función' obtenemos un numero al azar, usaríamos math.random, al cual se le asignan 2 valores dependiendo de la cantidad de mensajes que quieras poner, en este caso pondremos solo 2. setTimer ( function () numeroAlAzar = math.random ( 1, 2 ) --Declararemos numeroAlAzar, el cual sera el numero que obtendremos, seleccionará un numero al azar entre uno y dos end, 30000, 0 ) Ahora, tendremos que verificar si numeroAlAzar es uno o dos: if numeroAlAzar == 1 then--si el numero fue 1 entonces outputChatBox ( "hola" )--poner hola en el chat elseif numeroAlAzar == 2 then--en cambio si fue 2 entonces outputChatBox ( "chao" )--poner "chao" en el chat end Entonces el script sería así: setTimer ( function () numeroAlAzar = math.random ( 1, 2 ) --Declararemos numeroAlAzar, el cual sera el numero que obtendremos, seleccionará un numero al azar entre uno y dos if numeroAlAzar == 1 then--si el numero fue 1 entonces outputChatBox ( "hola" )--poner hola en el chat elseif numeroAlAzar == 2 then--en cambio si fue 2 entonces outputChatBox ( "chao" )--poner chao en el chat end end, 30000, 0 ) Cambias el valor de math.random dependiendo de los mensajes que quieras poner, y vas poniendo elseif por los mensajes que quieras poner, si hay alguna duda no tengas miedo en preguntar .
CeKiT Posted February 15, 2012 Author Posted February 15, 2012 Tengo otro problema al agregar mas mensajes mira el codigo es asi: setTimer ( function () numeroAlAzar = math.random ( 1, 2, 3, 4 ) -- Al azar , elige los mensajes ! if numeroAlAzar == 1 then--Este es el 1 outputChatBox ( "#FFFFFF Nuevo en el Server? #00FFFF Lee las /Reglas", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 2 then--Este es el 2 outputChatBox ( "#FFFFFF Abuser o Chater? #00FFFF Usa /Report", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 3 then--Este es el 3 outputChatBox ( "#FFFFFF Visita el Foro! #00FFFF GTAChile.com", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 4 then--Este es el 4 outputChatBox ( "#FFFFFF Admins Online? #00FFFF Usa /Admins", getRootElement(), 255, 0, 0, true ) end end, 30000, 0 ) Q es lo que balla?? Como agrego otros, msj? Gracias
Danii Posted February 15, 2012 Posted February 15, 2012 setTimer ( function () numeroAlAzar = math.random ( 1, 4 ) -- Al azar , elige los mensajes ! if numeroAlAzar == 1 then--Este es el 1 outputChatBox ( "#FFFFFF Nuevo en el Server? #00FFFF Lee las /Reglas", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 2 then--Este es el 2 outputChatBox ( "#FFFFFF Abuser o Chater? #00FFFF Usa /Report", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 3 then--Este es el 3 outputChatBox ( "#FFFFFF Visita el Foro! #00FFFF GTAChile.com", getRootElement(), 255, 0, 0, true ) elseif numeroAlAzar == 4 then--Este es el 4 outputChatBox ( "#FFFFFF Admins Online? #00FFFF Usa /Admins", getRootElement(), 255, 0, 0, true ) end end, 30000, 0 ) Para agregar mas mensajes esta bien lo que isistes, si agregas un 5 mensaje cambia el número: math.random ( 1, 5 )
Castillo Posted February 15, 2012 Posted February 15, 2012 Tambien podrias usar una tabla y hacerlo mucho mas facil. local mensajes = { "#FFFFFF Nuevo en el Server? #00FFFF Lee las /Reglas", "#FFFFFF Abuser o Chater? #00FFFF Usa /Report", "#FFFFFF Visita el Foro! #00FFFF GTAChile.com", "#FFFFFF Admins Online? #00FFFF Usa /Admins", } setTimer ( function () local numeroAlAzar = math.random ( #mensajes ) -- Al azar, elige los mensajes de la tabla. local mensaje = mensajes[numeroAlAzar] -- Sacamos el mensaje de la tabla con el numero. outputChatBox ( mensaje, getRootElement(), 255, 0, 0, true ) end ,30000, 0 )
diegofkda Posted February 16, 2012 Posted February 16, 2012 Es nuevo, supongo que tiene que aprender también.
Recommended Posts