Jump to content

[HELP] I don't know why this won't work


MGO

Recommended Posts

Hi guys, I'm having trouble with the following code for my RP server
the purpose of this is to take badge item from player and give key item instead but only in the area that I specified which is the flying zone, the whole script works fine except this part, I want it to exchange the badge for the key but if the player doesn't have the badge it will send a message saying you don't have any badges and if the exchange is made it will say you gave the badge so here's the code that I'm having trouble with :
Client :
 

bindKey( "E", "down", function()
		if getElementData(localPlayer, "Jobs") == "Dealer" then
		local detection = isElementWithinColShape ( localPlayer, Col )
		if not( detection ) then return outputChatBox("#ffffff[ #FC861DFly-System#ffffff ] : You must be inside the flying zone.",255,255,255,true) end
		local nobadge = triggerServerEvent("NoBadge", localPlayer )
		if not( nobadge ) then
		setPedAnimation(localPlayer, "BOMBER", "BOM_Plant", -1, false, false, false, false)
		triggerServerEvent("TakeBadgefromPlayer", localPlayer )
		setTimer (function()
		local x, y, z = getElementPosition(localPlayer)
		local Object =  createObject ( 677, x,y,z-1 )
		outputChatBox("#ffffff[ #FC861DFly System#ffffff ] : You gave the badge.",255,255,255,true)
		setTimer(function(Object)
		if ( isElement(Object) ) then 
		destroyElement(Object)
		triggerServerEvent("GivekeytoPlayer", localPlayer )
		end
		end, 6000, 1,Object)
		end, 2000, 1) 
		end
	end
end
)

Server :
 

addEvent("TakeBadgefromPlayer", true)  -- Give Badge.
addEventHandler("TakeBadgefromPlayer", root,
	function()
		if exports.global:hasItem(client, 285)
			then
				exports.global:takeItem(client, 285)	
			else
				outputChatBox("#ffffff[ #FC861DFly-System#ffffff ] : You don't have enough badges.",source,255, 255, 255,true)	
		end
	end
)

addEvent("GiveKeytoPlayer", true)  -- Receive Key.
addEventHandler("GiveKeytoPlayer", root,
	function()
	exports.global:giveItem(client, 33, 10)
	outputChatBox("#ffffff[ #FC861DFly-System#ffffff ] : You got 10 keys",source,255,255,255,true)
	end
)

addEvent("Nobadge", true)  -- Don't have Badge.
addEventHandler("Nobadge", root,
	function()
		if not (exports.global:hasItem(client, 285))then
			outputChatBox("#ffffff[ #FC861DFly-System#ffffff ] : You don't have any badges.",source,255,255,255,true)
		end
	end
)

 

Link to comment

Client:

bindKey("e", "down", function()
    local getJob = getElementData(localPlayer, "Jobs") or "NONE"
    if getJob == "Dealer" then
       if not isElementWithinColShape(localPlayer, Col) then
          return outputChatBox("You must be inside the farming zone", 255, 255, 255, true)
       end
       if not exports.global:hasItem(localPlayer, 285) then return end
       if TSK == false then return end
       TSK = false
       setPedAnimation(localPlayer, "BOMBER", "BOM_Plant", -1, false, false, false, false)
       triggerServerEvent("TakeSeedfromPlayer", localPlayer)
       setTimer(function()
         local x, y, z = getElementPosition(localPlayer)
         local Object = createObject(677, x, y, z - 1)
         outputChatBox("You planted seed", 255, 255, 255, true)
         TSK = true
         setTimer(function()
           if isElement(Object) then
              destroyElement(Object)
              triggerServerEvent("GiveDrugtoPlayer", localPlayer)
           end
         end, 6000, 1)
       end, 2000, 1)
    end
end)

Server:
 

addEvent("TakeSeedfromPlayer", true)
addEventHandler("TakeSeedfromPlayer", root, function(takeseed)
    if exports.global:hasItem(source, 285) then
       exports.global:takeItem(source, 285)
    else
       outputChatBox("#ffffff[ #FC861DDrug-System#ffffff ] : You don't have enough seeds.",source,255, 255, 255,true)
    end
end)

The problem was solved on discord, so I think this topic can be closed

Edited by Hydra
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...