Probleme scripte LUA pour fiveM
Répondre à la discussion
Affichage des résultats 1 à 1 sur 1

Probleme scripte LUA pour fiveM



  1. #1
    Myrlie

    Question Probleme scripte LUA pour fiveM


    ------

    Bonjour,

    Le scripte ci dessous ne fonctionne pas. Surement les timer ? ! En effet, quand on plante l'objet en jeu, le PED arrive, le PROP aussi, l'animation fonctionne mais ca n'évolue pas...

    Je suis dans l'urgence... : /


    MERCI infiniment d'avance pour l'aide.
    Cordialement.

    Code:
    function CreateWeedLocal()
    
    	local self = {}
    	
    	self.drug           = 'weed'
    	self.created        = {}
    	self.spawnedObjects = {}
    	self.spawnedPeds    = {}
    
    	self.create = function(coords, startTime, duration, cb)
    
    		local parent = self
    		local self   = {}
    
    		startTime = startTime - TimeDiff
    
    		self.obj            = nil
    		self.employee       = nil
    		self.endTime        = startTime + duration
    		self.level          = -1
    
    		Citizen.CreateThread(function()
    			while true do
    
    				Citizen.Wait(0)
    
    				if CurrentRoom == nil then
    					return
    				end
    
    				local time    = GetGameTimer() + TimeDiff
    				local percent = ((time - startTime) / duration) * 100
    
    				if percent <= 100 / 3 then
    					
    					if self.level < 0 then
    
    						self.level = 0
    
    						ESX.Game.SpawnLocalObject('bkr_prop_weed_01_small_01a', coords, function(obj)
    							self.obj = obj
    							table.insert(parent.spawnedObjects, obj)
    						end)
    
    					end
    				
    				elseif percent <= 100 / 3 * 2 then
    					
    					if self.level < 1 then
    
    						self.level = 1
    
    						ESX.Game.DeleteObject(self.obj)
    
    						ESX.Game.SpawnLocalObject('bkr_prop_weed_med_01a', {
    							x = coords.x,
    							y = coords.y,
    							z = coords.z - 2.5
    						}, function(obj)
    							self.obj = obj
    							table.insert(parent.spawnedObjects, obj)
    						end)
    
    					end
    				
    				elseif percent <= 100 then
    					
    					if self.level < 2 then
    
    						self.level = 2
    
    						ESX.Game.DeleteObject(self.obj)
    
    						ESX.Game.SpawnLocalObject('bkr_prop_weed_lrg_01a', {
    							x = coords.x,
    							y = coords.y,
    							z = coords.z - 2.5
    						}, function(obj)
    							self.obj = obj
    							table.insert(parent.spawnedObjects, obj)
    						end)
    
    					end
    					
    				elseif percent >= 100 then
    					
    					DeletePed(self.employee)
    
    					self.level = 3
    
    					if self.obj == nil then
    
    						ESX.Game.SpawnLocalObject('bkr_prop_weed_lrg_01a', {
    							x = coords.x,
    							y = coords.y,
    							z = coords.z - 2.5
    						}, function(obj)
    							
    							self.obj = obj
    							table.insert(parent.spawnedObjects, obj)
    
    							if cb ~= nil then
    								cb()
    							end
    
    						end)
    					
    					else
    
    						if cb ~= nil then
    							cb()
    						end
    
    					end
    
    					return
    
    				end
    
    				if self.level < 3 and percent < 100 and self.employee == nil then
    
    		      local model = GetHashKey('G_F_Y_Families_01')
    			    
    		      RequestModel(model)
    
    			    while not HasModelLoaded(model) do
    						Citizen.Wait(0)
    					end
    
    					self.employee = CreatePed(5, model, coords.x - 0.2, coords.y - 0.5, coords.z + 1.0, 0.0,  false,  false)
    
    					table.insert(parent.spawnedPeds, self.employee)
    
    					RequestAnimDict('amb@world_human_gardener_plant@female@idle_a')
    					
    					while not HasAnimDictLoaded('amb@world_human_gardener_plant@female@idle_a') do
    						Citizen.Wait(0)
    					end
    
    					TaskPlayAnim(self.employee, 'amb@world_human_gardener_plant@female@idle_a', 'idle_a_female', 8.0, -8, -1, 49, 0, 0, 0, 0)
    
    				end
    
    			end
    		end)
    
    		return self
    
    	end
    
    	self.load = function(room, data)
    		
    		local spotsData = data['spots_' .. room .. '_' .. self.drug]
    
    		for i=1, #spotsData, 1 do
    			if spotsData[i] ~= -1 then
    				
    				ActiveEmployees = ActiveEmployees + 1
    				
    				self.created[i] = self.create(Config.Zones.Rooms[room].Spots[i], spotsData[i], Config.Time[self.drug], function()
    					ActiveEmployees = ActiveEmployees - 1
    				end)
    
    			end
    		end
    
    	end
    
    	self.unload = function()
    
    		for i=1, #self.spawnedObjects, 1 do
    			ESX.Game.DeleteObject(self.spawnedObjects[i])
    		end
    
    		for i=1, #self.spawnedPeds, 1 do
    			DeletePed(self.spawnedPeds[i])
    		end
    
    	end
    
    	self.onEnterSpotArea = function(spot)
    
    		local key = 'spots_' .. CurrentRoom .. '_' .. self.drug
    
    		if LocalData[key][spot] == -1 then
    
    			local cb = function()
    
    				local totalEmployees  = LocalData['employees_' .. CurrentRoom .. '_' .. self.drug]
    
    				if ActiveEmployees < totalEmployees then
    
    					ESX.TriggerServerCallback('esx_weed:tryRemoveInventoryItem', function(success)
    
    						local time = GetGameTimer() + TimeDiff
    
    						if success then 
    							TriggerServerEvent('esx_weed:updateSpot', CurrentOwner, CurrentRoom, self.drug, spot, time)
    						else
    							ESX.ShowNotification('Vous n\'avez pas de ~r~graines de cannabis')
    						end
    
    					end, 'graine', 1)
    
    				else
    					ESX.ShowNotification('Aucun employé disponible')
    				end
    
    			end
    
    			CurrentAction     = 'start_drug'
    			CurrentActionMsg  = 'Appuyez sur ~INPUT_CONTEXT~ pour faire pousser de la weed'
    			CurrentActionData = {cb = cb}
    
    		elseif self.created[spot].level == 3 then
    
    			local cb = function()
    
    				TriggerServerEvent('esx_weed:harvest', 'weed')
    				TriggerServerEvent('esx_weed:updateSpot', CurrentOwner, CurrentRoom, self.drug, spot, -1)
    
    			end
    
    			CurrentAction     = 'harvest_drug'
    			CurrentActionMsg  = 'Appuyez sur ~INPUT_CONTEXT~ pour ramasser la weed'
    			CurrentActionData = {cb = cb}
    
    		end
    
    	end
    
    	self.updateSpot = function(spot, val)
    
    		local key            = 'spots_' .. CurrentRoom .. '_' .. self.drug
    		LocalData[key][spot] = val
    
    		if val == -1 then
    
    			ESX.Game.DeleteObject(self.created[spot].obj)
    			
    			self.created[spot]   = nil
    			LocalData[key][spot] = -1
    
    		else
    
    			ActiveEmployees = ActiveEmployees + 1
    			
    			self.created[spot] = self.create(Config.Zones.Rooms[CurrentRoom].Spots[spot], val, Config.Time[self.drug], function()
    				ActiveEmployees = ActiveEmployees - 1
    			end)
    
    		end
    
    	end
    
    	return self
    
    end
    
    DrugLocals['weed'] = CreateWeedLocal()

    -----
    Dernière modification par JPL ; 14/05/2018 à 23h32. Motif: Ajout de la balise Code (#) pour garder l'indentation

Discussions similaires

  1. probleme pour configurer mes interfaces sur linux ( probleme assez théorique)
    Par docEmmettBrown dans le forum Internet - Réseau - Sécurité générale
    Réponses: 1
    Dernier message: 31/07/2023, 21h07
  2. [Thermique] Problème pour trouver un condensateur permanent pour VMC
    Par dixi35 dans le forum Dépannage
    Réponses: 7
    Dernier message: 29/12/2017, 17h31
  3. Problème pour calcul de masque solaire pour maison passive
    Par Muad79 dans le forum Habitat bioclimatique, isolation et chauffage
    Réponses: 4
    Dernier message: 23/09/2009, 15h31