Skip to content

Commit

Permalink
Merge pull request #8 from Patrick2562/add-some-exports
Browse files Browse the repository at this point in the history
Add some exports
  • Loading branch information
Patrick2562 authored Jul 2, 2022
2 parents 71900b9 + 876f203 commit 3631b3b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ bool isAttached(element Element)
**Returns:** Returns true if element is already attached, false otherwise.


## **setDetails**
\- This function set details of attached element.

```
bool setDetails(element Element [, element Ped = currentPed, int/string Bone = currentBone, float xPosOffset = currentXPosOffset, float yPosOffset = currentYPosOffset, float zPosOffset = currentZPosOffset, float xRotOffset = currentXRotOffset, float yRotOffset = currentYRotOffset, float zRotOffset = currentZRotOffset])
```

| Required arguments | Description |
| :----------------- | :------------------------------------------------------------------------------------------------------------ |
| **Element** | The element which you want to update. |

*NOTE: Use 'false' if you don't want to modify the current value.*
| Optional arguments | Description |
| :----------------- | :------------------------------------------------------------------------------------------------------------ |
| **Ped** | New ped or player which you want to attach element to. |
| **Bone** | New number (or name what you can find below) of the ped or player's bone which you want to attach element to. |
| **xPosOffset** | New X position offset. |
| **yPosOffset** | New Y position offset. |
| **zPosOffset** | New Z position offset. |
| **xRotOffset** | New X rotation offset. |
| **yRotOffset** | New Y rotation offset. |
| **zRotOffset** | New Z rotation offset. |

**Returns:** Returns true if details was successfully changed, false otherwise. (only on client side)


## **getDetails**
\- This function gets details of attached element.

Expand All @@ -153,6 +179,36 @@ table getDetails(element Element)
**Returns:** Returns table with details (value order same as attach function's parameters, starts from Ped) if element exists and attached, false otherwise.


## **setPed**
\- This function set ped or player which you want to attach element to.

```
bool setPed(element Element, element Ped)
```

| Required arguments | Description |
| :----------------- | :----------------------------------------------------- |
| **Element** | Element which you want to update. |
| **Ped** | The ped or player which you want to attach element to. |

**Returns:** Returns true if ped was successfully changed, false otherwise. (only on client side)


## **setBone**
\- This function set bone which you want to attach element to.

```
bool setBone(element Element, int/string Bone)
```

| Required arguments | Description |
| :----------------- | :------------------------------------------------------------------------------------------------------------ |
| **Element** | Element which you want to update. |
| **Bone** | The number (or name what you can find below) of the ped or player's bone which you want to attach element to. |

**Returns:** Returns true if bone was successfully changed, false otherwise. (only on client side)


## **getAttacheds**
\- This function get attached elements which is attached to ped or player.

Expand Down
39 changes: 39 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@ pAttach = {
return (element and self.instances[element]) and true or false
end,

setDetails = function(self, element, ped, _boneid, ox, oy, oz, rx, ry, rz)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
if not self:isAttached(element) then return false end

local details = self:getDetails(element)

if ped then self:setPed(element, ped) end
if _boneid then self:setBone(element, _boneid) end
self:setPositionOffset(element, ox or details[4], oy or details[5], oz or details[6])
self:setRotationOffset(element, rx or details[7], ry or details[8], rz or details[9])
return true
end,

getDetails = function(self, element)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
if not self:isAttached(element) then return false end
Expand Down Expand Up @@ -186,6 +199,32 @@ pAttach = {
return true
end,

setBone = function(self, element, _boneid)
local boneid = boneIDNames[_boneid] or tonumber(_boneid) or false
assert(isElement(element), "Expected element at argument 1, got "..type(element))
assert(boneid and boneIDs[boneid], "Expected valid bone-id or bone-name at argument 2, got "..tostring(_boneid)..". Check available bones in README.md")
if not self:isAttached(element) then return false end

local ped = self.instances[element]
local ins = self.pedInstances[ped].list[element]

ins._boneid = _boneid
ins.boneid = boneid
return true
end,

setPed = function(self, element, ped)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
assert(isElement(ped), "Expected element at argument 2, got "..type(ped))
if not self:isAttached(element) then return false end

local details = self:getDetails(element)

self:detach(element)
self:attach(element, ped, details[3], details[4], details[5], details[6], details[7], details[8], details[9])
return true
end,

invisibleAll = function(self, ped, bool)
assert(isElement(ped), "Expected element at argument 1, got "..type(ped))

Expand Down
46 changes: 46 additions & 0 deletions exports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ if isClientSide then
addEvent("pAttach:setRotationOffset", true)
addEventHandler("pAttach:setRotationOffset", resourceRoot, setRotationOffset)

function setPed(...)
return pAttach:setPed(...)
end
addEvent("pAttach:setPed", true)
addEventHandler("pAttach:setPed", resourceRoot, setPed)

function setBone(...)
return pAttach:setBone(...)
end
addEvent("pAttach:setBone", true)
addEventHandler("pAttach:setBone", resourceRoot, setBone)

function invisibleAll(...)
return pAttach:invisibleAll(...)
end
Expand All @@ -54,6 +66,10 @@ if isClientSide then
return pAttach:isAttached(...)
end

function setDetails(...)
return pAttach:setDetails(...)
end

function getDetails(...)
return pAttach:getDetails(...)
end
Expand Down Expand Up @@ -103,6 +119,21 @@ else
return triggerClientEvent("pAttach:setRotationOffset", resourceRoot, element, x, y, z)
end

function setPed(element, ped)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
assert(isElement(ped), "Expected element at argument 2, got "..type(ped))

cache[element][2] = ped
return triggerClientEvent("pAttach:setPed", resourceRoot, element, ped)
end

function setBone(element, boneid)
assert(isElement(element), "Expected element at argument 1, got "..type(element))

cache[element][3] = boneid
return triggerClientEvent("pAttach:setBone", resourceRoot, element, boneid)
end

function invisibleAll(ped, bool)
for element, data in pairs(cache) do
if data[2] == ped then
Expand All @@ -117,6 +148,21 @@ else
return cache[element] and true or false
end

function setDetails(element, ped, boneid, ox, oy, oz, rx, ry, rz)
assert(isElement(element), "Expected element at argument 1, got "..type(element))

local details = getDetails(element)

cache[element] = {
element,
ped or details[2],
boneid or details[3],
ox or details[4], oy or details[5], oz or details[6],
rx or details[7], ry or details[8], rz or details[9]
}
return triggerClientEvent("pAttach:setDetails", resourceRoot, element, ped, boneid, ox, oy, oz, rx, ry, rz)
end

function getDetails(element)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
return cache[element] or false
Expand Down
3 changes: 3 additions & 0 deletions meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<export function="detachAll" type="shared" />
<export function="setPositionOffset" type="shared" />
<export function="setRotationOffset" type="shared" />
<export function="setPed" type="shared" />
<export function="setBone" type="shared" />
<export function="isAttached" type="shared" />
<export function="setDetails" type="shared" />
<export function="getDetails" type="shared" />
<export function="invisibleAll" type="shared" />
<export function="getAttacheds" type="shared" />
Expand Down

0 comments on commit 3631b3b

Please sign in to comment.