Skip to content

refactor(esx_drugs): code structure#85

Open
ghost wants to merge 6 commits intodevfrom
drugs-fix
Open

refactor(esx_drugs): code structure#85
ghost wants to merge 6 commits intodevfrom
drugs-fix

Conversation

@ghost
Copy link

@ghost ghost commented Oct 19, 2025

Description

Better performance, cleaner code structure, and more reliable plant spawning system.

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

@N0tNvll N0tNvll requested review from Kr3mu and N0tNvll October 19, 2025 20:18
Copy link
Member

@Kr3mu Kr3mu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I am not sure but it would be better if you use esx point build in system.
Not everything uses locales. In client/main.lua you have local elements2 and elements move the local elements in do end code block to avoid naming variable to elements2.
The weed.lua CreateThread is unreadable, try creating local functions that handles certian parts please. I would rename localization item to items. And better would be if you add those item names etc. to the locales and then do config variable add default licenses and items or whatever and if it is enable then add them using sql or if i am not mistaken there is a function to do that. In server/main.lua you also use pairs but don't use the plantId. ProcessCannabis is also very nested. you can do if not x then return end to make it slightly more readable

}
menuOpen = true

for k, v in pairs(ESX.GetPlayerData().inventory) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use pairs. Use numeric loop instead as you don't even use key.

local menuOpen = false
local inZoneDrugShop = false
local inRangeMarkerDrugShop = false
local dealerTextShow = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the code structure. Can you use do end code blocks so it much clearer.
Last code snippet: https://www.lua.org/pil/4.2.html

@@ -159,4 +130,4 @@ CreateThread(function()
for k,zone in pairs(Config.CircleZones) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here. You don't need key.
https://springrts.com/wiki/Lua_Performance#TEST_12:_Adding_Table_Items_.28table.insert_vs._.5B_.5D.29
Check the performance article.


ESX.OpenContext("right", elements2, function(menu2,element2)
ESX.CloseContext()
local count = tonumber(menu2.eles[2].inputValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if count fails?

@ghost ghost requested a review from Kr3mu October 23, 2025 20:23
@Kr3mu Kr3mu changed the base branch from main to dev October 23, 2025 20:26
@Kr3mu
Copy link
Member

Kr3mu commented Oct 23, 2025

Well the commit you have created don't meet the comments again.
Let me explain because you might not understand.
You should use numeric for loop for better optimization
https://springrts.com/wiki/Lua_Performance#TEST_12:_Adding_Table_Items_.28table.insert_vs._.5B_.5D.29
Here you have the benchmark stats.
While it techincly ain't an error, it has impact on the performance.
Also I would like to talk about creating a nested code.
As you can see in weed.lua you/or someone before did that.
It would be better readable if you add negation to the codition and just return or whatever.
If return or break isn't possible use goto http://lua-users.org/wiki/GotoStatement
This is what is unwanted thing:
image
If you don't know something ask me or any of the team members on dev chat 👍

Kenshiin13 and others added 3 commits October 23, 2025 22:41
Signed-off-by: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com>
@CLAassistant
Copy link

CLAassistant commented Nov 16, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Kenshiin13
❌ Rafael Antunes


Rafael Antunes seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants