SetHorseOwner
Makes a horse a player’s - or nobody’s.
The owner’s horse is theirs in the game on their screen (its saddlebags in their inventory, the plain “Mount”) and its
saddlebags hold their things whoever simulates it; they go to the new owner here, gone from the last one’s records. Anyone
else gets on it as a thief (OnPlayerStealHorse). A horse made for a player (CreateHorse with a pid, the /horse
built-in) is theirs from the start; nil makes it nobody’s - then its bags go with whoever simulates it. A player may own
several horses; the game shows one of them as “your horse” (the newest). The owner leaving the server makes it nobody’s -
after OnPlayerDisconnect, where it is still theirs: the place to save it or take it out of the world.
Syntax
Section titled “Syntax”SetHorseOwner(id [, pid])| Parameter | Type | |
|---|---|---|
id |
number | the horse |
pid |
number | the new owner; nil = nobody (optional) |
Returns
Section titled “Returns”boolean - false when it is not a horse
Example
Section titled “Example”-- /buyhorse at the stable: the horse standing there becomes the buyer's once paidlocal PRICE = 250function OnPlayerCommandText(pid, cmd, args) if cmd ~= "buyhorse" then return false end local horse = GetNearestEntity(pid, ENTITY_HORSE, 5) if not horse or GetHorseOwner(horse) then SendClientMessage(pid, COLOR_RED, "No horse for sale here.") return true end if GetPlayerMoney(pid) < PRICE then SendClientMessage(pid, COLOR_RED, "It costs " .. PRICE .. " Groschen.") return true end GivePlayerMoney(pid, -PRICE) SetHorseOwner(horse, pid) return trueendSee also
Section titled “See also”GetHorseOwner · GetPlayerHorses · OnPlayerStealHorse · CreateHorse · the Horses group of the index
