Jump to content

bone_attach not visible to everyone


Recommended Posts

local Me = getLocalPlayer() 
backpack = createObject(371,0,0,-111)
hat = createObject(954, 0, 0, -111)
exports.bone_attach:attachElementToBone(backpack,Me,3,0,-0.15,-0.0,0,0,0)
exports.bone_attach:attachElementToBone(hat,Me,1,0,0.05,-0.56,0,0,0)

the objects attached to the player are only visible to me, not my friend that is on the server. help?

( he sees them too but on his character)

Link to comment

Your file is on client side. Change it to server side.

On your meta.xml change it to.
<script src="server.lua" type="server"/>

server.lua

local backpack = {}
local hat = {}
function attachBackpackAndHatToPlayer(player)
if isElement(player) and getElementType(player) == "player" then
if isElement(backpack[player]) and isElement(hat[player]) then
destroyElement(backpack[player])
backpack[player] = nil
destroyElement(hat[player])
hat[player] = nil
else
local resource = getResourceFromName("bone_attach") -- returns the resource named bone_attach --
local state = getResourceState(resource) -- checks the resource status --
if tostring(state) == "running" then -- checks if the bone_attach resource is running to continue --
backpack[player] = createObject(371, 0, 0, -111)
hat[player] = createObject(954, 0, 0, -111)
exports.bone_attach:attachElementToBone(backpack[player], player, 3, 0, -0.15, -0.0, 0, 0, 0)
exports.bone_attach:attachElementToBone(hat[player], player, 1, 0, 0.05, -0.56, 0, 0, 0)
else
outputChatBox("Ask an admin to start the 'bone_attach' resource to use this command.", player, 0, 255, 0, false)
end
end
end
end
addCommandHandler("backpack", attachBackpackAndHatToPlayer)

 

Link to comment
2 minutes ago, SARSRPG said:

Your file is on client side. Change it to server side.

On your meta.xml change it to.
<script src="server.lua" type="server"/>

server.lua


local backpack = {}
local hat = {}
function attachBackpackAndHatToPlayer(player)
if isElement(player) and getElementType(player) == "player" then
if isElement(backpack[player]) and isElement(hat[player]) then
destroyElement(backpack[player])
backpack[player] = nil
destroyElement(hat[player])
hat[player] = nil
else
local resource = getResourceFromName("bone_attach") -- returns the resource named bone_attach --
local state = getResourceState(resource) -- checks the resource status --
if tostring(state) == "running" then -- checks if the bone_attach resource is running to continue --
backpack[player] = createObject(371, 0, 0, -111)
hat[player] = createObject(954, 0, 0, -111)
exports.bone_attach:attachElementToBone(backpack[player], player, 3, 0, -0.15, -0.0, 0, 0, 0)
exports.bone_attach:attachElementToBone(hat[player], player, 1, 0, 0.05, -0.56, 0, 0, 0)
else
outputChatBox("Ask an admin to start the 'bone_attach' resource to use this command.", player, 0, 255, 0, false)
end
end
end
end
addCommandHandler("backpack", attachBackpackAndHatToPlayer)

 

make it as simple as the script I sent xD

Link to comment

That is as simple as it can be.

Its just that on client, all the tables aren't quite necessary because its only made for the client that is calling the function. On server, it calls for everyone, so you've to make it specifically for the player who called it. Hence the tables made, backpack[player] and hat[player], etc.

Forgot to mention, try the script, I'm sure it'll work.

Link to comment
2 minutes ago, SARSRPG said:

That is as simple as it can be.

Its just that on client, all the tables aren't quite necessary because its only made for the client that is calling the function. On server, it calls for everyone, so you've to make it specifically for the player who called it. Hence the tables made, backpack[player] and hat[player], etc.

Forgot to mention, try the script, I'm sure it'll work.

works, ty

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...