Jump to content

Weed [Script] Help


Recommended Posts

function clickPlant(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) 
    if button == 'left' and state == 'down' then 
            local px, py, pz = getElementPosition(localPlayer) 
            for i,v in ipairs(getElementsByType("object")) do 
            if getElementData(v, "dbid") then 
                if getElementData(v, "hours") then 
                local x, y, z = getElementPosition(v) 
                local distance = getDistanceBetweenPoints3D(x, y, z, worldX, worldY, worldZ) 
                if distance <= 0.3 then  
                    stage = getElementData(v, "stage") 
                    harvest = getElementData(v, "harvest") 
                    dbid = getElementData(v, "dbid") 
                    cCheckPlant() 
                end 
                end 
            end 
        end 
    end 
end 
addEventHandler('onClientClick', root, clickPlant) 
  
local checkPlantGUI = nil 
  
function cCheckPlant() 
    if checkPlantGUI == nil then 
     
    checkPlantGUI = checkPlantGUI 
     
    local lplayer = getLocalPlayer() 
     
    local width, height = 150, 175 
    local scrWidth, scrHeight = guiGetScreenSize() 
    local x = scrWidth/2 - (width/2) 
    local y = scrHeight/2 - (height/2) 
  
    plantWindow = guiCreateWindow(x, y, width, height, "Cannabis Plant - Stage: " .. stage .. "", false) 
     
    local width2, height2 = 10, 10 
    local x = scrWidth/2 - (width2/2) 
    local y = scrHeight/2 - (height2/2) 
     
    harvest = guiCreateLabel(0.1, 0.1, 0.75, 0.30, "Current Harvest: ".. harvest .."gram(s)", true, plantWindow) 
    guiLabelSetHorizontalAlign(harvest, "center", true) 
    guiLabelSetVerticalAlign(harvest, "center") 
     
    --Buttons 
    pick = guiCreateButton(0.1, 0.4, 0.75, 0.30, "Pick Buds", true, plantWindow) 
    addEventHandler("onClientGUIClick", pick, harvestBud) 
     
    close = guiCreateButton(0.1, 0.7, 0.75, 0.30, "Close", true, plantWindow) 
    addEventHandler("onClientGUIClick", close, closeWindow) 
     
    --Quick Settings 
    guiWindowSetSizable(plantWindow, false) 
    guiWindowSetMovable(plantWindow, true) 
    guiSetVisible(plantWindow, true) 
    showCursor(true)     
    end 
end 
addEvent("cCheckPlant", true) 
addEventHandler("cCheckPlant", getRootElement(), cCheckPlant) 
  
function harvestBud() 
    if (source==pick) then 
        triggerServerEvent("harvestPlant", localPlayer, localPlayer, dbid) 
        showCursor(false) 
        destroyElement(plantWindow) 
        checkPlantGUI = nil 
    end 
end 
  
function closeWindow() 
    if (source==close) then 
        showCursor(false) 
        destroyElement(plantWindow) 
        toggleAllControls(true) 
        triggerEvent("onClientPlayerWeaponCheck", localPlayer) 
        checkPlantGUI = nil 
    end 
end 

Client Side --

It's meant to open a GUI once clicked on object, but it doesn't. Any ideas? I spent hours trying to fix it.

Link to comment

Just change that part.

  
local checkPlantGUI = nil 
  
function cCheckPlant() 
    if checkPlantGUI == nil then 
    
    --checkPlantGUI = checkPlantGUI --wtf this shit!? disabled.. checkPlantGUI will be always nil. 
    
    local lplayer = getLocalPlayer() 
    
    local width, height = 150, 175 
    local scrWidth, scrHeight = guiGetScreenSize() 
    local x = scrWidth/2 - (width/2) 
    local y = scrHeight/2 - (height/2) 
  
    plantWindow = guiCreateWindow(x, y, width, height, "Cannabis Plant - Stage: " .. stage .. "", false) 
  
    checkPlantGUI = plantWindow --added 
    
    local width2, height2 = 10, 10 
    local x = scrWidth/2 - (width2/2) 
    local y = scrHeight/2 - (height2/2) 
    
    harvest = guiCreateLabel(0.1, 0.1, 0.75, 0.30, "Current Harvest: ".. harvest .."gram(s)", true, plantWindow) 
    guiLabelSetHorizontalAlign(harvest, "center", true) 
    guiLabelSetVerticalAlign(harvest, "center") 
    
    --Buttons 
    pick = guiCreateButton(0.1, 0.4, 0.75, 0.30, "Pick Buds", true, plantWindow) 
    addEventHandler("onClientGUIClick", pick, harvestBud) 
    
    close = guiCreateButton(0.1, 0.7, 0.75, 0.30, "Close", true, plantWindow) 
    addEventHandler("onClientGUIClick", close, closeWindow) 
    
    --Quick Settings 
    guiWindowSetSizable(plantWindow, false) 
    guiWindowSetMovable(plantWindow, true) 
    guiSetVisible(plantWindow, true) 
    showCursor(true)    
    end 
end 

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