Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Created by dev0
- --
- Plants = {}
- function Plants.new(...)
- local o = setmetatable({}, { __index = Plants })
- if o.constructor then
- o:constructor(...)
- end
- return o
- end
- function Plants:constructor()
- self._tblAllPlants = {}
- self._tblPlantTimer = {}
- setTimer(function() self:createPlants() end, 1000, 1)
- addEventHandler("onPlayerClick", root, function(...) self:onPlantClick(...) end)
- end
- function Plants:createPlants()
- local SQL = dbQuery(connection, "SELECT * FROM plants")
- if (SQL) then
- local tblResult, iRows = dbPoll(SQL, -1)
- if (iRows >= 1) then
- for _, value in ipairs(tblResult) do
- self._plantID = tonumber(value["id"])
- self._plantOwner = tostring(value["owner"])
- self._plantTime = tonumber(value["time"])
- self._plantModelID = tonumber(value["type"])
- if (not (isElement(self._tblAllPlants[self._plantID]))) then
- self._tblAllPlants[self._plantID] = Object(tonumber(value["type"]), tonumber(value["posX"]), tonumber(value["posY"]), tonumber(value["posZ"]) - 0.9)
- self._tblAllPlants[self._plantID]:setData("id", self._plantID)
- self._tblAllPlants[self._plantID]:setData("owner", self._plantOwner)
- self._tblAllPlants[self._plantID]:setData("time", self._plantTime)
- self._tblAllPlants[self._plantID]:setData("isPlant", true)
- if (self._plantModelID == 3409) then
- self._PlantPlaceHolder = Object(2991, 0, 0, 0, 0, 0, 0)
- self._PlantPlaceHolder1 = Object(2991, 0, 0, 0, 0, 0, 0)
- self._PlantPlaceHolderPosition = Vector3(-2588.5119628906 - (-2589.3125), 330.2961730957 - (330.35571289063), -0.5)
- self._PlantPlaceHolderPosition1 = Vector3(-2588.5119628906 - (-2587.8278808594), 330.2961730957 - (330.31005859375), -0.5)
- self._PlantPlaceHolder:attach(self._tblAllPlants[self._plantID], self._PlantPlaceHolderPosition.x, self._PlantPlaceHolderPosition.y, self._PlantPlaceHolderPosition.z, 0, 0, 270)
- self._PlantPlaceHolder1:attach(self._tblAllPlants[self._plantID], self._PlantPlaceHolderPosition1.x, self._PlantPlaceHolderPosition1.y, self._PlantPlaceHolderPosition1.z, 0, 0, 270)
- self._PlantPlaceHolder:setParent(self._tblAllPlants[self._plantID])
- self._PlantPlaceHolder1:setParent(self._tblAllPlants[self._plantID])
- self._PlantPlaceHolder:setAlpha(0)
- self._PlantPlaceHolder1:setAlpha(0)
- self._PlantPlaceHolder:setData("weedObject", self._tblAllPlants[self._plantID])
- self._PlantPlaceHolder1:setData("weedObject", self._tblAllPlants[self._plantID])
- end
- if (self._plantModelID == 3409) then
- self._PlantGrowTime = 120000
- else
- self._PlantGrowTime = 240000
- end
- if (self._plantTime < 100) then
- self._tblPlantTimer[self._tblAllPlants[self._plantID]] = setTimer(function(uPlant)
- if (isElement(uPlant) and uPlant:getData("time") < 100) then
- uPlant:setData("time", uPlant:getData("time") + 1)
- end
- end, self._PlantGrowTime, 100 - self._plantTime, self._tblAllPlants[self._plantID])
- end
- end
- end
- end
- end
- end
- function Plants:deletePlant(uPlayer, uPlant)
- if (isElement(uPlant)) then
- for key, value in ipairs(self._tblAllPlants) do
- if value == uPlant then
- table.remove(self._tblAllPlants, key)
- break
- end
- end
- if (uPlant:getModel() == 3409) then
- if (uPlant:getData("time") == 100 or isAdmin(uPlayer, 1)) then
- -- uPlayer:setData("WEED", uPlayer:getData("WEED") + math.random(1, 5))
- dbExec(connection, "DELETE FROM plants WHERE id = '" .. uPlant:getData("id") .. "'")
- uPlayer:outputChat("Du hast das Hanf abgeerntet!", 0, 120, 0)
- if isElement(uPlant) then uPlant:destroy() end
- else
- uPlayer:outputChat("Du kannst diese Pflanze noch nicht ernten!", 120, 0, 0)
- end
- end
- end
- end
- function Plants:onPlantClick(strButton, strState, uElement)
- if (strButton == "left" and strState == "up") then
- if (uElement) then
- local playerPosition = Vector3(getElementPosition(source))
- if (getDistanceBetweenPoints3D(playerPosition.x, playerPosition.y, playerPosition.z, getElementPosition(uElement)) <= 5) then
- if (uElement:getData("weedObject")) then
- local clickedPlant = uElement:getData("weedObject")
- source:outputChat(string.format("PflanzenID: %s, Pflanzenowner: %s, Pflanzenzeit: %s", clickedPlant:getData("id"), clickedPlant:getData("owner"), clickedPlant:getData("time")), 255, 255, 0)
- end
- end
- end
- elseif (strButton == "right" and strState == "up") then
- if (uElement) then
- local playerPosition = Vector3(getElementPosition(source))
- if (getDistanceBetweenPoints3D(playerPosition.x, playerPosition.y, playerPosition.z, getElementPosition(uElement)) <= 5) then
- if (uElement:getData("weedObject")) then
- local clickedPlant = uElement:getData("weedObject")
- self:deletePlant(source, clickedPlant)
- end
- end
- end
- end
- end
- G_Plants = Plants.new()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement