The server I work on has a hitman class. When a player who’s not a cop types this in the chat:
/hit <name> <reward amount>
ex: /hit Bobby 500
I want a thing to happen similar to the CP Wanted code. Only hitmen will know the person is targeted for a hit. I used the wanted code as a template. When the hitman kills the targeted player, he will recieve the reward amount and the person who ordered it will lose that much money. (when a normal person kills the target nothing will happen). I have added this code to gamemode/server/main.lua
local function PlayerHitted(ply, args)
if ply:IsCP() then
GAMEMODE:Notify(ply, 1, 6, string.format(LANGUAGE.police_cant_hit)) -- Cops can't order hits on people.
local tableargs = string.Explode(" ", args)
local reason = ""
if #tableargs == 1 then
GAMEMODE:Notify(ply, 1, 4, LANGUAGE.vote_specify_reward) -- Tells the player to set a reward if they don't
if not ply:Alive() then
GAMEMODE:Notify(ply, 1, 4, "You must be alive to request a hit") -- you can't order a hit when you're dead.
for i = 2, #tableargs, 1 do
reason = reason .. " " .. tableargs*
reason = string.sub(reason, 2)
if string.len(reason) > 22 then
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.unable, "/hit", "<23 chars"))
local p = GAMEMODE:FindPlayer(tableargs)
if p and p:Alive() and not p:isArrested() and not p.DarkRPVars.hitted then
hook.Call("PlayerHitted", GAMEMODE, ply, p, reason)
for a, b in pairs(player.GetAll()) do
if b:IsHitman then -- only happens if a player is hitman
b:PrintMessage(HUD_PRINTCENTER, string.format(LANGUAGE.wanted_by_police, p:Nick()).."
Reason: "..tostring(reason)) -- if you're a hitman it displays a message on your screen
if b:IsAdmin() then
b:PrintMessage( HUD_PRINTCONSOLE, ply:Nick() .. " has made " .. p:Nick() .. " wanted by police for " ..tostring(reason) ) -- Shows a message in the admins' consoles
timer.Create(p:UniqueID() .. " wantedtimer", GAMEMODE.Config.wantedtime, 1, function() TimerUnwanted(ply, p) end) -- Creates a timer to count down how long the player has the hit on them.
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.could_not_find, "player: "..tostring(args))) -- Happens if it can't find the player specified.
AddChatCommand("/hit", PlayerHitted) -- The command to order the hit
AddChatCommand("/hitid", PlayerHitted) -- Inspired by the /warrent for people not spelling write. You can rewrite so you can want like this: STEAM_0:0:29257121 stupid kid
local function PlayerUnHitted(ply, args)
if not ply:IsHitman() then
GAMEMODE:Notify(ply, 1, 6, string.format(LANGUAGE.must_be_x, "hitman", "/unhit"))
local p = GAMEMODE:FindPlayer(args)
if p and p:Alive() and p.DarkRPVars.hitted then
hook.Call("PlayerUnHitted", GAMEMODE, ply, p)
for a, b in pairs(player.GetAll()) do
b:PrintMessage(HUD_PRINTCENTER, string.format(LANGUAGE.hit_expired, p:Nick()))
timer.Destroy(p:UniqueID() .. " wantedtimer")
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.could_not_find, "Player: "..tostring(args)))
AddChatCommand("/unhitid", PlayerUnWanted) -- Can also do like /wantid but for now it's also for grammar mistakes made by people.
local function HitComplete(victim, weapon, killer)
if killer:isHitman() then
if p.DarkRPVars.hitted then
hook.add("PlayerDeath", "playerDeathTest", HitComplete)
and this code to gamemode/shared/language.lua
police_cant_hit = "You can't order hits as a cop!",
vote_specify_reward = "You must specify a reward...",
hit_expired = "The hit on %s has expired"
Problem is, when it’s run on the server I receive this error:
[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:86: attempt to index global ‘LANGUAGE’ (a nil value)
- DrawInfo - gamemodes/darkrp/gamemode/client/hud.lua:86
- DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:226
3. unknown - gamemodes/darkrp/gamemode/client/hud.lua:338
What have I done wrong?
NOTE: I’m a complete noob at lua so try to take it easy on me
[editline]3rd December 2012[/editline]
Edit: I think the very last line in the language.lua part needs a comma at the end. Could that be what’s causing this error?