Jump to content

can someone fix this small script


HealthDown

Recommended Posts

weedID = 826 -- object id for weed 
weedGrowTime = 100000 -- milliseconds 
weedHealthAmount = 50 -- health amount if smoking the weed 
weedCash = 100 -- cash if selling the weed 
seedCash = 5 -- weed seed price 
weedArea = createRadarArea(-50.442802,-108.432037,130.955353,134.419464,0,0,0,50) -- weed planting area 
weeds = { } -- weed objects table 
weedReady = { } -- weed ready table 
weedCol = { } -- weed collision circles table 
weedPlants = "" -- players weed slots which contain weed (dont edit this!) 
playerWeed = 0 -- player's weed at start 
playerSeeds = 0 -- player's weed seeds at start 
-- These are not relevant settings, but the default ones. There is the function which calls the server for the right settings. 
  
addEvent("weed.onSend",true) 
addEventHandler("weed.onSend",getRootElement(),function(a,b,c,d,e,f,g) if type(a) == "number" then weedID = a end if type(b) == "number" then weedGrowTime = b end if type(c) == "number" then weedHealthAmount = c end if type(d) == "number" then weedCash = d end if type(e) == "number" then seedCash = e end if type(f) == "number" then playerSeeds = f end if type(g) == "number" then playerWeed = g end addCommandHandler("weed",weedCommands) end) 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),function() triggerServerEvent("weed.onRequest",localPlayer) end) 
function weedCommands(cmd,subcmd,id) 
    if not id and subcmd ~= "plants" then outputChatBox("Please specify a slot, or specify amount of weed!",255,0,0) return end 
    if subcmd == "plant" then 
        if not weeds[id] then 
            local x,y,z = getElementPosition(localPlayer) 
            if isInsideRadarArea(weedArea,x,y) and isPedOnGround(localPlayer) and not isPedInVehicle(localPlayer) then 
                if playerSeeds < 1 then outputChatBox("Not enough seeds!",255,0,0) return end 
                weeds[id] = createObject(weedID,x,y,z-2) 
                weedPlants = weedPlants..id..", " 
                weedCol[id] = createColCircle(x,y,10) 
                playerSeeds = playerSeeds - 1 
                moveObject(weeds[id],weedGrowTime,x,y,z,0,0,0,"InOutQuad") 
                setTimer(function(idd)weedReady[idd] = true end,weedGrowTime,1,id) 
                outputChatBox("Successful plant! Wait till its ready for harvesting. Your seeds: "..playerSeeds,0,255,0) 
            else 
                outputChatBox("Please go in the planting area, exit your vehicle and stay on the ground to plant.",255,0,0) 
            end 
        else 
            outputChatBox("This weed slot is alerady in use! Choose another slot!",255,0,0) 
        end 
    elseif subcmd == "harvest" then 
        if weeds[id] then 
            local x,y,z = getElementPosition(localPlayer) 
            local x2,y2,z2 = getElementPosition(weeds[id]) 
            if isElementWithinColShape(localPlayer,weedCol[id]) and weedReady[id] then 
                destroyElement(weedCol[id]) 
                destroyElement(weeds[id]) 
                weedReady[id] = nil 
                weeds[id] = nil 
                weedCol[id] = nil 
                weedPlants = weedPlants:gsub(id..", ","") 
                playerWeed = playerWeed + 1 
                outputChatBox("Successful harvest! Your have "..playerWeed.." grams of weed.",0,255,0) 
            else 
                outputChatBox("Wait till the weed is ready for harvesting, and stay close to it!",255,0,0) 
            end 
        else 
            outputChatBox("No weed in this slot!",255,0,0) 
        end 
    elseif subcmd == "highlight" then 
        if weeds[id] then 
            local x,y,z = getElementPosition(weeds[id]) 
            local blip = createBlip(x,y,z,41,1,0,153,0,153) 
            setTimer(destroyElement,100000,1,blip) 
        end 
    elseif subcmd == "plants" then 
        if weedPlants == "" or weedPlants == " " then  
            outputChatBox("You have no plants.",0,255,0) 
            weedPlants = "" 
        else 
            outputChatBox("Your weed plants' slots: " ..weedPlants,0,255,0) 
        end 
    elseif subcmd == "sell" then 
        id = tonumber(id) 
        if id <= playerWeed then 
            playerWeed = playerWeed - id 
            outputChatBox("You sold "..id.. " grams of weed. You now have "..playerWeed.." grams.",0,255,0) 
            givePlayerMoney(id*weedCash) 
        else 
            outputChatBox("Not enough weed!",255,0,0) 
        end 
    elseif subcmd == "buy" then 
        id = tonumber(id) 
        if id*8 <= getPlayerMoney() then 
            playerSeeds = playerSeeds + id 
            outputChatBox("You bought "..id.." seeds. You now have "..playerSeeds..".",0,255,0) 
            takePlayerMoney(id*seedCash) 
        else 
            outputChatBox("Not enough money!",255,0,0) 
        end 
    elseif subcmd == "smoke" then 
        id = tonumber(id) 
        if id <= playerWeed then 
            setElementHealth(localPlayer,getElementHealth(localPlayer)+10*id) 
            playerWeed = playerWeed - id 
            outputChatBox("You smoked "..id.." grams of weed. Your health has been refilled. You have "..playerWeed.." grams of weed.",0,255,0) 
        else 
            outputChatBox("Not enough weed!") 
        end 
    end 
end 
  
  
guiWeed = guiCreateWindow(246,237,275,177,"F2 - Weed Panel",false) 
guiSetAlpha(guiWeed,1) 
guiWindowSetMovable(guiWeed,false) 
guiWindowSetSizable(guiWeed,false) 
guiWeedHarvest = guiCreateButton(10,73,92,31,"Harvest Weed",false,guiWeed) 
guiWeedPlant = guiCreateButton(10,35,92,31,"Plant Weed",false,guiWeed) 
guiWeedSmoke = guiCreateButton(10,110,92,31,"Smoke Weed",false,guiWeed) 
guiWeedTxt1 = guiCreateLabel(109,80,99,17,"Number of Seeds:",false,guiWeed) 
guiWeedTxt2 = guiCreateLabel(109,109,99,17,"Number of Weed:",false,guiWeed) 
guiWeedTxt3 = guiCreateLabel(8,148,262,17,"You can buy seed and sell weed in Weed Shop",false,guiWeed) 
guiLabelSetColor(guiWeedTxt3,215,0,0) 
guiWeedClose = guiCreateButton(212,36,51,23,"Close",false,guiWeed) 
guiWeedProgress = guiCreateProgressBar(112,36,92,23,false,guiWeed) 
guiWeedSeed = guiCreateLabel(213,81,48,15,"2",false,guiWeed) 
guiWeedWeed = guiCreateLabel(213,109,48,15,"2",false,guiWeed) 
  
guiSetVisible(guiWeed, false) 
  
function showGuiWeed() 
    if (guiGetVisible(guiWeed, true)) then 
        guiSetVisible(guiWeed, false) 
        showCursor(false) 
    else 
        guiSetVisible(guiWeed, true) 
        showCursor(true) 
    end 
end 
addEventHandler( "onClientResourceStart", getRootElement( ), 
    function ( startedRes ) 
        bindKey("f2", "down", showGuiWeed) 
    end 
); 
function guiWeedCloseAction() 
    guiSetVisible(guiWeed, false) 
    showCursor(false) 
end 
addEventHandler("onClientGUIClick", guiWeedClose, guiWeedCloseAction, false) 
  
function guiWeedPlantAction() 
    if not guiGetText(guiWeedSeed)==0 then 
        guiSetText(guiWeedSeed, guiGetText(guiSeedWeed)-1) 
        setTimer (guiWeedTimer, 1000, 100) 
    else 
         
    end 
end 
addEventHandler("onClientGUIClick", guiWeedPlant, guiWeedPlantAction, false) 
  
function guiWeedTimer ( text ) 
    guiProgressBarSetProgress(guiWeedPorgress, guiProgressBarGetProgress(guiWeedPorgress)+1) 
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...