Jump to content

help plants


kevincouto6

Recommended Posts

how it works script :

  • First a counter is created, to calculate the plants that were add with the command /d
  • It is only possible to plant if you are in the Zone
  • To each plant that is add, a check is made to see if it has not already given the total = 2
  • if equal to 2 then it will activate the function to complete the mission
  • where it will activate a trigger that will destroy the elements, Where am I in trouble?

Could you help me here? 

I'm developing a planting mission, I have a problem in destroy element 

  • It is only destroying last to be planted
  • if another player does at the same time will destroy that of the other player
  • I wanted the destruction of plants to work individually, Type if 2 players are doing and 1 player complete remove only his

Thanks in advance, ?

 

 

Server-side

local plants = {}

function iniciarFarm8 ( x, y, z )

    --animation = setPedAnimation(source, "medic", "CPR", -1, false, false, false, false)
    --setTimer(function()
    plants[client] = createObject ( 862, x , y , z - 1 , 0, 0, 0 )
    --end, 6500, 1)
    
end
addEvent ("iniciaJob8", true) 
addEventHandler ("iniciaJob8", getRootElement(), iniciarFarm8)

function plantDestroy (source)
    destroyElement ( plants[client] )
end
addEvent ("onDestroyElement", true) 
addEventHandler ("onDestroyElement", getRootElement(), plantDestroy)

Client-side

plantsPoints = 0

function inicio8 ( )
	
	local retanguloParaPlantio = createColRectangle ( 209.52605, 1906.70947, 155, 155 )
	hillRadar = createRadarArea ( 209.52605, 1906.70947, 155, 155, 0, 255, 0, 175 )
	
	addEventHandler("onClientColShapeHit", retanguloParaPlantio, function ( theElement, matchingDimension )
		if ( theElement == localPlayer ) then 
			function plant ()	
				local block, anim = getPedAnimation( localPlayer ) 
				if ( not( block == "medic" and  anim == "CPR" ) ) then 
					local x, y, z = getElementPosition ( localPlayer ) 
					triggerServerEvent ("iniciaJob8", localPlayer, x, y, z )			
					setTimer(function() 
						plantsPoints = plantsPoints+1 
						outputChatBox( "Foi plantado  "..(plantsPoints).."/2" )
						
						if plantsPoints >= 2 then 
							completMission() 
						end
					end, 6500, 1)

				else
					outputChatBox (" voçê deve esperar 6 sec para plantar novamente " )
				end	
			end
			addCommandHandler ( "d", plant )
		end
	end )
	
	addEventHandler("onClientColShapeLeave", retanguloParaPlantio, function ( theElement, matchingDimension )
		if ( theElement == localPlayer ) then 
			outputChatBox( "nop Function." )
			removeCommandHandler ( "d", plant )
		end
	end )

end

function completMission ()
	outputChatBox ("voçê plantou todos")
	plantsPoints = 0
	destroyElement ( hillRadar )
	triggerServerEvent ( "onDestroyElement", localPlayer )
end

 

Link to comment

I'm a total newbie here, but try to define the player and assign the plant to him.

https://wiki.multitheftauto.com/wiki/SetElementData

local plantsTable = { }
local plant = createObject(...)
setElementData(plant, 'id_player', playerId)
plantsTable[index] = plant

Then you can delete the plant which that player has.

 

I don't know if this is correct, but definitely I would try it.

Edited by Peti
  • Like 1
Link to comment
8 hours ago, Peti said:

I'm a total newbie here, but try to define the player and assign the plant to him.

 https://wiki.multitheftauto.com/wiki/SetElementData


local plantsTable = { }
local plant = createObject(...)
setElementData(plant, 'id_player', playerId)
plantsTable[index] = plant

Then you can delete the plant which that player has.

 

I don't know if this is correct, but definitely I would try it.

It worked at the time of specifying, the plant but the last object is still being destroyed, the others still exist, now I just have to destroy all

Link to comment

server-side

local plants = {}

function iniciarFarm8 ( x, y, z )

    animation = setPedAnimation(source, "medic", "CPR", -1, false, false, false, false)
    setTimer(function()
      plants[client] = createObject ( 862, x , y , z - 1 , 0, 0, 0 )
    end, 6500, 1)
    
end
addEvent ("iniciaJob8", true) 
addEventHandler ("iniciaJob8", getRootElement(), iniciarFarm8)

function plantDestroy ( thePlayer )
	for id, plant in ipairs(getElementsByType("object")) do 
		if getElementModel( plant ) == 862 then
			destroyElement ( plant )
		end
	end 

end
addEvent ("onDestroyElement", true) 
addEventHandler ("onDestroyElement", getRootElement(), plantDestroy)

plantDestroy can someone help me, I can destroy all the plants, but I can not seperar the players to destroy, example if you have 2 doing at the same time will destroy the plant of the two players, I need to destroy only the plants of the players who completed the mission,  then as fasso to specify the destruction only of the  plants of a player ?

and srry double post

Edited by kevincouto6
Link to comment

You put the plant in the plants table so all that you need to do now is to use the client to reference the plant in the table.

function plantDestroy ( )
	destroyElement ( plants[client] )
	plants[client] = nil -- remove the entry from the table
end
addEvent ("onDestroyElement", true) 
addEventHandler ("onDestroyElement", getRootElement(), plantDestroy)

 

Edited by Mr.Loki
redundant coding mybad
Link to comment
local plants = {}

function iniciarFarm8( x, y, z )

    --animation = setPedAnimation(source, "medic", "CPR", -1, false, false, false, false)
    --setTimer(function()
    plants[source] = createObject ( 862, x , y , z - 1 , 0, 0, 0 )
    --end, 6500, 1)
    
end
addEvent ("iniciaJob8", true) 
addEventHandler ("iniciaJob8", getRootElement(), iniciarFarm8)

function plantDestroy ()
	destroyElement ( plants[source] )
end
addEvent ("onDestroyElement", true) 
addEventHandler ("onDestroyElement", getRootElement(), plantDestroy)

 

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