[Working] Call APB on another player

Finally got it working, this script allows you to type /apb followed by a player id in order to give another player (or yourself) a 2 star wanted level + a notification.

next step would be to restrict it to either cops as a form of backup, or admins as a punishment.

code:

-- Server side APB script

AddEventHandler('chatMessage', function(source, n, message) -- capture 'chatMessage' events
  local args = stringsplit(message, " ") -- Split the message up into an array of words

  if (args[1] == "/apb") then -- if the first "word" is /apb
    CancelEvent() -- dont pass this chat message further, we're handling it

    if (args[2] ~= nil) then -- make sure we have an actual second "word"
      local playerID = tonumber(args[2]) -- Store the playerID that was passed, as a number

      -- If this is not a valid player
      if (playerID < 1 or playerID > 32) then
        -- tell the sender they have an invalid target
        TriggerClientEvent('chatMessage', source, "SYSTEM", {200, 0, 0}, "Invalid PlayerID!")
        return -- dont continue any further
      end

      -- at this point we should have a valid PlayerID to target, so lets send him an apb
      TriggerClientEvent('mAPB', playerID) -- Sends event 'mAPB' to playerID
    else -- if args[2] does equal nil (doesnt exist)
      local event = 'chatMessage' -- What event are we sending
      local eventTarget = source -- Who do we send the event too (-1 means all)
      local messageSender = "SYSTEM" -- Message sender
      local messageSenderColor = {200, 0, 0} -- Message sender color
      local message = "Usage: /APB <PlayerID>" -- show a `how-to-use` message
      -- This could be shortened into just one line, it was exanded to show what each parameter does
      TriggerClientEvent(event, eventTarget, messageSender, messageSenderColor, message) -- send the event
      -- NOTE: the variables after "eventTarget" will be passed to the event handlers function
      -- you will see in cl_handcuffs.lua, that the 'mHandCuff' event does not take any arguements
      -- hence why it is sent above with only the event name and target ID
    end
  end
end)

-- utility function to turn a string into an array of words
function stringsplit(self, delimiter)
  local a = self:Split(delimiter)
  local t = {}

  for i = 0, #a - 1 do
     table.insert(t, a[i])
  end

  return t
end

-- client side APB script

RegisterNetEvent('mAPB') -- register that this is a valid event

AddEventHandler('mAPB', function()
    
	Citizen.CreateThread(function() -- create a thread

	    TriggerEvent("chatMessage", "", { 0, 0, 0 }, "An APB Has been declared on you,+2 Wanted level.")
        SetPlayerWantedLevel(PlayerId(-1), 2, 0)
		SetPlayerWantedLevelNow(PlayerId(-1), 0)
	end)

end)



What would I need to change in this script if I wanted to only put out a notification and not have a two star wanted level? Any help would be greatly appreciated!

Remove setting the wanted level in the client script.

So just to check… (Because I an not seeing where it gives you stars) To take out the level I just remove setplayerwantedlevel or setplayerwantedlevelnow? or both? lol

can you try and add this to cops fivem if you can?

Take out both of them. Those set the wanted level… as the function even says.

1 Like

I’m not sure what that is, if it’s a gametype or server I can’t really do much but if you’re asking if you can implement this on something other than es-skater or es-hipster the answer is yes