Skip to content

SetPlayerThirdPerson

Gives a player the third-person view - or keeps them in first person.

The third-person view is the game’s own camera behind the player, so nobody needs a camera mod for it. "off" keeps the player in first person (one looking from behind goes back to first person at once). "allow" lets them switch with their third-person key - F3 unless they changed it in the launcher’s options - and the view they had is kept. "force" puts them in third person and the key does nothing. true is "allow", false and nil are "off", and the words may be written in any case.

Two more rules say where the view gives way to first person. With inFights set to false the player’s game goes to first person while they fight with a sword, an axe or fists, and with whenAiming set to false while a bow, a crossbow or a gun is drawn; each goes back to third person when the fight or the aiming ends. While a bow, a crossbow or a gun is in the player’s hands in third person an aiming dot shows at the centre of the screen; crosshair set to false keeps it off (first person always keeps the game’s own look, without a dot). Left out, or nil, all three are true: third person stays on there and the dot shows. Each call sets the whole rule, so a call that changes only the mode passes the three again.

It lasts until you change it or the player leaves; every visit starts with "off", third person kept on in fights and when aiming and the dot on, so a mode that wants the view sets it when the player connects (OnPlayerConnect). The game’s own camera still takes over in a dialogue, in a menu and in a minigame; riding a horse keeps the view, and so do fighting and aiming unless a rule above says first person (while aiming in third person the camera moves over the player’s shoulder and the shot flies to the crosshair). It is a setting of KCD:MP’s own camera: a camera mod a player runs themselves is not stopped by it.

The shipped game modes keep this rule in a CAMERA table at the top of their script and set it in OnPlayerConnect, as the example below does: freeroam and BasicRP use "allow", the duel arena "off". Change the table to change the view.

SetPlayerThirdPerson(pid, mode [, inFights, whenAiming, crosshair])
Parameter Type
pid number the player
mode string | boolean | nil "off", "allow" or "force"; true for "allow", false or nil for "off"
inFights boolean | nil false keeps the player in first person while they fight with a sword, an axe or fists; true or nil (the default) keeps third person on (optional)
whenAiming boolean | nil false keeps the player in first person while a bow, a crossbow or a gun is drawn; true or nil (the default) keeps third person on (optional)
crosshair boolean | nil false keeps the aiming dot off in third person; true or nil (the default) shows it while a bow, a crossbow or a gun is in the hands (optional)

boolean - true, or false and the reason ("Not connected.", or the three words when mode is none of them)

-- the one place the mode's camera rule lives
local CAMERA = {
third_person = "allow", -- "off", "allow" or "force"
in_fights = true, -- false: first person while fighting with a sword, an axe or fists
when_aiming = false, -- false: first person while a bow, a crossbow or a gun is drawn
crosshair = true, -- false: no aiming dot in third person
}
function OnPlayerConnect(pid)
SetPlayerThirdPerson(pid, CAMERA.third_person, CAMERA.in_fights, CAMERA.when_aiming, CAMERA.crosshair)
end
-- /view off|allow|force: a player picks their own view; the rules stay as they are
function OnPlayerCommandText(pid, cmd, args)
if cmd == "view" then
local _, inFights, whenAiming, crosshair = GetPlayerThirdPerson(pid)
local ok, reason = SetPlayerThirdPerson(pid, args, inFights, whenAiming, crosshair)
SendClientMessage(pid, COLOR_SERVER, ok and ("The third-person view is " .. GetPlayerThirdPerson(pid) .. ".") or reason)
return true
end
end

GetPlayerThirdPerson · OnPlayerConnect · OnPlayerCommandText · the Players group of the index