Leaderboard
Popular Content
Showing content with the highest reputation on 03/05/19 in all areas
-
Hello everyone! Many of you have decided to use Entity Framework instead of raw SQL but failed somehow in the process (myself included)! This is why I am creating this quick guide with some examples on how to use Entity Framework Core with MySQL database in RAGEMP C# gamemode. It's not perfect, but it will work just fine. If you find a mistake or have a better way of doing something, please let me know! Let's start! Requirements: - Visual Studio 17 or better - Net Core 2.2 - RageMP C# 0.3.7 - MySQL database (I use XAMPP) 1. First, you will need some dependencies. Open up the nuget package manager and add these dependencies to your project: Microsoft.EntityFrameworkCore - Version 2.2.0 Microsoft.EntityFrameworkCore.Tools - Version 2.2.0 Pomelo.EntityFrameworkCore.MySql - Version 2.1.4 Pomelo.EntityFrameworkCore.MySql.Design - Version 1.1.2 Pomelo.EntityFrameworkCore.MySql is a MySQL provider. There are many more providers, but Pomelo's is just fine. How it looks when everything's added: NOTE: As of writing this, you have to use exactly those versions I had screenshot above! 2. Now we are ready to create a DbContext class. I will just copy and paste and explain needed with comments! using System; using System.Collections.Generic; using System.Reflection; using System.Text; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; namespace EFCoreTutorial { public class DefaultDbContext : DbContext { // Connection string, more details below private const string connectionString = "Server=localhost;Database=efcoretutorial;Uid=root;Pwd="; // Initialize a new MySQL connection with the given connection parameters protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseMySql(connectionString); } // Account model class created somewhere else public DbSet<Account> Accounts { get; set; } } } Server = the address of the server, in this case localhost Database = name of the database Uid = user accessing the database Pwd = database password, leave empty if none 3. Create a model class, in this case it's called Account using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text; namespace EFCoreTutorial { public class Account { [Key] public int Id { get; set; } public string Username { get; set; } public string Password { get; set; } } } 4. Let's make a simple registration command. using System; using System.Collections.Generic; using System.Linq; using System.Text; using GTANetworkAPI; namespace EFCoreTutorial { public class Commands : Script { [Command("register")] public void AccountCmdRegister(Client player, string username, string password) { RegisterAccount(player, username, password); NAPI.Chat.SendChatMessageToPlayer(player, "~g~Registration successful!"); } public static void RegisterAccount(Client client, string username, string password) { // create a new Account object var account = new Account { Username = username, Password = password }; // When created like this, the context will be immediately deleted AKA disposed. // This will make sure you don't have slowdowns with database calls if one day your server becomes popular using (var dbContext = new DefaultDbContext()) { // Add this account data to the current context dbContext.Accounts.Add(account); // And finally insert the data into the database dbContext.SaveChanges(); } } } } 4a. To check if you are properly connected to the database without going into the game, make a query when a resource starts, for example: using System; using System.Collections.Generic; using System.Linq; using System.Text; using GTANetworkAPI; namespace EFCoreTutorial { public class Main : Script { [ServerEvent(Event.ResourceStart)] public void OnResourceStart() { using (var dbContext = new DefaultDbContext()) { var playerCount = dbContext.Accounts.Count(); NAPI.Util.ConsoleOutput("Total players in the database: " + playerCount); } } } } 5. Before we can test the command or the above example, we need to make a migration. Manual migrations are the only way as of EF Core. To use them in our gamemodes which are most often only libraries (.dlls), we need to "trick the system" into thinking our gamemode is executable. The easiest way is to "create" a console application. First, open your project properties, ALT + F7. Change output type to "Console Application" Save with CTRL + S! Create a new class called Program.cs with the code below: using System; using System.Collections.Generic; using System.Text; namespace EFCoreTutorial { public class Program { public static void Main(string[] args) { } } } Yes, that's right. You only need the Main method. It's because the console app approach looks for "Main" as a starting point. Save and build the project! Now let's make the first migration. Open up the Package Manager Console and type "add-migration FirstMigration" (FirstMigration is only the name). After the migration class has been created, type once again into the console "update-database". The very first migration is now added and inside your database you will find Accounts table: Note: If there are any errors by this stage, then you are most likely not connected to your Database. This guide will not cover that! 6. We are almost done. For server to properly work, it will need runtime dlls. When you first start RAGEMP client, you will download some runtime files. Those are not enough and you have to take some extra steps. Go to the "RAGEMP" root folder, then "dotnet" folder and copy everything. Paste it inside the "runtime" folder (RAGEMP\server-files\bridge\runtime). When you build your project, it will also give you runtime files. Copy everything from bin/debug/netcoreapp2.2 (default build path) except Bootstrapper.dll , Newtonsoft.Json.dll and everything that starts with YourProjectName (EFCoreTutorial in my case). Paste it once again inside the "runtime" folder (RAGEMP\server-files\bridge\runtime). Finally, open YourProjectName.csproj with notepad and add this line <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> like so: Save and close. 7. You are all set up! From now on you don't have to worry about missing runtimes, errors and whatnot. This is everything Entity Framework Core requires to work properly in RAGEMP. Changelog: - Added appsettings.json, a better way of handling connection strings. Thanks @horseyhorsey! - Some clarification - Cleaned and updated the code per @Adam's suggestion This was my first tutorial/guide. Leave feedback and opinions. Thank you for reading! xForcer1 point
-
With a lot of people with very potential projects presented a lot of quality mapping, I'm a bit late to introducing this but in this tutorial, I'll basically be showing off how to get your mapping into your server through means of it being client-sided. (Which I'd consider as far as displaying mapping goes instead of getting them through .jsons ala server-sided.) What you'll need. 1. First you're gonna need to gather all the tools needed to bring a mapping over to your RageMP server. I made a special folder for this tutorial. 2. Okay so here's the two .xml maps both exported from Map Editor. (But you can export it from Menyoo too) 3. So what we're gonna do next is open up ME2YM (Ymap converter) and try to convert it over. 4. When you got it opened up, goto File > Open. Then navigate your mapping, I will be bringing in my examples I got from GTA 5 Mods. (There's two of them, but I RECOMMEND you importing ONE at a time and converting them ONE AT A TIME.) 5. After getting your mapping in ME2YM, goto File > Export. And export your mapping anywhere you like. I'll be exporting mine in the same folder for the sake of the tutorial. (Again, LOOK back at number 4. ONLY import and export ONE mapping at a time.) 6. Since there's two mappings, I'll basically be doing steps 4 and 5 again for the other one. Simple. 7. After you've gotten those converted over, you're done with ME2YM! Open up OpenIV and navigate to your mapping dlcpack base by going to File > Open folder. (In this case, if you downloaded my base, find "mapname") 8. You should see the dlc archive itself when opening up the dlcpack. Open it up and go all the way to the "custom_maps" .rpf archive. 9. Import the .ymap mappings through openFormats. 10. Extract the custom_maps.rpf anywhere after importing your .ymap mappings, then DELETE the .rpf archive inside OpenIV after extracting it. 11. Next we're gonna be affixing that .rpf archive. Locate ArchiveFix and where you placed your custom_maps.rpf then drag the .rpf archive onto the ArchiveFix icon. ...and you should get this. Don't panic. It means you did something right... 12. Re-add/Import that archive back into OpenIV in the same place where you deleted it from. 13. Exit OpenIV, then locate your mapping base dlc archive. (If you're using mapname, it'll be in mapname..) 14. Drag that .rpf archive into ArchiveFix like custom_maps. 15. Then finally, go into your server's files and into client_resources. Then drop your mapping dlcpack base (or mapname) into dlcpack. (Make a dlcpack folder inside client_resources if you haven't made one.) 16. Either copy it to your client_resources as well or be lazy and just hop in game to let the server download it for you. (If you let the server download it, restart your game and client after downloading it from the server.) 17. Your mapping should be in the server for you and anyone else who joins! (Granted they download the resources too from the server..)1 point
-
Hi This is my Beeker's/LS Customs mod for GTA. This is a work in progress. I intend to make this a humble little car parts trading mod. I'm happy to share this development with the community, especially the add-on car .rpf's. I'll keep the list growing as I add to my collection. Until I get the frameworks complete, use the commands: ## Mod the vehicle you are currently in. ## X = mod index, Y = mod /mod X Y ## Change the color of your car ## X = primary color, Y = secondary color /color X Y ## Chang your license plate ## X = alphanumeric string to display on license plate /licenseplate X Vehicle Colors Vehicle Mods Open Source RP Compatible The project is compatible with Open Source Role Play with some additions to the cMisc.js file. Special Eclipse Public License This mod is free to use with special provisions. Please familiarize yourself with the LICENSE as it is essential to understanding how this mod may be used. Install Download To install on your copy of Open Source RP just drop the files into their respective folders: Place the contents of dlcpacks into your client_packages/dlcpacks/ Place packages/Auto-Shop into your packages/ Place app/client/Business/cAutoShop.js into your app/client/Business/ Place app/client/Browsers/Business/AutoShop into your app/client/Browsers/Business/ Add the following to app/client/index.js require('./Business/cAutoShop'); Add this smarter camera function to app/client/cMisc.js // POINTED CAMERA // function createPointedCam(x, y, z, rx, ry, rz, viewangle, px, py, pz) { camera = mp.cameras.new("Cam", {x, y, z}, {x: rx, y: ry, z: rz}, viewangle); camera.setActive(true); camera.pointAtCoord(px, py, pz) mp.game.cam.renderScriptCams(true, true, 20000000000000000000000000, false, false); } exports.createPointedCam = createPointedCam; Add-on Car List Garage Bay Framework The shop menu is accessed from the manager's desk. The available menu depends on which garage bay is occupied by a car. At it's current state, if both bays are occupied the available menu will represent the last bay to become occupied. In the future, an option for both bays will be accessible from the manager's desk. Mods as Items Framework This garage mod focuses on addon vehicles that have unique "vehiclemods" .rpf packs. The vehicle mods applied are custom made to their real life counterpart. Each individual mod is it's own object within an array that represents the vehicle. This data is currently stored in the vue.js data object. It will need to be refactored into Vue components as the intended library of cars gets added. m3f80: [ { local: "spoiler", index: 0, mod: 2, item: "GT Universal Racing Spoiler" }, { local: "spoiler", index: 0, mod: 1, item: "VIE Rear Lip Spoiler" } ] The model of your vehicle is identified by the server when entering the designated garage bay. The model ID transfers into the vue.js data object. While we have your model ID we can tell you if there are mods available for that model of car. <div v-if="model === 3714356651"> <div v-for="product in m3f80" class="applyMod"> <div>{{ product.local }}</div> <div>{{ product.index }}</div> <div>{{ product.mod }}</div> <div>{{ product.item }}</div> </div> </div> The BMW has 19 different mods available The Impala shows 29 items available here but I didn't even scratch the surface on it. This thing has 16 different steering wheels not in the array yet. TODO: Make the UI pretty and function as a shopping cart... then work on the paint bay.1 point
-
Worked for me. Was looking for exactely that. Thanks for the effort!1 point
-
Помогите пожалуйста, запускаю мультиплеер и он сразу закрывается! Что делать помогите, уже все испробовала, перезапускала комп, переустанавливала мультиплеер несколько раз, визуалы переустанавливала все, меняла файлы1 point
-
1 point
-
1 point
-
1 point
-
0 points
