Create and trigger new openShop hook on shop open#51
Conversation
|
So going over the conversation that took place in #🧩│scripting It seems like the decision was intentional, shops weren't planned to be included in the open inventory not being an inventory. The events are however handled on a lower level, it's triggered straight from within the meta object when the open method is called, same for closed inventory.
|
|
Just to make sure I've got the finer details clear, can you confirm this path forward? New
For the events, do we want to change them so that openInventory sends the id of the shop, or should it trigger a different new event?
Let me know what you think. New commit coming in soon with the new hook as described above. |
|
It would be a significant improvement if duty status were supported, similar to what's implemented in #41, though I realize that may not be feasible. Even if we use a hook to block shop access while off duty, the text labels, targets and blips still appear, which isn't ideal. |
I think that's a good idea, but a little out of scope for this PR. I want this PR to stay focused on the addition of a new hook, rather than changing the core functionality of the shops. |
| shopType = shop.type, | ||
| shopId = shop.id, | ||
| label = shop.name, | ||
| groups = shop.groups or shop.jobs, |
There was a problem hiding this comment.
shop.jobs will always be nil it's the internal parameter used by the inventory not the parameter made public that developers will interact with.
There was a problem hiding this comment.
local hookPayload = {
source = source,
id = shop.id, -- string <name index>
label = shop.label, -- string
slots = shop.slots, -- integer
items = shop.items, -- table
groups = shop.groups, -- table | nil
coords = shop.coords, -- vec3 | nil
distance = shop.distance -- float | nil
}New payload, tested and verified
There was a problem hiding this comment.
shop.distance isn't it number or false ? Iirc it's false when not using targeting.
Why did you annotate the other values being possibly nil ?
There was a problem hiding this comment.
distance just came back as nil in my tests. groups, coords, and distance might be nil if the hook is triggered by a shop created at runtime or if the fields aren't created. Here's some sample data I got from my test server.
[
{
"label": "Runtime Burger Shot",
"items": [
{
"weight": 100,
"name": "bs_bleeder",
"count": 0,
"price": 53,
"slot": 1
},
{ "weight": 100, "name": "bs_fries", "count": 0, "price": 25, "slot": 2 },
{
"weight": 100,
"name": "bs_heartstopper",
"count": 0,
"price": 50,
"slot": 3
},
{
"weight": 100,
"name": "bs_heartstopper_meal",
"count": 0,
"price": 80,
"slot": 4
},
{
"weight": 100,
"name": "bs_moneyshot",
"count": 0,
"price": 50,
"slot": 5
},
{
"weight": 100,
"name": "bs_moneyshot_meal",
"count": 0,
"price": 80,
"slot": 6
},
{
"weight": 100,
"name": "bs_nugget_meal",
"count": 0,
"price": 80,
"slot": 7
},
{
"weight": 100,
"name": "bs_nuggets",
"count": 0,
"price": 25,
"slot": 8
},
{
"weight": 100,
"name": "bs_torpedo",
"count": 0,
"price": 50,
"slot": 9
},
{
"weight": 100,
"name": "bs_torpedo_meal",
"count": 0,
"price": 80,
"slot": 10
},
{ "weight": 100, "name": "coffee", "count": 0, "price": 8, "slot": 11 },
{ "weight": 100, "name": "ecola", "count": 0, "price": 5, "slot": 12 },
{ "weight": 100, "name": "sprunk", "count": 0, "price": 5, "slot": 13 }
],
"slots": 13,
"id": "RuntimeBurgerShot 1",
"type": "shop"
},
{
"label": "Shop",
"items": [
{ "weight": 220, "name": "burger", "price": 10, "slot": 1 },
{ "weight": 500, "name": "water", "price": 10, "slot": 2 },
{ "price": 10, "name": "cola" }
],
"type": "shop",
"slots": 3,
"id": "General 1",
"coords": {
"x": 25.05999946594238,
"y": -1347.3199462890626,
"z": 29.70000076293945
},
"distance": 1.5
},
{
"groups": { "sasp": 0, "police": 0, "bcso": 0 },
"label": "Police Armoury",
"items": [
{ "weight": 7, "name": "ammo-9", "price": 5, "slot": 1 },
{ "weight": 4, "name": "ammo-rifle", "price": 5, "slot": 2 },
{ "weight": 125, "name": "WEAPON_FLASHLIGHT", "price": 200, "slot": 3 },
{ "weight": 1000, "name": "WEAPON_NIGHTSTICK", "price": 100, "slot": 4 },
{
"weight": 1130,
"name": "WEAPON_PISTOL",
"price": 500,
"metadata": { "registered": true, "serial": "POL" },
"license": "weapon",
"slot": 5
},
{
"weight": 3100,
"name": "WEAPON_CARBINERIFLE",
"price": 1000,
"metadata": { "registered": true, "serial": "POL" },
"grade": 3,
"license": "weapon",
"slot": 6
},
{
"weight": 227,
"name": "WEAPON_STUNGUN",
"price": 500,
"metadata": { "registered": true, "serial": "POL" },
"slot": 7
}
],
"coords": {
"x": 453.2099914550781,
"y": -980.030029296875,
"z": 31.43000030517578
},
"slots": 7,
"id": "PoliceArmoury 1",
"type": "shop",
"distance": 6
}
]There was a problem hiding this comment.
Ah those prints are just showing general shop data after adding them no ? It isn't printed from within the openShop callback ? What exactly are you printing ?
There was a problem hiding this comment.
These came from printing the shop object directly prior to triggering the new openShop hook.
Maximus7474
left a comment
There was a problem hiding this comment.
Requires some minor changes
|
Any status on this? Are there any changes that need to be made? |
|
Any status on this? Are there any changes that need to be made? It's been over 2 weeks without any movement, not sure if there's anything I need to do to get things moving again. Let me know. |
|
Please update docs with new hook type. |
Please reference this linked PR: |
|
Ready for review |
Trigger the
openInventoryhook when a shop is opened by the player.Additional Notes:
openedInventoryandclosedInventoryevents fire when a shop is opened/closed with only data pertaining to the player who is performing the action. It may be worth modifying these events to trigger with the data of the shop instead. Please let me know if you all agree. If so, I will extend this PR to also include those changes.