tr-properties keeps the ownership, keys and doors; your script adds what's specific to it. tr-housing and tr-ranching are built this way.
Server exports¶
local props = exports["tr-properties"]
| Export | Returns | What it does |
|---|---|---|
register(id, data) |
Adds a property, in the same format as the config. | |
get(id) |
table or nil |
label, type, price, coords, lockable, storage, owner, locked, plus area and animals. |
getOwner(id) |
{ kind, id } or nil |
kind is "char" or "job". |
getOwned(kind, ownerId) |
list of ids | Every property a character or job owns. |
getForSale(type?) |
list of ids | Unowned properties with a price, optionally of one type. |
hasAccess(src, id, ignoreLock?) |
boolean |
Owner, job member, master job or a fitting key. |
isOwner(src, id) |
boolean |
The owning character, or a member of the owning job. |
setLocked(id, locked, hash?) |
boolean |
Locks or unlocks one door, or every door without a hash. |
purchase(src, id) |
ok, err |
Charges the price and gives the property and key, with all the usual checks. |
transfer(id, owner, src?) |
boolean |
Gives the property to owner ({ kind, id }). src gets the new key. |
release(id) |
boolean |
Puts the property back on the market. |
giveKey(src, id) |
key serial or false |
A key to the current lock. false if not owned or no room. |
changeLocks(id, src) |
ok, err |
A new lock, with its first key to src. Keeps the old lock if the key doesn't fit. |
setProvider(name, value) |
Takes over part of the script. See Providers. |
Client exports¶
| Export | What it does |
|---|---|
get(id) |
The property as the client sees it (label, doors and their lock states, storage, blip...). |
canAccess(id) |
Asks the server whether this player can get in. |
addStorageOption(type, label, key, onSelect) |
Adds a prompt next to Open Storage for every property of a type. onSelect(id) runs when it's pressed. |
hideStorage(hidden) |
Hides the storage prompt, e.g. while a menu opened from it is up. |
exports["tr-properties"]:addStorageOption("house", "Open Wardrobe", "INPUT_INTERACT_OPTION2", function(id)
OpenWardrobe()
end)
Storage options are lost when tr-properties restarts. Add them again on onClientResourceStart:
AddEventHandler("onClientResourceStart", function(resource)
if resource == "tr-properties" then
addOptions()
end
end)
Events¶
Server events, for scripts that react to properties:
| Event | Arguments | When |
|---|---|---|
tr-properties:ownerChanged |
id, owner, previous |
Bought, transferred or released. owner is nil when released. |
tr-properties:lockChanged |
id, locked, hash |
A door (or every door, hash = nil) was locked or unlocked. |
tr-properties:storageOpened |
src, id |
A player opened a property's storage with a key. |
tr-properties:lockpicked |
src, id, hash, success, target |
A lockpick attempt. target is "door" or "storage"; hash is nil for storage. |
Providers¶
A provider replaces one part of the script. Set it from your script when it starts:
exports["tr-properties"]:setProvider("sale", "external") -- no buying at the door
| Provider | Default | What it does |
|---|---|---|
sale |
"door" |
"external" turns off the buy prompt, for scripts that sell properties themselves (e.g. a government office calling purchase). |
pay |
cash | function(src, amount): take the price. Return true if paid. |
refund |
cash | function(src, amount): give the price back when a purchase can't finish. |
Set sale back to "door" when your script stops, so properties can still be bought.