Jump to content

Search the Community

Showing results for tags 'tut'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Multi Theft Auto: San Andreas 1.x
    • Support for MTA:SA 1.x
    • User Guides
    • Open Source Contributors
    • Suggestions
    • Ban appeals
  • General MTA
    • News
    • Media
    • Site/Forum/Discord/Mantis/Wiki related
    • MTA Chat
    • Other languages
  • MTA Community
    • Scripting
    • Maps
    • Resources
    • Other Creations & GTA modding
    • Competitive gameplay
    • Servers
  • Other
    • General
    • Multi Theft Auto 0.5r2
    • Third party GTA mods
  • Archive
    • Archived Items
    • Trash

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Gang


Location


Occupation


Interests

Found 3 results

  1. ¿Qué es un callback? Como la palabra en inglés lo indica un callback es una “llamada de vuelta”. Es simple: llamo a una funcion y le envío por parámetro otra función (un callback) esperando que la función que llamé se encargue de ejecutar esa función callback. Concepto de google. Siendo más explicito, es una funcion a la cual le vamos a pasar como parametro otra función, esperando que esta se encargue de ejecutarla. ¿Cuando es necesario usar un callback? Desde mis inicios en MTA hasta en la actualidad no he visto ningún Scripter que haya empleado el uso de un callback, yo me familiarize con este concepto cuando empeze a trabajar con C# y realmente es muy útil para muchas situaciones. Por ejemplo un uso que yo le di en MTA, fue cuando desarrolle un sistema de Ventanas de dialogo para mi sistema de grupos ( basado en el MessageBox de C# ), como parametros a esta funcion para las ventanas de dialogo, fueron 2: Tipo de ventana ( SI/NO, OK, SI/NO/CANCELAR ) Funcion de callback En el primer argumento enviaba el tipo de ventana y en el segundo argumento la funcion a ejecutar como callback, esta funcion iba a ser empleada de tal forma que cuando un jugador de click al boton SI la funcion de callback seria ejecutada enviando parametros adicionales indicando que boton fue clickeado. Ahora les daré un pequeño ejemplo: Crearemos una funcion que se encargará de insertar productos en una Base de datos, la cual queremos que después de ejecutar la sentencia SQL, ejecute otra funcion que imprima un mensaje. local data_base = dbConnect( "sqlite", "sql.db" ) dbFree( dbQuery( data_base, "CREATE TABLE IF NOT EXISTS producto ( codigo STRING, producto STRING, precio INT )" ) ); -- funcion que sera usada para el callback function mensajeDB( text ) outputServerLog(text) end function insertarDatos( cmd, funcion_mensaje ) -- Ejecutamos el código SQL dbExec( data_base, cmd ) -- Luego de esto vamos a ejecutar la funcion enviada para imprimir el mensaje indicando que los datos fueron insertados correctamente funcion_mensaje( "Datos insertados" ); end -- Aqui estamos enviando como primer argumento un codigo SQL para que se inserte en la base de datos -- Como segundo argumento estamos enviado a la funcion mensajeDB que será ejecutada una vez se inserten los datos en la DB. insertarDatos( "INSERT INTO producto( codigo, producto, precio ) VALUES( '00001', 'Computadora', 276.89 )", mensajeDB ) Bien, en la funcion de insertarDatos estamos enviando como primer parametro una sentencia SQL, en el segundo estamos enviando la funcion mensajeDB que se encargaria de imprimir un mensaje en la consola. Cuando usamos esta funcion lo primero que se hizo fue ejecutar la sentencia SQL y luego de esto la funcion que se encargaría de imprimir el mensaje, pero como nos fijamos el segundo argumento de insertarDatos se llama 'funcion_mensaje', la cual estamos ejecutando como una función normal mandando una Cadena de texto como argumento, Esto no afectara en absoluto la función original mensajeDB. Espero haber sido lo más especifico posible intentando explicar el concepto de los callbacks en Lua, puede ser usado en muchos ambitos.. Aparte de yo hacer uso de la misma en un sistema de Ventanas de dialogo, tambien la emplee creando mi propio sistema de eventos el cual dejare como aporte a continuación: --[[ * ******************************************* * * Developed by: -Rex- * * Last modified: - * * Description: * * ******************************************* * ]]-- events = {} events.handled = {}; events.callbacks = { }; function exec_event( event_name, ... ) local arguments = { ... }; arguments.lenght = #arguments; local event_callback = function( event_name, arguments ) for i, _function in ipairs(events.callbacks) do _function( event_name, arguments); end end if( events.handled[event_name] ~= nil ) then event_callback( event_name, arguments ); for i, _functions in ipairs(events.handled[event_name] or { }) do _functions( arguments ); end end end function handle_event( _function, event ) if ( not events.handled[event] ) then events.handled[event] = { }; end local result = false; if not exists_in_table( events.handled[event] ) then table.insert( events.handled[event], _function ) result = true; end if( not result ) then outputDebugString( "Event: [ ".. event .." ] already handled", 3, 255, 0, 0 ); return; end outputDebugString( "Event: [ ".. event .." ] handled", 0, 0, 255, 0 ); end -- //Este funcion se ejecuta cada que sucede un evento y retorna los argumentos del mismo ( En pocas palabras, un delegado ) function add_ecallback( _function ) if not exists_in_table( _function, events.callbacks) then table.insert( events.callbacks, _function ); outputDebugString( debug.getinfo(1,"n").name .." was added to events callback" ); else outputDebugString( debug.getinfo(1,"n").name .." was already been added" ) end end Funciones -- Esta funcion se encarga de añadir un evento. handle_event( _function, event_name ) -- Con esta funcion ejecutaremos un evento y podremos mandar parametros. exec_event ( event_name, ... arguments ) -- Esta funcion se ejecutara cuando cualquier evento añadido se ejecute, enviando a la funcion del callback el nombre del evento y sus argumentos. add_ecallback( _function ) Ejemplo de uso: -- Por ejemplo creamos un evento que notifique cuando se cree un grupo. function create_gp( creador, nombre_grupo, fecha_creacion ) outputChatBox( "El jugador: "..getPlayerName( creador ) .." fundo el grupo: "..nombre_grupo.." a la fecha: "..fecha_creacion, root, 255, 255, 255, true ) end handle_event( "on_player_create_group", create_gp ) -- Aquí ejecutaremos el evento enviando siertos argumentos, por ejemplo: -- El jugador X creo el grupo xNout a la fecha 18/04/2018 15:45 exec_event("on_player_create_group", player, "xNout", "18/04/2018 15:45" ) -- Resultado: --> El jugador: X fundo el grupo: xNout a la fecha: 18/04/2018 15:45 -- Cada vez que se cree un grupo el evento será ejecutado enviando todos los parametros que se le den.
  2. Hey guys. I found a video on YouTube (in German, sorry) that shows you how to install MTA syntax highlighting and autocomplete for Notepad++. You don't have to watch the video, but there are links in the video description (which I'll leave here) that leads to a forum and in there will be a download link (which I'll also leave here) for installing to Notepad++. And the reason why I'm recommending this version is because for whatever odd reason, JR10's way of doing it doesn't really come out the way I'd like it to be. Problems such as 'function' turn to white and MTA functions are blue and also everything is in a thinner font which is hard to read, so I don't like that. So with this version, things like function names are highlighted in red, it's the same font thickness, and all the up to date functions are also highlighted. If you don't like the autocomplete, just go to Settings > Preferences > Auto-Completion > and uncheck 'Enable auto-completion on each input'. And that's pretty much it. Hope it makes things a lot easier for you. https://www.youtube.com/watch?v=tyXEm--h3EU https://www.mta-sa.org/thread/4117-1-3-5-1-4-lua-mta-erweiterung-für-notepad/?pageNo=9 https://www.mta-sa.org/attachment/2508-1-5-1-lua-mta-erweiterung-für-notepad-zip/
  3. السلام عليكم ورحمة الله وبركاتة الكثير كان يبحث عن برنامج الـ MTA Editor اللي كان يدعمة ويبرمجة @50p لكنة الان توقف عن دعم البرنامج بسبب الاخطاء والمشاكل اللي واجهها فية هذا البرنامج اللي اسمة Sublime Text 3 نفس الـ Notepad+ لكن 50p مسوي اضافة عليه بحيث ضايف جميع وظائف الام تي اي في الـ LUA وان ماكانت جميعها فـ اغلبها طريقة التثبيت : قم بتحميل Sublime Text 3 من هنا : https://www.sublimetext.com/3 وبعد تحميل البرنامج وتثبيتة اتبع هذه الارشادات للتثبيت اضافة لغه LUA + MTA Functions : https://dl.dropboxusercontent.com/u/4370616/mtatools/SublimeText/50pMTAEditor.zip قم بتحميل الملف التالي بعد تثبيت البرنامج السابق : بعد تحميل الملف اذهب الى المسار التالي : C:\Users\\AppData\Roaming\Sublime Text 3\Packages\User\ 50pMTAEditor قم بانشاء مجلد جديد باسم 50pMTAEditor.zip استخرج محتويات هذا الملف في المجلد الذي قمت بانشائة في الخطوة السابقة قم بتشغيل برنامج Sublime Text 3 قم بانشاء ملف جديد File > New هذه الخطوة ضرورية بعد استخراج محتويات المجلد المضغوط للتحقق من عمل الصيغه والوظائف مع البرنامج بعد ذلك اذهب الى الاعلى في الخيارات واتبع الاتي view > syntax > LUA(MTA:SA) لتحديد الالوان الخاصة بالوظائف مثل الكلنت سايد والسيرفر سايد والمشتركة اتبع الآتي Preferences > Color Scheme > User > 50pMTAEditor > Monokai-MTA-Edit وهنا تكون انتهيت من تثبيت البرنامج والساينتكس الخاصة بلغة لوا ووظائف ام تي اي --------------------------------------------------------------------------------------- تنبية ** NOTE : قد يكون هناك مشكلة في مسار الملف التالي : C:\Users\\AppData\Roaming\Sublime Text 3\Packages\User\ لذلك عندما تذهب للمسار قد لايكون هناك المجلد User اذا لم تجد المجلد قم بانشاء مجلد جديد بالاسم User وقم بانشاء المجلد الذي في الخطوة رقم 3 داخل المجلد الجديد الذي انشئتة وهو User --------------------------------------------------------------------------------------- ماهي الفائدة من عمل هذه الطريقة؟ هذه الطريقة استعملها شخصياً في برمجة المودات وكتابة السكربتات والاكواد تسهل عملية كتابة الكود والوظائف تضع لك الوظائف بالارقمنت الخاص بها عند كتابة اول حرف ستظهر لك الوظائف بشكل مرتب وتدريجي في الايديتور اتمنى للجميع التوفيق واللي تحصل معه مشكلة يطرحها وبساعدة في تثبيت البرنامج واضافة 50p جميع حقوق الاضافة تعود لـ 50p والسلام عليكم ورحمة الله وبركاتة
×
×
  • Create New...