First of all, thanks for this. Ive been looking at doing something similar myself.
Excuse my ignorance if so but isn’t fetching results every 4 seconds a bad thing?
At the moment for testing ive removed the loop that gets level, ive disabled the ui and just added a /checklevel command that displays level and % in chat. What i noticed with this is, if you trigger addexp or addlevel more than once before checking level, itll only rank you up for the first trigger.
So for example, if i sell drugs to 3 people for 1% each. If i dont check my level for 3 sales, it’ll only give me exp for 1 sale. I’ve yet to understand why, but maybe you have an idea.
after installed the sql file , you got identifier, level and percent
i added the code when player fetch information from database if they didn’t find their identifier id , the server lua will create one for them with their steam id as identifier and level to 0 also the percent to 0 automatically . after that they found their steamid . mysql will fetch it’s level and percent to player and then send to client nui
yes a loop 4 second fetching database is a bad thing. i don’t know if this idea gonna work ( i plan to fetch player exp and percent only once when they are spawning , and when they achieve more exp it only update the value of exp and percent in their local , and when they disconnect the server will fetch their local exp and percent update it back to database )
as you can see , addlevel addpercent uses the current exp and percent + extra level and percent that you store in local update back to database , so you example if you use /checklevel once and it store 2 level and 30% in local . let’s name it
local currentlvl= 0 and then you fetch the data by /checklevel so now currentexp = 2 . so you add 2 morelevel and now the level in database is 4 but the local currentlvl is still 2 because you didn’t update the currentlvl by fetching it . the second time you add 2 more level it just gonna use the currentlvl= 2 , plus the extra 2 and it still 4 , even if you plus it many more time it still gonna be the same without update the current lvl