(DarkRP Error) attempt to call field 'defineChatCommand' (a nil value)

Hello, i have a big problem…
Excuse me if my English is not very good.
I would to create a command for police chief for active counter-terrorist job
I show to you all my coding :

(I have create gouvernement jobs in a module)
ServeurDarkRP\steamapps\common\GarrysModDS\garrysmod\addons\darkrpmodification-master\lua\darkrp_modules\jobs\sh_job_gouvernement.lua :


TEAM_POLICE = DarkRP.createJob("Policier", {
    color = Color(0, 0, 0, 255),
    model = {
        "models/player/santosrp/Male_02_santosrp.mdl",
        "models/player/santosrp/Male_04_santosrp.mdl",
        "models/player/santosrp/Male_05_santosrp.mdl",
        "models/player/santosrp/Male_06_santosrp.mdl",
        "models/player/santosrp/Male_07_santosrp.mdl",
        "models/player/santosrp/Male_08_santosrp.mdl",
        "models/ccz/femalecop1.mdl",
        "models/ccz/femalecop2.mdl"},
    description = [[La police doit assurer la sécurité des personnes, des biens et maintenir l'ordre public en faisant appliquer la loi.]],
    weapons = {"arrest_stick", "unarrest_stick", "weapon_stungun", "weapon_checker", "fas2_glock20", "fas2_m3s90", "stunstick", "door_ram"},
    command = "policier",
    max = 10,
    salary = 130,
    admin = 0,
    vote = true,
    hasLicense = true,
    category = "Protections Publics",
	CanPlayerSuicide = function(ply) return false end,
	candemote = true,
	PlayerDeath = function(ply, weapon, killer)
		ply:teamBan()
		ply:changeTeam(GAMEMODE.DefaultTeam, true)
	end
})

TEAM_COMMISSAIRE = DarkRP.createJob("Commissaire", {
    color = Color(0, 0, 0, 255),
    model = {
        "models/player/uk_police/uk_police_01.mdl",
        "models/player/uk_police/uk_police_02.mdl",
        "models/player/uk_police/uk_police_03.mdl",
        "models/player/uk_police/uk_police_04.mdl",
        "models/player/uk_police/uk_police_05.mdl",
        "models/player/uk_police/uk_police_06.mdl",
        "models/player/uk_police/uk_police_07.mdl",
        "models/player/uk_police/uk_police_08.mdl",
		"models/player/uk_police/uk_police_09.mdl"},
    description = [[Vous dirigez les brigades policières et prenez en charge le commisariat.]],
    weapons = {"arrest_stick", "unarrest_stick", "weapon_stungun", "weapon_checker", "fas2_deagle", "fas2_m3s90", "stunstick", "door_ram"},
    command = "commissaire",
    max = 1,
    salary = 160,
    admin = 0,
    vote = true,
    hasLicense = true,
    chief = true,
	CanPlayerSuicide = function(ply) return false end,
	candemote = true,
    NeedToChangeFrom = TEAM_POLICE,
    category = "Protections Publics",
	PlayerDeath = function(ply, weapon, killer)
		ply:teamBan()
		ply:changeTeam(GAMEMODE.DefaultTeam, true)
		if killer:IsPlayer() then
			for k, v in pairs (player.GetAll()) do
			DarkRP.talkToPerson(Color(0,0,0, 255), DarkRP.getPhrase("new"), Color(255, 255, 0, 255), "Le/La commissaire a été tué(e)" )
            PrintMessage( HUD_PRINTTALK, "Journal d'actualité: Le/La commissaire a été tué(e)." )
			end
		else
			for k, v in pairs (player.GetAll()) do
            PrintMessage( HUD_PRINTTALK, "Journal d'actualité: Le/La commissaire est mort(e)." )
			end
		end
	end
})

local function ActiveSAT(ply)
	if ply.Team("TEAM_COMMISSAIRE") then
		TEAM_SAT = DarkRP.createJob("Anti-Terroriste", {
			color = Color(0, 0, 0, 255),
			model = {
				"models/player/PMC_4/PMC__02.mdl",
				"models/player/PMC_4/PMC__03.mdl",
				"models/player/PMC_4/PMC__04.mdl",
				"models/player/PMC_4/PMC__05.mdl",
				"models/player/PMC_4/PMC__06.mdl",
				"models/player/PMC_4/PMC__07.mdl",
				"models/player/PMC_4/PMC__08.mdl",
				"models/player/PMC_4/PMC__09.mdl",
				"models/player/PMC_4/PMC__10.mdl",
				"models/player/PMC_4/PMC__11.mdl",
				"models/player/PMC_4/PMC__12.mdl",
				"models/player/PMC_4/PMC__13.mdl",
				"models/player/PMC_4/PMC__14.mdl"},
			description = [[La S.A.T. (Section Anti-Terroriste) est là pour intervenir dans les opérations les plus risqués pour la justice. Les agents de la S.A.T. doivent être contacter seulement en cas d'urgence. Seul le supérieur des agents de la S.A.T. peut prendre le commandement.]],
			weapons = {"arrest_stick", "unarrest_stick", "weapon_stungun", "weapon_checker", "fas2_p226", "fas2_famas", "stunstick", "door_ram"},
			command = "satagent",
			max = 6,
			salary = 160,
			admin = 0,
			vote = true,
			hasLicense = true,
			NeedToChangeFrom = TEAM_POLICE,
			CanPlayerSuicide = function(ply) return false end,
			candemote = true,
			category = "Protections Publics",
			PlayerDeath = function(ply, weapon, killer)
				ply:teamBan()
				ply:changeTeam(GAMEMODE.DefaultTeam, true)
			end
		})
		
		TEAM_SATLEADER = DarkRP.createJob("Leader Anti-Terroriste", {
			color = Color(0, 0, 0, 255),
			model = {
				"models/player/PMC_1/PMC__01.mdl",
				"models/player/PMC_4/PMC__01.mdl",
				"models/player/PMC_5/PMC__01.mdl"},
			description = [[La S.A.T. (Section Anti-Terrorisme) est là pour intervenir dans les opérations les plus risqués pour la justice. Les agents de la S.A.T. doivent être contacter seulement en cas d'urgence. Seul le supérieur des agents de la S.A.T. peut prendre le commandement.]],
			weapons = {"arrest_stick", "unarrest_stick", "weapon_stungun", "weapon_checker", "fas2_glock20", "fas2_famas", "stunstick", "door_ram"},
			command = "satleader",
			max = 1,
			salary = 200,
			admin = 0,
			vote = true,
			hasLicense = true,
			category = "Protections Publics",
			chief = true,
			CanPlayerSuicide = function(ply) return false end,
			candemote = true,
			NeedToChangeFrom = {TEAM_SAT, TEAM_COMMISSAIRE},
			PlayerDeath = function(ply, weapon, killer)
				ply:teamBan()
				ply:changeTeam(GAMEMODE.DefaultTeam, true)
				if killer:IsPlayer() then
					for k, v in pairs (player.GetAll()) do
					DarkRP.talkToPerson(ply, Color(0, 0, 0, 255), DarkRP.getPhrase("new"), Color(255, 255, 0, 255), "Le/La leader anti-terroriste a été tué(e).")
					PrintMessage( HUD_PRINTTALK, "Journal d'actualité: Le/La leader anti-terroriste a été tué(e)." )
					end
				else
					for k, v in pairs (player.GetAll()) do
					PrintMessage( HUD_PRINTTALK, "Journal d'actualité: Le/La leader anti-terroriste est mort(e)." )
					end
				end
			end
		})
		
		GAMEMODE.CivilProtection = {
		[TEAM_POLICE] = true,
		[TEAM_COMMISSAIRE] = true,
		[TEAM_SAT] = true,
		[TEAM_SATLEADER] = true,
		}
	else
	DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_x", "commissaire", "effectuer cette action"))
	end
end
DarkRP.defineChatCommand("activesat", ActiveSAT)

ServeurDarkRP\steamapps\common\GarrysModDS\garrysmod\addons\darkrpmodification-master\lua\darkrp_modules\jobs\sh_declarecommand.lua :


DarkRP.declareChatCommand{
	command = "activesat",
	description = "Activer les anti-terroristes",
	delay = 1.5
}

when i connect to the server, my console game show :


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:151: attempt to call field 'defineChatCommand' (a nil value)
  1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:151
   2. doInclude - [C]:-1
    3. loadModules - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:86
     4. Call - gamemodes/darkrp/gamemode/libraries/modificationloader.lua:147
      5. unknown - gamemodes/darkrp/gamemode/cl_init.lua:53


and lately when police chief execute /activesat chat command the console of the server show this :


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:71: Tried to use a NULL entity!
  1. Team - [C]:-1
   2. callback - addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:71
    3. callback - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17
     4. RP_PlayerChat - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:78
      5. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:142

But I don’t find, understand this error in my coding
thank you in advance for your answers !

Are you trying to make it so the player has to be one job to get to the other?

I don’t fully 100% get what your trying to do

Yes, provided that if police chief use /activesat
Now I go to bed I would read your posts tomorrow, thank you!

why not just change your job to something like this



TEAM_SWATS = DarkRP.createJob("S.W.A.T Sniper", {
    color = Color(0, 0, 255, 255),
    model = {"models/player/swat.mdl"},
    description = [[You are a member of the S.W.A.T! You handle raids that the cops can't!]],
    weapons = {"tfa_csgo_flash", "tfa_csgo_smoke", "weapon_rad15", "unarrest_stick", "arrest_stick", "weaponchecker", "stunstick", "door_ram", "m9k_deagle", "m9k_intervention", "weapon_stungun", "breachingcharge", "weapon_cuff_police", "weapon_baloondie", "weapon_spiketrap"},
    command = "swats",
    max = 2,
    salary = 60,
    admin = 0,
    vote = true,
    hasLicense = true,
    NeedToChangeFrom = TEAM_SWAT,
})


adding this to the job



    NeedToChangeFrom = TEAM_SWAT,


That will make the job only show up for people that are TEAM_SWAT (change that to whatever you need)

Yes I now this option but the police chief has not execute /activesat chat command, excuse me if i’m harsh

No problem but i don’t believe you can make a chat command to add a job… darkrp does not work that way

The defineChatCommand error is simple. defineChatCommand is a serverside function only.

Ah, thanks I test your solution tomorrow, I would be careful to keep gouvernement jobs in clientside ! I’ll let you know

defineChatCommand is serverside, but declareChatCommand has to be ran shared (both inside a initialize hook)

I may be wrong, but I think that it would be better to create the team and use customCheck function to verify if “SAT Mode” is enabled.


 customCheck = function(ply) return sat end 

See http://wiki.darkrp.com/index.php/DarkRP:CustomJobFields

From there, you just have to create a command that would change sat boolean if the activator’s team is TEAM_COMMISSAIRE

ps : I speak french, feel free to contact me on steam.

thank you very much for your support but it remains a concern last : when i execute the command the server console show to me this error :


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:142: Tried to use a NULL entity!
  1. Team - [C]:-1
   2. callback - addons/darkrpmodification-master/lua/darkrp_modules/jobs/sh_job_gouvernement.lua:142
    3. callback - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17
     4. RP_PlayerChat - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:78
      5. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:142

in the 142 line have this :


	if ply.Team("TEAM_COMMISSAIRE") then

I have tested the callback but it did not work because TEAM_COMMISSAIRE isn’t an entity …
Can you help me for this please ? thanks

Between ply and Team there should be “:” instead of “.”.
Also, ply:Team funtion doesnt have any arguments, it just givea you the players team, so you should do:


if ply:Team() == TEAM_COMMISSAIRE then

Also, if the case was that the 1st argument of ply:Team like that it would still be wrong beacouse you are suplying a string, not the actual teams variable.

Ah thank you very much, I really am a noob: ')