RDR2 (RedM) Script Development C# - E1 - Setup & Coding Our First Resource

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so I don't know about you guys but I've been having a lot of fun with Red Dead - so we've been doing five em development and what's pretty cool is that the head the Citizen FX collective has actually started to release some of the binaries and you know software that will need to do read em which is basically five them but for Red Dead 2 so that's what I want to take a look at today it's really exciting it'll kind of show us some of the cool stuff that we can expect you know obviously we've got trainers like you see I'm using here but it'd be really cool to do this all on a multiplayer server so I don't know that's enough talking let's just go ahead and install red in so we can kind of get started because this might be a long one so the first thing that you're gonna need to do is actually go into the 5 in citizen FX discord once you're in there you're gonna scroll down and you'll see the red M group of channels down at the bottom in there is going to be the hello channel that's where you're going to see all this information that you're seeing on your screen now and this has all the information and the download links that you'll need so you're going to want to grab this SP build link here and you're gonna want to download that it's going to be a zip file within that zip files gonna be two files you're gonna extract that into its own folder wherever you won't read em install because it's gonna download a whole bunch of other files into that directory so you don't want to just like put it on your desktop or something like that so once you have it extracted you're gonna want to go ahead and run it once it's running it's gonna go ahead and update itself and download all the missing files once it has all the missing files it's going to launch again and it's going to start to download the cache that it's missing so spread em needs a specific cache version so it will obtain it from somebody else who has one and then once you have the cache version it'll go ahead and relaunch and you'll see this kind of pink screen if you run into any issues with this like for example you see here I'm kind of stuck on 25% you can close read em and close the launcher relaunch both of them and try it again and I've run into some issues where you have to try and launch it two or three times for it to work like I said earlier this is early access software this is kind of what we get for you know kind of being on the bleeding edge but it's some really cool stuff and I'm really excited to write some of the really cool scripts that we can do because it's you know Wild West and uh you know I'm pretty excited about it alright so once you have the read em single-player installed and you have the cache downloaded we'll need to move on to the next step so will be downloaded in the multiplayer server but we're using it and we're gonna install it but we're vainly just using it to load the resource in to read em the multiplayer and read em is still very very buggy like if you die you're just dead forever the horses don't spawn with carriages some people are invisible you know it's kind of weird so we'll be using this to load the resource but we actually won't be loading like session manager or anything like that which will actually need to like have the actual multiplayer work so we'll go ahead and download the latest build here if you run into any issues with that you can always download the next latest the other thing we'll need is the CFX server data so I'll have this link down below as well and this is actually the same server data that we use in find them except we'll have to make a few changes to this so I've already copied over my red m SP files onto this virtual machine you'll see them here and this has all of the everything except the cache you don't need the cash to do any development so I don't want to put it into here let's go ahead and make a new folder call it red M server once this is open we can go ahead and actually extract these zip files open those up and then in here we'll want to just extract the resources folder into here and then in here you can just copy and drag all these files into here and you can extract it into this folder so once this is setup there's a few edits so we'll have to make to the chat system to make them work because RT r2 is using a new version of the citizen FX API or library whatever you want to call it so we'll need to make some edits to this so once you go to write and server if you go to resources go to system go to chat and then there's the underscore underscore resource Allah so this is one of the main things that changed is this needs to be FX manifest Lua and in here I actually typed our own fix manifest I think it's like Beck's main fest then we'll go ahead and open this up with code and in here we'll have to make a few edits at the top so let's go ahead and add games and then our dr3 I know that seems kind of weird you think of the RDR too but I presume you know that's more of like the next-gen consoles is already our 2fx version is going to be adamant a da ma NT and then we're gonna need something else for this but we'll copy and paste it from the console once we get to another sounds kind of weird the other thing we'll need to do is edit this the chat system so we'll open this up in our text editor as well and in here we want to do for a search for is control pressed and we're gonna need to edit this value because these values are actually different for RT R 3 R 2 I guess that's confusing me so we'll need to set this to 0 X 9 7 2 0 FC EE I'll just have that down below it you can copy and paste yourself as well but this is the key for the T key as weird as that is I had to look this up and the actual like read em discord to figure this out so we'll go ahead and save that and you can close it but we'll leave this one open because we'll have to make one more edit to this alright so now that we've got all of that done we need to go ahead and create our our server config so let's create a new text document server CFG and then let's go ahead and open this up in our text editor and then let's paste in the default config alright so there we go so we'll need to change this to en-us there's nothing really up here that we need to change yet later we'll need to actually add our extension here that week right here you can set your name if you'd like to but the main important thing is down here you need to set your license key and your Steam Web API key mainly the license key is the most important thing right now but you'll need to go ahead and fill this out and once you have this filled out you can go ahead and save it all right so I've got my server dot CFG file created so we can go ahead and run the server so much like 5mm will do run dot CMD + exact server CFG but there's an extra option that we actually have to add for Red Dead and that's so that the FX server knows what game it's launching so to do that we need to just type + set game name Rd R 3 and then you can hit enter and it'll load everything and the most important thing that we're looking out for here is the actual error that it's gonna throw us so we'll click allow access and then we want to actually control C out because if you notice this error right here geez this error right here is that resource chat does not contain the red M pre-release warning in FX manifest Lua please add RDR warning I acknowledge that this is a pre-release ability of red em and I am aware that my resources will become an incompatible once read em ships so yeah we need to go add this to there and we can just paste that in and then we can go ahead and start the server again we shouldn't see any kind of issues we will see an error for session manager Rd R 3 we're not loading that because we don't want the network code to actually run we just want to stay on single-player for this so there we go our server is all ready to go so let's go ahead and jump into Visual Studio alright so we're here in Visual Studio so we can go ahead and create a new project for this we'll make a class library dotnet framework c-sharp like likes like last time for 5m and then we're gonna want to set the project name we'll just name it client and then the solution name we can name whatever you'd like but I'll name mine Rd our test and then you want to make sure the framework is dotnet framework 4.5.2 and then we can go ahead and create the solution all right so once we're in Visual Studio we can do much of the same stuff that we have to do for 5m you can go ahead and rename this from class 1 to whatever you'd like but I'll name on main and then we'll go ahead and say yes to the mastery name and then in here we can go ahead and create our public main oops public main and then we can start doing whatever we'd like like register in a tick handler registering commands but one thing we need to actually do is add the reference so we'll right click on references add reference then I'll browse and you're gonna go to where you have read em SP installed so for me that's C read em SP citizen CLR to live mono 4.5 and we're gonna copy the citizen FX core dll copy this and then we need to go to wherever our repos are so already our test client and then you can just paste this in here and we'll go ahead and click Add and ok and in here we'll come down here to copy local and we'll set this to false then the next thing we'll want to do is create our actual like FX manifest lua so we'll come up here client and then what we'll actually add the file first because that's a lot of cleaner way in my opinion so we'll go to C and then we'll go to our actual like repos folder so for me that see users admin source repos RDR test and in here I'm going to create a new file called epics manifest Lua and I go and save this and open that up in my text editor and in here we're gonna set the same stuff so we'll set games to our dr3 and then you can even step you tape up but honestly that's not needed in an F X underscore version a da ma NT and then I'm gonna copy and paste the warning from the from the clients script that we saw so I have this paste it in here then the neck thing we need to do is set clients script to whoops not capitalized though client script to client net dll and go ahead and save this and this looks good so we've got our game set got our FX version we've got our warning and we've got our client script so we can go ahead and close that and then we'll go back to visual studio and we'll do client add existing item and then we'll go up one folder show all files and then we'll select our epics manifest Lua let's go ahead and click this file and we'll click to copy to output and we'll do copy always so this way are our actual like FX manifest is always saved for us and copied all that good stuff so within here now that we have our references added we can go ahead and add our inheritance for base script hover over that and then we can actually add the citizen FX core just close that out so in here like I said we can do our tick handlers we can do commands stuff like that so the easy stuff of course is to just register a command and we'll need to import this obviously so this this register command is actually exactly the same so you just give it a command name so we'll say let's say give force and then we'll register a new action of test horse and false as the last parameter so let's go ahead and create this test horse function so this will be a private void of test horse so in here we'll need to do some things now there's quite a few things that are different in this new version of the citizen effects so for example since also since this is so early in development a lot of the natives haven't been translated yet so things are still pretty early on so some of the stuff is a little more difficult than it would normally be but anyways so the first thing we need to do is actually know who our player is so unfortunately you can't just you know do ped player or anything like that we have to get it through the API so let's do we'll call him player pet ID and we'll make this equal to AP i dot player pet ID like that and this is going to return an int and this is going to be our handle as you can kind of remember from 5m we have the dot handle so once we have our actual pedestrian we can start to do some different stuff so the first thing we need to do is know where we want to spawn him so we probably just want a small name like a few steps ahead of us for example so much like 5m we have board vector if we have we have the forward vector which kinda can help us out here but to use forward vector we actually need to know where the player is at at first so we need to get his position so we'll use a type of vector three and we'll name this POS four pause but for position and then this is going to be equal to function dot call and this is how you can call some different natives and what we'll need to do is add the open the Open bracket and this is so we can tell it what it's actually going to be returning because if you don't add this and you do the regular function it's just going to return a void which isn't going to work for you very well so in here we'll just tell it that it's going to be returning a vector three and then we can call hash and then in here you can see a lot of the functions some of these will look pretty familiar some of these might be new but the one that we are we're looking for specifically is get entity chords and then the next thing you need to pass it R is the actual arguments so this can be an infinite list of arguments it depends on the native that you're calling but this one just needs our player pet ID so we'll go ahead and call that so this will actually call this native get our entity coordinates and and then store them into POS this is just going to get our current position we actually probably want to go a few steps ahead of our guide so we can do a few things we can make another vector3 of of forward POS and we can make this equal to a function call a vector3 and then hash get and then there's entity forward vector and just like the one above we just need a fastest our actual pet ID that ID and this will then return that so this is just going to return the forward vector so we actually have to add this on to our position and then we probably want to multiply the forward vector a little bit because if you just leave it as is now it's not gonna be very far away from you so if you're so on like a big coach or something you might end up between them and the game will kind of bug out if you're stuck between the horses so what we'll do is we'll call POS for our position and then we'll call plus equal and what this is basically doing is doing POS equals POS plus whatever you type here it's kind of the way to look at it so we'll do POS plus enter or plus plus equal not enter and we want to call our forward POS and then we'll times this by five which should put it about five steps ahead ahead of us ahead of the player the next thing we want to know is which way the player is actually facing because if you spawn the like a coach for example the opposite way that you're facing you can end up inside the horses as well so it's important to know what the actual heading is so this is a float and we'll call this H DG for heading and we'll do another function call and this is going to return a float and then you can probably guess what this one's called get entity heading and we'll call our player pet ID here and end that off there so now we've kind of got everything that we need we know where we want to spawn aim which way we want to spawn in and we know where our player like who our player is and stuff like that so we can go ahead and actually create a horse or the carriage or whatever you want to call them so technically this is like a vehicle so we'll call int of veh for vehicle and this will be equal to function call and this is going to return an integer and then create vehicle and now this one has all kinds of very unique parameters so let's go ahead and take a look at this one now this is another thing that's temporary he even says it up here temporary that it is not gonna be here forever so when this link gets updated I'll try to update the video if it's not right I can try to just let me know and I can try to help it out help you out there all right so as you can see here we get our two different ones um there's not too many options here to kind of help you out and let you know what is what but this is kind of where some research will come in handy either scoping through the read em chats or a scoping through github something like that will kind of help you figure these out so let's go back to visual studio and so the first thing that it needs is the hash of the vehicle that we want to create so for now let's just pass hash we haven't actually created this variable yet then it needs to know the position so we'll call posx POS y POS Z and then we need our heading here and then we'll pass 0 0 0 for these parameters false false 0 0 and I know you kinda have to trust me it works I did some research on github and found some other people on in vehicles and I kind of did my own research some people were putting the heading way down here and it the heading is definitely right here so I've even kind of already improved on some some of the code we found so anyways the next thing we need to do is create this hash so the hashing system is completely different in this new one so we can't just call API dot get hash oops get hash key I wish it was that easy we're gonna need to write a function for this so let's go ahead and let's create a new class and we'll name this one just util and then in here we're gonna actually create this function so this is actually coming from the read em simple trainer so they've actually kind of already figured out how the hashing works exactly so I'm gonna copy and paste this function over and there we go so this is going to generate the hash that the Citizen FX code needs so that I can spawn everything let's go ahead and save that alright so let's go ahead and add in the function that we need so it's going to obviously return an int and we'll call this hash to match up with the variable that we already created and we'll need lips when you do gin hash and then this needs to be equal to the string of the vehicle that you want to create so for example coach to as little as a decent vehicle to spawn and this has given us some trouble here so let's go ahead and using static to up there and I don't thought of that issue so now we have that but the next thing we need to do is actually load the vehicle so the loading system is basically the same as 5m so we'll actually need I guess create the function before we start writing the code for it alright so we'll go ahead and add some lines up here and let's do a public whoops a public static async task boom or load model and then we're gonna need the int of hash and do it like so so we still kind of stuck to doing everything with natives unfortunately so if function we're gonna need to probably import this yeah and using that and then we'll do dot call and this is gonna return a bool because we're gonna check to make sure this is actually valid so is model bad and then we'll pass our hash and then we can do this so anyways we'll then know you can name it here so model hash is not valid so this way we can actually prevent ourselves from getting stuck in some different stuff so let's go ahead and using system diagnostics and in here we'll want to call the actual loading function so we'll do function call and we don't have to put a type here or anything because we don't really care about the response from this it's gonna be true because we know it's a valid model we already checked it so we'll call hash request model and then we'll pass our hash again and then while man I cannot type today function call hash and then we want to check if it has loaded so has model loaded and we'll pass our hash again and then in here we can write our debug line and then let's go add our dollar sign so we can use that variable in there and then we will await a script delay 100 and let's see of this has to return a bool sorry because of course it's gonna just return a void if you don't have this type here so that's what it was complaining about it can't you can't convert a Bulbul to a to avoid it just doesn't work so we probably just have to add this to there we go so this is all good so let's go ahead and use this function and so let's see while we wait love modeling hash and I actually have this too far up actually because we haven't even determine what our hashes hid and we'll just do a return here so we'll go ahead and await this so we need to go at our async operator here fix that up so this way it'll go ahead and load the model and then if it returns false it'll just return so that way if you faffing or something up here you won't you don't have to manually restart any resources or anything like that so now we actually have our vehicle created we're kind of almost there so there is one other thing that you can do you can always set it as a mission entity doesn't really matter for us but if you want it to do it you can just do function call and then hash you can probably guess what this thing's called so set entity as mission entity and this will basically prevent it from despawning true true all right and whoops I did not mean to do that I have a very bad habit of doing that I've been doing that pretty much almost every function so anyways there we go so we can set it as a mission entity and this will actually spawn our horse so there's a few other things you can do you can always do it through the function like this but if you want to do it through like a tick handler you can do on tick like this and it's pretty similar to how we do ticks for 5m except you have to add this decorator here and then we'll add him here so in here you can do different kinds of like loops if you wanted to do or if we wanted to for example detect if a key was pressed so if API dot is control just pressed API player pet ID and so this is basically checking has our player pet ID press the button so as for this button there's all different kinds of ones there are but this I'll have a link to them but down below in a description but this one here is the horse call action so that way whenever we actually want to say press H and call our horse it will just spawn this one because technically we're not going to have one so we'll just call it test horse here and there we go that's all we really have to add for that and now our horses should spawn perfectly so let's go ahead and save this and test this out real quick so we've got everything in here we don't have any errors so let's go ahead and set our properties for this the most important thing is we'll need to change this to client net and then let's go to build and then I always like to set this out of directory and into a single output directory oops I did not include brows that's just so whenever you actually eventually add a server library you don't have to worry about going to do two different locations to grab them so let's go ahead and save this here and let's go ahead and build see if we got any issues it's probably just gonna complain about this being async and not have anything async in it but it's just something that's required for that so oh it's actually given us some complaints about this that's interesting so you can't always just name these back to that but honestly you probably just have to get rid of that and it should work fine so to save that and build there we go so everything built right so now the next step is for us to actually add this to our server so let's go to output this is on our repos folder let's go ahead and copy these guys let's open up a new fault a new Explorer window and we'll go to see the red M server resources and let's create a new folder in here called RDR test and I'm gonna paste the file is in there I'm gonna come back to our server because we actually have to add this to our config for to work open this back up in code and then let's scroll up to the top away from all my key values and let's do start already our tests here there we go all right so let's go ahead and give this a shot and let's see how it goes all right so I'm loaded into red M and what I'm gonna go ahead and do is connect to the virtual machine so you can go to direct connect and if you're running it locally you can obviously just hit your loop package your loopback address at 127.0.0.1 and this would get a locally hosted server mine's not there mine's hosted at this IP and I'm going to go ahead and connect here now if you run into any kind of loading issues you can always try to reload I've had like maybe one or two crashes while loading they like into the game so no worries if you went into that to just reload and try it again alright so I've loaded into game so let's go ahead and give it a shot of Presti and we'll do our command give horse and boom it spawned our carriage it looks pretty good we can also go ahead and press h and spawn one that way and that kind of works as intended pretty cool so let's go ahead and move on to the next thing with you alright so we're back here into Visual Studio and it's time to move on to the next thing so there's a few other things that we can do that already work and that I've kind of tested out like given weapons you can even do some scenarios and stuff like that so let's go ahead let's do the scenarios because that one's pretty easy so we'll do API dot register command and we'll do one that is let's say start completely on the wrong home key there we go start scenario new action and then let's do test start scenario and we'll do false is the last one and then we're also going to want to be able to stop it so we'll do register command stop scenario new function test scenario false there and you could always maybe register like a tick event and while they are you know by the well there's a flag set that they are in a scenario as soon as they would maybe press WASD you could also put this function into there too but I'm actually not sure what the hug movement keys are so that's part of the reason why we're not doing that so we'll do a private void of test start scenario and in here we can actually do our our native call so we'll do function call hash and then there is a start scenario in place and we're gonna want this one so there we go and you can always do also like at position if you want but this one's just as good it'll just do it exactly where you're at the first parameter this one wants is your player peds so will be API and then you need to do player ID and then the next parameter it wants is the actual scenario that you want to do so we'll do API you get hash key and then there's all different kinds of scenarios or it's like so many more than GTA 5 there's a huge list here at the mod Red Dead website it's all different kinds of ones and there's quite a few you know like the smoking ones to drinking ones there's just basically probably probably basically any type that you'd ever want this list is super massive but I guess with his uh you know open-world as already are is you kind of have to so let's do this one here world human smoke and let's go back to visual studio and let's pop this in here then the next parameter it wants is the time that it's going to be doing it so if we set this to negative one it'll just do it infinite and let's pass true false false flux for this for these parameters and that'll get us set to where we exactly need it at and there we go so the next thing we'll need is private void test stop scenario and this one as you probably can guess we'll do a function call to hash dot clear pet tas and you you can do pet task or pet task immediately if you do immediately it's it's kind of too quick and he like goes into a quick t pose as he ends the scenario so I found that that one doesn't work too well and then we'll just do clear pet tasks and then once again we're gonna need our player pet ID and then we'll go ahead in that there so this will get our scenario going then the other thing I mentioned is maybe like a weapon a weapon thing so what we'll basically want give our guys some weapons because you spawn with nothing you don't have anything when you've responded to read him so let's go ahead and create that function so we'll name it test weapon and then we can go ahead and add our function up here let's do API register command and give weapon and we'll do a new whoops a new action of the test weapon and then false for that guy let's come back down here and we'll probably want to give him a few different weapons so we'll want to maybe give him like a repeater maybe like a lasso or something like that so what we want to do is do a function call and then now this one there isn't a there isn't like a predetermined one that's already translated in here like if you do weapon might give weapon there's not really too much give delayed weapon so I mean I don't have that one's not too far away but there are some actual give weapon natives that you can do so you can do give weapon to ped and then there's also this one and this one has a lot more options and it actually looks like people are using this one so for a list of weapon groups here is a weapons enum made by mushi let's take a look at this and this will have a list of like weapons weapon groups stuff like that so this is all pretty useful so let's go ahead and copy this into our utility class down here and we'll copy this let's go back to visual studio and then we'll go to our utility class down here and we'll add these guys down at the bottom and this will even give us like ammo and stuff like that so that's pretty interesting alright so now that we've got that we can go ahead and save the utility one and we'll want to go back to our native documentation so he gives a few of the parameters here that you should actually fill out and the rest of them are pretty self-explanatory like ammo count equipped now stuff like that so yeah pretty cool so let's go back to visual studio and since there's no hash for that we actually have to call it by the the native variable so for example this right here will actually copy and paste this because this is the only way we can actually copy it and we're gonna cast this to a hash and this will get us doing exactly what we need so the first the first parameter that is said it actually needed was the was was the ped so we'll go ahead since we know we're going to be giving our guy a few weapons let's go ahead and create a variable for this so player cut ID equals API player ped ID and let's go ahead and add him in here then the next thing we're gonna need is the actual as aun of the weapon so that would be something like weapon hash and then there's all different there's all the weapon weapons we added so let's just give him like a repeater oops repeater carbine and then the next thing is the ammo count so we'll do a hundred and then we'll pass true and true for these two variables then one for the weapon group false 0.5 1.05 and our 1.0 F sorry and these are the two parameters that he mentioned and then the last two were zero and zero so false and zero for that and going in that call there so this will actually give our guy a repair now we could just copy and paste this a few times and change these weapons but it's probably better and cleaner for if we just created a gift weapon give weapon to pet function so we'll take a pet and we'll take a weapon hash of weapon and what we want to do instead is move this call let's say it into here and then we'll change this to just weapon we'll change this to ped and then up here all we have to do is call give weapon to ped player that ID and then we need to pass a weapon hash so we'll pass the repeater and there that is much much easier to type out so obviously this would be like a really good utility utility I cannot type today at all to ped player ped ID and what else do we have like there's like the binoculars that you can giving what else did I say like a lasso we're giving the weapon power lasso so this way he'll actually get all these weapons and we can use them and the ammo won't really apply to some of these but it's fine that won't really cause like any major issues with anything it'll still they'll still work just fine all right so we've got everything we've got our we've got our functions up here we've got our scenarios created so we can actually go ahead and test this out we won't add any other controls just because it's pretty early on and like a lot of this probably isn't going to stay the same so all right let's go ahead and build do a quick build let's make sure everything works make sure we didn't make any terrible mistakes but looks like we're all good so let's go ahead and copy over this file good resources RDS or your test copy these over and replace these and then if you have the server already running you can't always just do we start our TR test and it'll start and restart the resource or you can just control C and restart the server if you'd like that way but let's go ahead and jump back in to read em and let's see kind of what we did all right so we're back in game 1 let's go ahead and try out our scenarios for example so let's start slash start scenario and if you take a look he's actually got a little cigarette in his hand and he'll stand here and and do his thing but uh you can't really move out of it or anything like that so if we do slash stop scenario you'll see him kind of slowly drop the cigarette and then you can walk away or whatever you want if you did the immediately thing he would just drop it in like glitch immediately back to like his resting position so that's why I don't do the immediately one let's test out our other one give weapon and we can instantly see that worked it gave us our last so and stuff so let's go ahead and come out to here so we probably have to wait for this thing to realize that we're not on a server so let's just give it a few seconds until it yep there goes until it rises it can't connect and then we should be able to do whatever we want with this so all good and now we've got our weapons and these signs are even destructible I did not know that for the longest time so yeah it looks like we got everything working there's even pedestrians out see what he do he's not too happy about that but anyways we got our weapon we got our last so we got our binoculars so we can see him run away he's hurtin but uh yeah that's gonna be all for today I'm sure there's a long video as is but hopefully you guys have enjoyed making your own read and mods we're gonna do some cool stuff in this series I think the five M stuff is pretty cool but I already have some pretty cool ideas first stuff that we can do like especially once this gets improved in like you know stuff like that is fixed I promise this isn't my PC that seems to be like a red M thing like yeah like this bush is flickers too and stuff like that yeah there it goes but uh yeah hopefully you guys have enjoyed leave your suggestions for mods and scripts that we can create in this series I think that'd be pretty cool and I'll see you guys next time
Info
Channel: rubysown
Views: 38,823
Rating: undefined out of 5
Keywords: rubysown, RedM, red m, red dead 2, red dead redemption 2, script development, how to, walkthrough, guide, citizenfx, cfx, fivem, c#, lua, c sharp, visual studio, visual, studio, custom, coding, develop, development
Id: pCIfZh0Lni4
Channel Id: undefined
Length: 42min 14sec (2534 seconds)
Published: Mon Dec 02 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.