Jump to content

Question


Bean666

Recommended Posts

I made a simple hat script that attaches to a player, but there's a question for me since i made this serverside and i have the onPlayerWasted on root

if he dies, will it remove other people's hat too since the player wasted is on root? or will it remove only his hat?

if it does, how do i make it when a player dies only his hat gets removed?

do i need to switch to client side? or am I missing something

addCommandHandler("hat", function(p)
object = createObject(2053, 0, 0, 0)
local id = getElementModel ( p ) 
outputChatBox("test")
    if id == 0 then
    exports.bone_attach:attachElementToBone(object, p, 2, 0.01, -0.02, -0.48, 0, 0,110)
end
   if id == 287 then
   exports.bone_attach:attachElementToBone(object, p, 2, 0, -0.01, -0.45, 0, 0,100)
end
 if id == 285 then
 exports.bone_attach:attachElementToBone(object, p, 2, 0.005, -0.01, -0.45, 0, 0,100)
  end
end
);

addEventHandler( "onPlayerWasted", root,
	function()
destroyElement(object)
	end
)

 

Link to comment
  • Moderators
2 hours ago, Shaman123 said:

if he dies, will it remove other people's hat too since the player wasted is on root? or will it remove only his hat?

All players.

There is only 1 serverside, since there is only 1 server.

There can be multiple clientside(s), since there are multiple clients/players.

 

A table will help to manage which player wears which hat:

local hats = {}

addCommandHandler("hat", function(p)

	local hat = createObject(2053, 0, 0, 0)
	hats[p] = hat

	local id = getElementModel ( p ) 

	if id == 0 then
		exports.bone_attach:attachElementToBone(hat, p, 2, 0.01, -0.02, -0.48, 0, 0,110)
	elseif id == 287 then
		exports.bone_attach:attachElementToBone(hat, p, 2, 0, -0.01, -0.45, 0, 0,100)
	elseif id == 285 then
		exports.bone_attach:attachElementToBone(hat, p, 2, 0.005, -0.01, -0.45, 0, 0,100)
	end
end
);


function removeHat ()
	local hat = hats[source]
	if hat then
		hats[source] = nil
		if isElement(hat) then
			destroyElement(hat)
		end
	end
end
addEventHandler( "onPlayerWasted", root, removeHat)
addEventHandler( "onPlayerQuit", root, removeHat)

 

 

 

 

 

 

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...