Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/10/19 in all areas

  1. 2 points
  2. 2 points
  3. Introduction Hello, So I have decided I should make this tutorial about how to use CEF alongside RAGEMP to make interactable UI because I have spent some time understanding it from examples without a clear tutorial, I am going to explain how to interact between the CEF browsers and RAGEMP client, and how to send/receive information from and to server. This tutorial is targeting new comers in RAGEMP but who have background in scripting and know how to run and connect their server locally. So the main points will be: 1-What is CEF 2-Sending information from CEF to RAGEMP client (and vice versa) 3-Sending information from RAGEMP to The Server (and vice versa) (I will be using C# Bridge API for working with the serverside scripting) Before we start you are going to need the following to better understand the tutorial: Basic knowledge in HTML, CSS and JavaScript (Optional – Nice to have) Bootstrap and JQuery Let’s start! What is CEF CEF is abbreviation to Chromium Embedded Framework an open source framework that allow the ability to embed HTML webpages into applications. RAGEMP already integrates the CEF so you don’t have to download anything externally to begin using it. CEF and RAGEMP Client So now we are going to learn how to create a browser inside the RAGEMP client and interact with it. I am going to teach by giving example, it is going to be a basic login/register system. First download or or create your own webpage design, If you don't know how to create a webpage just use my sample (Attached to this thread) and follow the tutorial. Start by going to RAGEMP/server-files/client_packages folder and create a new folder name it “Login” then inside the Login folder we’ve just created place the HTML,CSS and JS files that is related to the webpage inside and then create the (clientside) script we will call it “Main.js” that will be the main connecting point between the CEF browser, client and the server. NOTE: In the Login folder you are going to place the webpage files and all dependences such as Bootstrap or JQuery libraries. So to this point you should’ve something similar to this Dependences folder contains the minified JQuery and Bootstrap libraries, Links below: https://getbootstrap.com/docs/3.3/getting-started/ https://code.jquery.com/jquery-3.3.1.min.js/ So I have pre-made this simple page for the sake of this tutorial, I will link download to all of the files that I have used at the bottom of this thread. But you can go with any page design you like. Disclaimer: I am new to web development so it may not look that good but it does the job. Now we need to interact with this page, Inside the Login.html (assuming you already have made/imported a page) find the main components that you want to interact with and give them the ‘id’ attribute, in my case I need the buttons and text input elements, image below for more understanding Also notice how we referenced the “Login.js” script. We are going to use these inside our “Login.js” file, so Open the Login.js file and write the following: (Code is written using JQuery) $('#loginButton').click(() => { mp.trigger('loginInformationToServer', $('#loginUsernameText').val(), $('#loginPasswordText').val()); }); $('#registerButton').click(() => { mp.trigger('registerInformationToServer', $('#registerUsernameText').val(), $('#registerPasswordText').val()); }); So what this basically does is once the loginButton/registerButton is clicked is going to trigger (mp.trigger) an event with the given name and pass the values inside the text fields as arguments, that later we are going to catch that in our “Main.js” script. (This point is where we send information from CEF Browser to RAGEMP Client). Now that we have send the information and they are waiting to be caught, But before we do that we are going to show the browser window when a player connect to our server. Open “Main.js” and use mp.browsers.new(‘package://path’); In our case: we have the html page inside our Login folder. var loginBrowser = mp.browsers.new('package://Login/Login.html'); Now at this point when the player connects to our server this will show him our page that we’ve just made, it is still not functional yet until we catch the information that we’ve sent before. Let’s catch them now, inside the “Main.js” add the following: mp.events.add('loginInformationToServer', (username, password) => { mp.events.callRemote('OnPlayerLoginAttempt', username, password); }); mp.events.add('registerInformationToServer', (username, password) => { mp.events.callRemote('OnPlayerRegisterAttempt', username, password); }); I am not going to go into much details here on the syntax but what we are doing is catching the 'loginInformationToServer' and 'registerInformationToServer' events (like you’d do in any other client event in ragemp) and sending them directly to the server to verify the information passed. But before we forget go back to the client_packages folder and create or open the file ‘index.js’ and place require('./Login/Main.js'); to let the server know that this file contains JavaScript codes that related to RAGEMP client (mp.events.add, mp.events.callRemote and mp.browsers.new), a complete list found on ragemp wiki https://wiki.rage.mp/index.php?title=Client-side_functions RAGEMP Client and RAGEMP Server Now that we have sent the information from the CEF client to the RAGEMP client, and then to the RAGEMP server via (mp.events.callRemote) we didn’t catch the event on the server yet, so let’s go ahead and do that. It can be done in same ways but different syntax depending on which programming language you are using, I am going to be using C# because I am more familiar with but it can be easily done with JS serverside once you are familiar with scripting in it. So go ahead and inside any resource file that you are using type the following: [RemoteEvent("OnPlayerLoginAttempt")] public void OnPlayerLoginAttempt(Client player, string username, string password) { NAPI.Util.ConsoleOutput($"[Login Attempt] Username {username} | Password: {password}"); if(username == "Max" && password == "123") { player.TriggerEvent("LoginResult", 1); } else player.TriggerEvent("LoginResult", 0); } So The above code catch the event that is triggered when player sends the information to the server so we validate them then send back a response to the client with either success or fail depending on the player data, in ideal case we should check the information from a database but that’s out of the scope for this tutorial so I am just checking if his username is Max and password is 123 then we send information back to the client with result 1 (success) else we send the result of 0 (incorrect username/password) Same thing apply for the register event handle. Now you can notice a pattern here is that whenever we send an event from one place to another we need to catch it, so back to the “Main.js” and let’s handle the response sent from the server, Add the following: mp.events.add('LoginResult', (result) => { if (result == 1) { //Success we destroy the loginBrowser as we don't need it anymore loginBrowser.destroy(); mp.gui.cursor.show(false, false); mp.gui.chat.push("You have successfully logged in."); } else { //Failed we just send a message to the player saying he provided incorrect info //Here you can be creative and handle it visually in your webpage by using the (browser).execute or loginBrowser.execute in our case to execute a js code in your webpage mp.gui.chat.push('Incorrect password or username.'); } }); Similar to what we did when we caught function from CEF we did for catching from server and we checked if the value passed is 1 then the player succeeds in logging in else he fails. Now you can just run your server and connect with your client and you should see the login page appear, enter anything and hit login - it should message Then try using the combinations of Max and 123 and you should see and the window should disappear. Same practice apply to the register I will leave it for you to practice and try to implement that by yourself! Good luck! Summary Important things to remember: - From CEF browser to RAGEMP client => mp.trigger caught by mp.events.add - From RAGEMP client to RAGEMP server (C#) => mp.events.callRemote caught by [RemoteEvent()] flag and a function Now the other way around: - From RAGEMP server (C#) to RAGEMP client => (Client).TriggerEvent caught by mp.events.add - From RAGEMP client to CEF browser => (Browser).execute For more information about the syntax for these you can check the ragemp wiki NOTE: Sometimes you don’t need to send anything to the server, For example a browser that contains information about your server, you just need to contact between CEF and RAGEMP client. NOTE: Similarly if you want to use JavaScript for serverside scripting you can find the equivalent to my functions used and do the same, however everything done in clientside scripts (Main.js) should remain the same for both languages!! The End And here you’ve just completed the tutorial! Thanks for taking your time to read and if you have faced any problems or any question post a comment below and I will do my best to answer it. Also feel free to correct me if there is any suggestions or any syntax/logical errors. Happy coding! Files used in this tutorial: https://www.solidfiles.com/v/nYR8xn43j57jv
    1 point
  4. Version 1.0.1

    1699 downloads

    This is a Vehicleseat Menu in JavaScript for Rage:MP Install: Unzip vehicleseatJS.zip in your root server folder. Use: Press "F" or "G" when a Vehicle nearby you. Contact: You can Contact me on Discord for Questions. {Brace}#0571 Have fun!
    1 point
  5. Version 1.0.1

    572 downloads

    (EN) This script allow you to play emergency alert sound (2 sounds: tornado siren, alert siren), coming soon: amber alert with sound&pop-up (FR) Ce script vous permet de déclencher des sirènes d'alertes (sirène tornade, sirène d'alerte), à venir: alerte enlèvement avec son&popup ----- HOW TO INSTALL ----- 1) Unpack RAGEMP Alert v0.1 2) Drop the content of "client_packages" folder inside your client folder 3) Drop the content of "packages" folder inside your server folder 4) Add in your server index.js : require('./Alert/sAlert'); 5) Add in your client index.js : require('./Alert/cAlert'); 6) Do not forget to change link of mp.browsers.new in Alert/cAlert.js if needed ----- HOW TO USE ----- /alert tornado {repeat time} --> {repeat time} FROM 1 TO 9 TIMES Duration: EACH time: 9sec (min: 9sec, max: 81sec) /alert siren {repeat time} --> {repeat time} FROM 1 TO 9 Duration: START: 5sec / ACTIVE: 12sec (repeat from 1 to 9) / END: 13sec (min: 30sec, max: 126sec) /alert siren stop --> stop the siren immediatly if activated (duration: 13sec) ----- DEMO ----- Tornado Siren: Alert siren: Amber alert (coming soon):
    1 point
  6. Version 2.1

    708 downloads

    With this script you can easily create custom timer. The file is fully commented and should be easy to understand. The file in Shared is required - and then use either the file in Server or in Client depending on where you are using it. You have to use the constructor to create the timer. Examples: Examples: // Yes, the method can be private // private void testTimerFunc(Client player, string text) { NAPI.Chat.SendChatMessageToPlayer(player, "[TIMER] " + text); } void testTimerFunc() { NAPI.Chat.SendChatMessageToAll("[TIMER2] Hello"); } [Command("ttimer")] public void timerTesting(Client player) { // Lamda for parameter // new Timer(() => testTimerFunc(player, "hi"), 1000, 1); // Normal without parameters // new Timer(testTimerFunc, 1000, 1); // Without existing method // var timer = new Timer(() => { NAPI.Chat.SendChatMessageToPlayer(player, "[TIMER3] Bonus is da best"); }, 1000, 0); // Kill the timer // timer.Kill(); }
    1 point
  7. Personally, I'm running MongoDB & Mongoose for my server's data. I've used it for web projects in the past, and it tends to be the first thing I reach for to manage persistent data. I don't think it's a bad choice for your server's data. MongoDB could be considered overkill for a project at the scale of a RageMP gamemode, since some of its features are mainly targeted for scaling a large app, but I dont think there's any harm in using it. If you haven't used it before and aren't familiar with it, but do have experience with SQL databases, then something like PostgreSQL with Sequelize might be a better choice in terms of getting things done faster. If you want to learn MongoDB just to build that knowledge for use in other areas outside of RageMP, then I think a RageMP server is as good a place as any to learn about it.
    1 point
  8. До этого все было нормально, сегодня проснулся открыл Ragemp а там это, пробовал перезапускать и все такое, не помогло. скрин --> https://imgur.com/a/fIuafRK
    1 point
  9. Упал мастерлист, проблема глобальная. Сейчас уже исправили.
    1 point
  10. Тоже самое,только я эту проблему решил.А теперь у меня при заходе и заполнение логина и пароля пишет (Слишком быстро!) чток чему...
    1 point
  11. #Push Wir sind weiterhin auf der Suche nach Frontend Entwickler Gamedesigner ( Mapping) Grafikdesigner Backend Entwickler Genauere Infos , wie immer per Discord (Fanb0ii#2879)( oder auf unseren Discord ( https://discord.gg/FS5bnEV ) oder hier im RageMP Forum per PN Liebe Grüße Das Team von Innovation-Life
    1 point
  12. #Push Wir sind weiterhin auf der Suche nach Frontend Entwickler Gamedesigner ( Mapping) Grafikdesigner Backend Entwickler Genauere Infos , wie immer per Discord (Fanb0ii#2879)( oder auf unseren Discord ( https://discord.gg/FS5bnEV ) oder hier im RageMP Forum per PN Liebe Grüße Das Team von Innovation-Life
    1 point
  13. Version 1.0.0

    1233 downloads

    Requirements You need to download & install these resources first: NativeUI Efficient Attachment Sync Currency API (after installing, define a currency named cash) Installing Put the files you downloaded in their respective places Set up some businesses and products (read below) All done Basically This script adds factories and buyers which sell and buy products, your job is to buy stuff from factories and sell them to buyers for profit. Commands /products: Accesses a vehicle's product inventory, you have to be at the back of the vehicle. /takeproduct: Takes a product from the ground/factory. /dropproduct: Drops a product from your hands to the ground/buyer. JSON Files Most of the changes are done by editing JSON files located in packages/courier/json/. Remember to validate your changes here: https://jsonlint.com/ config.json businessWorkInterval: Interval of the business work timer (used for factories to make product and buyers to sell product), default value is 60000. worldCleanerInterval: Interval of the world cleaner timer (used for removing dropped products), default value is 60000. droppedProductLife: Milliseconds a dropped product will stay for, default value is 600000. dropProductOnDeath: If true, dying will cause players to drop the product they're carrying, default value is true. dropProductOnDisconnect: If true, leaving the server will cause the players to drop the product they're carrying, default value is true. vehicles.json This file contains an object that keeps which vehicles are supported by this script in modelName: capacity format. (Vehicles List) { "burrito3": 6, // 6 products for burrito3 "rumpo": 6, // 6 products for rumpo "speedo": 4, // 4 products for speedo "youga": 4 // 4 products for youga } products.json This file contains the product information in object of objects format. A product has name, model, price, profit, businessTime, attachOffset and attachRotation properties. name: The product's visible name. model: Model name of the product, used for dropping and attaching. price: Price of the product. profit: Profit rate of the product. Price is multiplied by this value while selling products to a buyer. businessTime: Milliseconds it takes for a factory to create one of this product/for a buyer to sell one of this product. attachOffset: Attachment offset of the product model on player. attachRotation: Attachment rotation of the product model on player. // Example: Ammunition product "ammo": { "name": "Ammunition", "model": "gr_prop_gr_bulletscrate_01a", "price": 300, "profit": 1.2, "businessTime": 600000, "attachOffset": { "x": 0, "y": -0.18, "z": -0.18 }, "attachRotation": { "x": 0, "y": 0, "z": 0 } } businesses.json This file contains business information in array of objects format. A business has type, productType, initialStock, maxStock and position properties. type: Business type, only factory and buyer are available. productType: The product this business is interested in, only the values in products.json are available. initialStock: How much product this business has on server start. maxStock: Maximum product this business can have. position: Location of the business. // Example: Beer Factory & Buyer used in the video [ { "type": "factory", "productType": "beer", "initialStock": 100, "maxStock": 100, "position": { "x": 4.168992519378662, "y": 12.795921325683594, "z": 69.82928466796875 } }, { "type": "buyer", "productType": "beer", "initialStock": 0, "maxStock": 20, "position": { "x": 29.61789321899414, "y": 5.448328018188477, "z": 69.10714721679688 } } ] businessTypes.json This file contains business type information in object of objects format. You probably don't need to make any changes to this file, unless you want to add new business types. (which needs some scripting as well) A business type has label and blipSprite properties. label: Visible name, used for blip name and label. blipSprite: Blip sprite of the business type. (Blip Sprite List) // Example: Default business types { "factory": { "label": "Factory", "blipSprite": 615 }, "buyer": { "label": "Buyer", "blipSprite": 616 } } Extensions This script extends mp.Player and mp.Vehicle. Player Functions // Returns true if the player is carrying a product. player.isCarryingProduct(); // Returns the type of product the player is carrying, will be null if the player isn't carrying anything. player.getCarryingProduct(); // Makes the player start carrying a product. Type should be a valid product type and the player shouldn't be carrying a product, or it won't work. player.startCarryingProduct(type); // Makes the player stop carrying a product. player.stopCarryingProduct(); Vehicle Functions IMPORTANT: Vehicles with models that are in vehicles.json automatically get an inventory when entityCreated event is called, so you don't need to use setProductInventory for them. (Unless you want to be 100% sure they have it) // Sets the product inventory of a vehicle. newInventory must be an array created by the array constructor like "new Array(8)". vehicle.setProductInventory(newInventory); // Returns true if the vehicle has a product inventory. vehicle.hasProductInventory(); // Returns the product inventory of the vehicle, will be null if the vehicle doesn't have one. vehicle.getProductInventory(); // Adds a product to the vehicle product inventory, index must not have an item already and index must be within the bounds of product inventory array. Returns true if successful, false otherwise. vehicle.giveProduct(index, productType); // Returns the product at the specified index of vehicle product inventory, will be null if index doesn't have a product. vehicle.getProduct(index); // Removes the product at the specified index of vehicle product inventory. Returns true if successful, false otherwise. vehicle.removeProduct(index); Source code is available on GitHub in case you don't want to download: https://github.com/root-cause/ragemp-courier
    1 point
  14. Removed outdated guide.
    1 point
×
×
  • Create New...