FPtje / DarkRP

DarkRP, a non-serious roleplay gamemode for Garry's Mod.
https://darkrp.miraheze.org
MIT License
465 stars 710 forks source link

Modules loaded before config #2386

Closed uen closed 8 years ago

uen commented 8 years ago

Description of the bug

DarkRP loads it's own modules first, then default custom things, then calls DarkRPFinishedLoading which loads any non-gamemode darkrp_modules and then the non-gamemode custom things in darkrp_customthings/*

Which means that any items added using DarkRP.createEntity in modules that require those jobs (such as for using .allowed: https://github.com/vrondakis/Leveling-System/blob/master/addons/darkrpmodification/lua/darkrp_modules/levels/sh_config.lua#L184 ) won't work unless the job was added in the gamemode (and already loaded)

How to make the bug happen

1) Create: /addons/test/lua/darkrp_modules/test/sh_items.lua

2) Add the following to that file:

DarkRP.createEntity("Test entity 1", {
    ent = "ent",
    model = "models/props_c17/consolebox01a.mdl",
    price = 1000,
    cmd = "test1",
    allowed = {TEAM_CITIZEN},
})

DarkRP.createEntity("Test entity 2", {
    ent = "ent",
    model = "models/props_c17/consolebox01a.mdl",
    price = 1000,
    cmd = "test2",
    allowed = {TEAM_MERCHANT},
})

3) Add the following to /addons/darkrpmodification/darkrp_customthings/jobs.lua:

TEAM_MERCHANT = DarkRP.createJob("Merchant", {
    color = Color(0, 240, 150,255),
    model = "models/player/odessa.mdl",
    description = [[Merchants sell useful items to players]],
    weapons = {},
    command = "merchant",
    level = 5,
    max = 2,
    salary = 250,
    admin = 0,
})

4) Join the game, 'Test entity 1' will be purchasable because you're the TEAM_CITIZEN job, but when you switch to TEAM_MERCHANT neither 'Test entity 1' or 'Test entity 2' will be purchasable because you're not TEAM_CITIZEN and TEAM_MERCHANT wasn't available when the entity was added because it hadn't loaded the jobs file yet

Lua errors

Why the developer of DarkRP is responsible for this issue

I don't know if it's supposed to be this way but it doesn't seem possible to add items that use .allowed dynamically through modules unless the code to do so is in one of the darkrp_customthings files, which would still only work if that file was loaded after the other job files

FPtje commented 8 years ago

There exists no order that satisfies everyone. I've had people ask me to have modules run BEFORE shit is loaded. You're asking me to do it AFTER shit is loaded.

The decision is before, because you can always add a hook to do things later. In your case, OnGamemodeLoaded

FPtje commented 8 years ago

Or loadCustomDarkRPItems, that works better.