Jump to content

Building


redditing

Recommended Posts

function building(key, state)
	local x, y, z = getElementPosition(getLocalPlayer())
	local build = createObject(3374, x, y, z, 0, 0, 0)
	setElementAlpha(build, 150)
	attachElements(build, localPlayer , 0, 3, -1, 0, 0, 0)
	if key=="b" and state=="up" then
		if isElementAttached(build) then
			setElementAlpha(build, 255)
			detachElements(build, getLocalPlayer())
		end
	end
end

bindKey("b", "both", building)

 

When I release B, he puts a block of hay for me, but I don't lose the stick which stuck to me, PLS HELP

Link to comment

 

local player = getLocalPlayer();

local build
function building(key, state)
	if (key == "b") then -- check Key pressed
        	if (state == "down") then -- check state
            		destroy(build) -- useful
			local x, y, z = getElementPosition(player);
			build = createObject(3374, x, y, z, 0, 0, 0);
			setElementAlpha(build, 150);
			attachElements(build, player , 0, 3, -1, 0, 0, 0);
		elseif (state =="up") then -- check state
			if isElementAttached(build) then
				setElementAlpha(build, 255);
				detachElements(build, player);
                		setTimer(function() destroy(build) end, 1500, 1); 
			end
		end
	end
end
bindKey("b", "both", building)

function destroy(element) -- useful function
    if isElement(element) then -- if exists
        destroyElement(element) -- destroy
    end
end

 

Edited by Developer.
I forgot some things
Link to comment
  • Moderators

Because first time, when you press it down, the function stops in line 6, and leave.

Second time, when you release the button, it starts from the beginning, again. (create again the object) But then, it not stop in line 6, and immediately deatach the new object. And old object is still attached to you.

Edited by Patrick
Link to comment
22 hours ago, Patrick said:

Because first time, when you press it down, the function stops in line 6, and leave.

Second time, when you release the button, it starts from the beginning, again. (create again the object) But then, it not stop in line 6, and immediately deatach the new object. And old object is still attached to you.

I love u man

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