Let's create something useful! - FiveM treasure resource

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone uh so today i'm gonna make slightly different video i'm gonna work on a resource and i'm gonna try making something useful something that any server could use or not any but some server could use now like just a simple tutorial with a simple script just made to explain some stuff um probably not gonna explain every single step that i'm doing here but i'll try as best as i can and if you like a video like that just make sure to subscribe and like and comment if you if you're gonna want to see um any more of this uh so yeah so i'm gonna make a little uh resource that's gonna be used for treasures i just made a little uh a little diagram here just for myself to organize my stuff a little bit for the beginning uh i'll most likely gonna add a bit uh more stuff later into the diagram but yeah just for the beginning uh so the goal for the beginning is to create a little class treasure box class which is gonna hold ids content of box box id as well and if and it's gonna say is if the a box treasure box treasure chest i don't know i just gonna call it boxes probably uh it's looted or not uh i also gonna need a little table of all the boxes uh most likely just ids of them i'll see and yeah those are the functions for the beginning that i'm gonna need all of this is most likely gonna be just in server side uh we're gonna go to this is just gonna this is just a basic uh sort of um end of the resource so the idea of the resource is that um administrator or someone with the privileges will be able to drop boxes with specific inventory in any place of the map and then players basically can go search for them and get dilute so let's start with creating my resource manifest uh first of all gonna need server probably scripts server that lua and i'm gonna need a little uh file let's call it let's call it box.lula that's gonna be our class file and for now it should be okay so let's create a new folder in here let's call it classes new file in here box let me just open some documentation so i'm going to create a function uh let's call it create treasure uh box i guess and here we're gonna need um i'm thinking should i most likely i'm gonna need box id and then i'm gonna need a chords um and uh inventory of probably called inventory i'm just gonna return itself and we're going to create local self is equal to empty array so i know i didn't make any uh tutorials for the classes so maybe i'll make it in the future but i'll try to explain a little bit of the stuff here uh let's create a self course is equal to chords itself um i probably should have started with box id is equal to box id self um and inventory is equal to inventory um self is limited is equal to false yeah for the default one it falls because when i created it technically it shouldn't be limited like straight away okay so how classes are working uh so basically what class allows us to do is it allows to create lots of objects that that have different parameters and these are basically the parameters for our now basically these are parameters these are probably i don't really know about the i'm not sure about the terminology at the moment but basically yeah uh this is what um this is probably what parameters our uh each every single of our class object is going to have so class allows us to basically create lots of objects that can that can have same uh just might as well but do not disturb on my discord so what class does is allow us to have uh functions for the objects we create using the class and what we can do is for example we can create a function which we could call loot loot crate is equal to function there so in here once we create every single of our treasure boxes we can use for every single of them we can use loot crate and that's going to execute everything that's in our function that is why classes are quite useful especially it is really good and really nice to have them if you want your code to be really clean since you write it all in a separate uh in a separate file but probably talk about it more but later so now we need to think of what else we're going to need for our class self loot crate and so we're gonna have to add functionality to give probably all the items the person who loots it so maybe we need player id here player id of the person he loots it what else can we add for now i'm not really sure what else we need so let's create a server.hero file and here we create boxes our empty array and the idea is to make all the resource work through database that all the treasures will be stored in database and and yeah so [Music] when the resource starts it should she make up a little i need a little function that's going to load all the boxes into the boxes array from database so i need my sql dot ready trolls function and and from here i will need to i will probably need to fetch all [Music] from my database mysql async fetch all and i need select all from i need to create a table which we're gonna call probably treasure boxes i guess um i think i just need that really i'll start thinking if i really need a boxes array uh for everything because if i have everything in the database i don't really need an array unless i want unless i want the uh unless i want my database to be a bit uh not loaded as much basically so yeah i think if i will if i will load if i load all the boxes into the array that will load up my database a little bit less so i might as well just try doing that so yeah i'll just try doing that but then every time i delete a box i'll need to delete him from both from here from there or i just can really i'll think about them okay so let's do that if data is to four and then i will need to i is equal to one number of data and boxes is equal to boxes i i guess no wait why didn't i do that i don't really need that box is not equal to nil data is not equal to nil then boxes is equal to data there you go am i wrong sugar right yeah and then yeah so now i just need to create a a new table uh let's say okay so i need um i'm gonna create this create table treasure boxes um i'm gonna call it id and now we're gonna need chords i guess or charm g5 and oops culture not gorgeous i need more and then i need then i need a contents or inventory i'll just write contents watcher again two five five oh why the march what's that needs primary uh let's see do i need what's wrong with this yeah i miss a brighter somewhere everybody there you go so a great table treasure boxes uh i'll take command hold i call it treasure boxes here treasure boxes okay just so i can try as well copy that just so i can try if it if it gets held from there uh alright so i have this pudding there what else do i need we might as well as we'll just do and four is equal to one is equal to one and number of boxes do and print let's print boxes i dot er what remove course wasn't they're called chords uh yes splendido splendente okay now i can try starting my server to see how it goes i just realized that i forgot to add this which gives me access to uh basically that's basically uh library excuse me i refreshed it should have let me do that was i supposed to put it first i don't remember now okay there you go all right so there's scores and we also have and we also had uh and then inventory the call inventory contents for sake okay that is just why i put there that is great okay so once i'm done with that just here yep function add box to database and so i need chords and contents and here we're gonna call mysql placing execute execute insert into uh treasure boxes chords contents and values and then we did this yeah i can do that and then here i add chords is equal is equal to chords and contents content is equal to contents so now i'll add a function so now i'll add a function that is going to delete a treasure box from both array and database so let me just do that so now delete treasure box function is gonna delete it from uh from the mysql table and from uh and from the array as well so i think let's try doing that let's register command let's write the delete box and function handler source args and delete treasure box i'll just put that on this one uh yeah should i put your number here i don't think so really yeah let's try later so if i restart the box which has a id of four so this should be gone now yes it's gone that's perfect and if i restart it it obviously is not loading there that is great i don't need this anymore so now i can call this function whenever the box is looted so let's say i'll just copy that delete and self box id so that is going to delete once this is looted and that is great also we're going to need is i'm going to have to add a um all the items from this and i'll have to think of the weight of doing it okay i'm gonna try doing now is i'm gonna start i'm gonna start thinking about front end and how to implement everything to game first we're gonna do is i will um i will um try making uh try decoding all the items uh i just need to really remember how to do it to the code all the array of the contents that are gonna be in the box uh to json uh to json format to uh basically put it in database because that would be a much easier way of doing it so i'm just gonna try figuring out the way of doing it now so i ended up creating a little algorithm that lets me to put command add box and enter item name and number of the items and then another item name and a number of them as well but i got into another uh error saying that you can't find this for some reason right now is that because i um because i didn't put that and i need to refresh and oops and restart this and let's try doing that item 2 for let me see what goes into the database and yes i have first item second item and amounts of both of them that is great now i just need i just need to find a way to work with coordinates but that i'm gonna do when i start implementing everything to game i think i think i should register this command and a client side actually because i will need um coordinates of the player because i want to do that where player stands in that place there he will be able to add the box um and i'm not sure if i can actually find a coordinates from server side uh probably i need to do a client side yeah yeah i'll try figuring it out also actually i went into a native reference for them and i found out that it is in the server side as well there's one client and one server side and that's great because then i can [Music] uh yeah i can just uh use i get entity cores in in in in server side and that's really good so i won't need to actually do anything in client side uh in terms of that so uh okay now i need to do now i need to check actually if source exists if source is not equal to minus one then i think it's minus one i'm not sure what console actually returns uh marianne let's just start doing that i might as well just do this way so i'll still be able to do it in in here and i'm coming here and i'll add a variable let's say chords so is equal to how should i do it is equal to array um zero yeah so x is equal to zero um y is equal to zero and uh set is equal to zero point zero i'll just put point zero just uh so it knows that it's a double number i think that's how you write it not really sure yeah and i will need to encode that as well json and code and chords let's see how it goes uh yeah let's see if it yeah that's what i need really that's great i might as well put that as a number yeah i think i should uh make this to number and just so it registers it as a number so now because now it is uh putting that as a string as it is in quotes if i did that and then it should come up as an integer i mean as a number yeah it's not in quotes anymore so that's great and because later i might need a not as a string bar as a number okay so if sources uh basically if this command is written not from console that's what it means in simple terms then i will need to get player coordinates and rewrite them here so then uh i'm gonna what i'm gonna do is uh i lost yeah i need this actually i don't need it it's just that is equal and then i put it in chords and i mustn't just do it like that is equal to chords dot so basically that's the same format as here but it does it in it does it from coordinates where the player is exactly at that moment when he writes the command okay so so now i need to think that when i will need to create an a a function that is going to get all of the boxes or also i wanted to sort of modify this i'm gonna create local box is equal to create treasure box dot id dot dot course dot dot contents and then boxes is and then boxes dot dot id is equal to box yeah so that's going to put it in there as a um class object as an object created by class basically same way as it does here okay um that's just my testing stuff i should put it like on the top so this and mess around with all of these okay so now i'm gonna need i'm gonna need uh to create some i think i'm just gonna call it boxes as well and in here i'm gonna i'm gonna make a oops actually net i meant i'm gonna call it the simple treasures and i'm just going to need color boxes and then boxes is equal to boxes and set boxes so that is gonna send boxes away from server side to your client side basically that's what it's going to do because if i have it in server side it's not going to be found in here and in here i'm gonna need to create a thread and i'm gonna do some really uh and i'm gonna do some some nested or nested loops here uh i'm gonna do that amount of boxes and here you'll have to go through each box [Music] and also i need to create local bed is equal to get play minus one here i will need distance is equal to hash oh yeah uh local player calls equal to get entity cards uh i just gonna try uh making it uh draw each of the box when player is nearby yeah i'll just try doing that and i'll come back yeah so that should do that should draw marker and with players at least less than 100 meters away and then if he play if the player gets like 2.5 meters away from the marker you'll be able to press the button and he's gonna get that text let's just test it for now uh yeah obviously my phone crashed and that is just wonderful uh yeah let's try getting into the game and uh see if all of the client side works for now yeah i still know that um if i will make a marker i mean make a a box uh it's not gonna come up right away because i didn't make any any trigger to refresh uh let's refresh the um markers uh not the markers the boxes about what we're gonna try to do now is i'll try adding box uh let's say weapon this tool one let me see if that comes to the database it did come i'm going to put my coordinates i think because i didn't restart the thing actually i also had forgot i needed to put this in a for loop to index every single of the data line so yeah let's try doing it now let's see if it comes to the database yes coordinates are coming there the only thing is that they are quite long actually and they are not rounded that sometimes might cause problems so let's have a look into it uh so it's around uh coordinates i'll create a little function yeah that's just basically the algorithm and we're gonna need you just put that in front of uh basically put the coordinates inside of this uh on the side of the function and that should let me return the coordinates as a bit shorter uh rounded number and then it's not gonna cause any problems for me later uh so let's just see if it did it uh one two three four five five five five numbers in each one that is great so now wait if i'm if i'm restarting the resource i think it's still not going to uh it's still not showing me the thing or is it uh oh oh what the did i did here uh i need box dot chords i don't know why that put a player in there yeah that's what i need let me see if that is happening should draw the marker somewhere around here but it's not doing that for some reason um because it doesn't set on the client side obviously because the function the event is not even triggered so yeah i need to trigger the event trigger client went i'll just copy the name because otherwise i'll just mess it up um ah okay i will need to put it when player joins the server then i need to do it but yeah i'll just do that actually should put inside of this and oh okay and it is still not coming up okay what is still the problem then yeah obviously ah for sake okay that's what i did wrong uh okay so after a little bit of tweaking and debugging i found that i did some stuff wrong here with the tables um i needed to change i forgot to yeah i forgot to decode the coordinates here and uh yeah it was some stuff so yeah i have those three boxes that i created here and if i press e i get the looting notification uh not notification but print uh and that is what i wanted to do so far okay next i am gonna try to um i'll need to try to draw an object not draw not to create an object that is gonna replace the markers and uh i would like it to be a safe or something i'll try to look for some objects that would fit treasure sort of box and yeah we'll come back with that so so yeah i was able to um do something like that with a little box model the box object uh i might as well just uh try looking try having a look at the other objects and try changing it uh but i'll see about it later uh obviously i can't really delete the boxes that i spawned now but that's just for testing so it doesn't matter so yeah i'll just do a little bit of cleanup now and i will try to look for another uh box model so so yeah i ended up cleaning up a little bit of the code i ended up just i think i shouldn't leave that as well the sx i made it a little weight if it is still nil um i also deleted the marker which was not necessary in this case uh yeah i changed the coordinates a little bit and all that um also allow enable the collision for entity as well just to make it like a little bit more natural so yeah what could also do is i could add facing to it like a heading i think i'll do a bit later yeah i'm just leaving for now so yeah basically what i want to do next is i want to add a little notification when you come to it and just so player would know that it is a treasure and that they found the treasure and that they can press an e button to loot it and then after that i will try adding um i will try adding like looting like actual looting for it because now i can't really take any items out of that so i need to need to find one of them i think it's this yeah that's what i wanna show help notification show advanced notification show notification that's what i want is this client side should be yeah basically i just want to add notification for that sorry player is closer sx notification message who else is there okay i can change the color like 120 140 now i'll get just get 160 that's a bit more natural uh 160 and uh i as well put that to true why not i'll just get through there and i'll set 160 and let's see if it works no okay that's great if i'm away does he what why is it still there just gonna there you go and i'm gonna say e i'll say you found a treasure e looted yeah there you go oh good um i might as well oh careful with that um i'm not sure the flashing is not a bit annoying now i'll just leave for now i know that i can add a uh actual button and put pick up i think it is i can't really remember things like that should be like that ah but i put the number thing there you go that's what i wanted to do and if i press e it's looping it okay i've got that done now i need to uh make it actually lootable i guess so from that let's create a new event let's call it treasure box okay and one one in here i need to pass id of the loot box actually so box id is there anything else once okay so let's do local sources equal to source i mean it's not really necessary to do that but sometimes for some reason source just returns nil and when you do that it works so yeah that's just a practice that everyone is doing usually and then we're going to do x player is equal to es6 i'll need to register es6 here as well just like that okay so source okay and now um local box is equal to boxes um box id that's gonna return my box with all its um as an object basically and then i need to get all the contents of it so let me think uh so i need a local items in box is equal to uh i need to decode it oops json the code should decode it i think i should decode it here js sun decode uh so the code all this contents is gonna be saved there so i don't need to decode here and now we can save box that contents is equal to that then i need four um oh actually i was gonna do it here yeah i can't just do that uh so i'm just gonna do box boot box lead box it's gonna delete that and what i need to do is and box is equal to that box loot box blue right source and that's gonna pass that to this and here i'm gonna local x player is equal to the sx dot get player from id player and then i'm going to go through all its contents um for uh y is equal to one i guess a number of contents do and so it returns a mount of them uh i can't remember now should probably do in pairs in pairs self in fact self contents let's just try printing it print v and print okay and let's see what it does let's run my internet trigger server event oops yep and i need to pass box id let's see what it does um what what happened here oh there you go okay uh it seems like it is getting the amount and getting the thing but it's showing somewhere as 68 server that's weird i tend to think there's no value that little box how come that is nil value shouldn't really be no value uh let me just do some debugging okay so apparently the problem is that it does work but it doesn't destroy it doesn't refresh you it doesn't refresh the boxes here so need i need to find a way to despawn it um okay so what i need to do in um client side is to destroy uh entity need to destroy that with a hash of this that should do it someone suppressing should be destroyed uh i'm not sure if it's destroyed now because i'll spawn so many of them i'll just add one more restart okay yes that's great that's destroying it should destroy it for all network as well um i don't need this anymore so it is getting looted but i can still come here and i think i can still press e yeah i can still do that and that's what caused the problem basically so i need every time after box is getting looted it needs to set the boxes again let me see so afterwards looted it has to trigger this event again basically uh yep after all of that is done really i think it should do should do the job uh yeah okay so [Music] so v is returning item type so that's going to be item and that's going to be amount okay so now i need to add items to the player so i'm gonna go into uh and see where did i put it there you go and i add inventory item that's the one that's what i need to do for the player um i think i'm not gonna really check if player can carry that in this point uh i'm just gonna just gonna add the item it's just item name and item count add inventory item okay so if not then x player add item item name is item and amount should do okay uh let's delete the ones that have invalid names i mean invalid things and let's add a couple of boxes to see if it's working you for some reason i didn't destroy one of the boxes i wonder why that happened okay let's restart and now should get yeah i didn't get it that's weird uh okay let's try doing weapon smg no that's not coming up okay now we did and i didn't get the weapon obviously because i'm not putting them in capitals capital letters smg why is not coming up that's quite weird so what i'm gonna do instead is when i'm restarting the resource this event should get triggered and i will just put wait like two seconds and and then that event is gonna get triggered after the resource getting restarted so let's see if that happens once you set boxes uh yeah it worked looks like uh this time it did yeah that's great uh so if i put that we started after two seconds yes it did pop up that's great that is just wonderful okay so i'm getting the items that works pretty much well um i'm thinking if there's anything at all oh so wait if i remove the item it is getting refreshed if i'm removing the item it is getting refreshed uh i just need to add some permissions for this sandboxes is not really needed for the moment and this i think i should add a bit higher um so that is working lead box is working and surfing for the moment obviously there is much more stuff that you can improve on and what i can do but i think i'm just gonna leave it like that for now i think i'll try putting the code to the github if i did you will find the code down in description and so if you want to improve it yourself if you want to add something just go ahead and do it just go ahead get the code and do it and obviously tell me in the comments what would you improve what else you would do with the with this resource and yeah i'll just leave it for you uh i hope you learned something and i hope you helped someone if you want any if you need any help just join my discord which is going to be down in description as well and i hope to see you next time bye
Info
Channel: daZepelin
Views: 1,779
Rating: undefined out of 5
Keywords: gaming, game, gtaV, Fivem, lua, scripting, programming, resource, writing, VSC, Virtual Studio Code, coding, code, script, program, mods, rp, multiplayer, Grand Theft Auto, roleplay, role play, role-play, role, play, tutorial, education, how to, help, discord, fx manifest, fx server, fxserver
Id: 6st4I-aKsEo
Channel Id: undefined
Length: 76min 37sec (4597 seconds)
Published: Sun Sep 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.