Jump to content

SetTimer + SetElementPosition not found


Recommended Posts

Server Side,  

it does not work with the set timer directing it, but with the command

function SubenPasajeros ()
			if CantidadDeAsientos >= 0 then
					 if Asiento1 == 0 then
						Asiento1 = 1	
						client = player
						local vehicle = getPedOccupiedVehicle( client ) 
						x1, y1, z1 = getElementPosition ( client )
						Asiento1 = createObject (2035, 1421.958984375, 2624.4677734375, 11.392612457275)
						setElementPosition ( Asiento1, x1, y1, z1)
						attachElements( Asiento1, vehicle, 0.95, 0.6, 0, 0, 0, 0 )  --Fila 1 A
						outputChatBox ("Asiento1")
		else if Asiento2 == 0 then
						Asiento2 = 1
						outputChatBox ("Asiento2")
						local vehicle = getPedOccupiedVehicle( client ) 
						x1, y1, z1 = getElementPosition ( client )
						Asiento2 = createObject (2035, 1421.958984375, 2624.4677734375, 11.392612457275)
						setElementPosition ( Asiento2, x1, y1, z1)
						attachElements( Asiento2, vehicle, 0.5, -0.2, 0, 0, 0, 0 ) --Fila 2 B

 

function D3 ()
outputChatBox ("JEJE")
setTimer ( SubenPasajeros, 500, 1, DispPasajeros)
end
addCommandHandler("pe",D3)

 

Link to comment

I don't know what are you going to do with that. Is there any error coming out from debug?

You know, 4th argument on setTimer is variable you wish to pass to SubenPasajeros function. And you should do this on SubenPasajeros function

function SubenPasajeros (DispPasajeros) -- pass the variable here

end

 

Link to comment

asd

function SubenPasajeros (client)
			if CantidadDeAsientos >= 0 then
			if Asiento1 == 0 then
						Asiento1 = 1	
						local vehicle = getPedOccupiedVehicle( client ) 
						local x1,y1,z1 = getElementPosition( client )
						Asiento1 = createObject (2035, 1423.2880859375, 2602.650390625, 10.8203125)
						setElementPosition ( Asiento1, x1,y1,z1)
						attachElements( Asiento1, vehicle, 0.95, 0.6, 0, 0, 0, 0 )  --Fila 1 A
						outputChatBox ("Asiento1")
		else if Asiento2 == 0 then
						Asiento2 = 1
						outputChatBox ("Asiento2")
						local vehicle = getPedOccupiedVehicle( client ) 
						x1, y1, z1 = getElementPosition ( client )
						Asiento2 = createObject (2035, 1421.958984375, 2624.4677734375, 11.392612457275)
						setElementPosition ( Asiento2, x1, y1, z1)
						attachElements( Asiento2, vehicle, 0.5, -0.2, 0, 0, 0, 0 )

 

 

From another function, SubenPasajeros is activated as I show it here. What happens is that the SetElementPosition (Object Asiento1) does not work. But if you add it with the Upload command if you add the object

 

function greetingCommand ( playerSource, commandName )
	setTimer ( SubenPasajeros, 500, 1, client)
    triggerClientEvent ( "onGreetingb", getRootElement(), PasajSuben ) 
end

 

Link to comment

You're setting Asiento1 and Asiento2 as integers and then setting them as elements, which won't allow the check to run again. Change the variable names for your objects and try it again.

Edited by ShayF
  • Thanks 1
Link to comment

Good point, but anyway changing the name of the variables, still does not work

Asiento1=0; Asiento2=0; Asiento3=0; Asiento4=0; Asiento5=0; Asiento6=0; Asiento7=0; Asiento8=0; Asiento9=0; Asiento10=0; Asiento11=0; Asiento12=0; Asiento13=0; Asiento14=0; Asiento15=0; Asiento16=0; Asiento17=0; Asiento18=0; Asiento19=0; Asiento20=0; Asiento21=0





function SubenPasajeros (client)
			if CantidadDeAsientos >= 0 then
			if Asiento1 == 0 then
						Asiento1 = 1	
						local vehicle = getPedOccupiedVehicle( client ) 
						local x1,y1,z1 = getElementPosition(client )
						Asiento1T = createObject (2035, 1423.2880859375, 2602.650390625, 10.8203125) -- add "T"
						setElementPosition ( Asiento1T, x1,y1,z1)
						attachElements( Asiento1T, vehicle, 0.95, 0.6, 0, 0, 0, 0 )  --Fila 1 A
						outputChatBox ("Asiento1")
		else if Asiento2 == 0 then
						Asiento2 = 1
						outputChatBox ("Asiento2")
						local vehicle = getPedOccupiedVehicle( client ) 
						x1, y1, z1 = getElementPosition ( client )
						Asiento2T = createObject (2035, 1421.958984375, 2624.4677734375, 11.392612457275)
						setElementPosition ( Asiento2T, x1, y1, z1)
						attachElements( Asiento2T, vehicle, 0.5, -0.2, 0, 0, 0, 0 ) --Fila 2 B
        
        function greetingCommand ( playerSource, commandName )
	local x1,y1,z1 = getElementPosition(client )
	setTimer ( SubenPasajeros, 500, 1, client)
    triggerClientEvent ( "onGreetingb", getRootElement(), PasajSuben ) 
end

        
        

 

Edited by Lormateve
Link to comment
18 minutes ago, Lormateve said:

Good point, but anyway changing the name of the variables, still does not work


Asiento1=0; Asiento2=0; Asiento3=0; Asiento4=0; Asiento5=0; Asiento6=0; Asiento7=0; Asiento8=0; Asiento9=0; Asiento10=0; Asiento11=0; Asiento12=0; Asiento13=0; Asiento14=0; Asiento15=0; Asiento16=0; Asiento17=0; Asiento18=0; Asiento19=0; Asiento20=0; Asiento21=0





function SubenPasajeros (client)
			if CantidadDeAsientos >= 0 then
			if Asiento1 == 0 then
						Asiento1 = 1	
						local vehicle = getPedOccupiedVehicle( client ) 
						local x1,y1,z1 = getElementPosition(client )
						Asiento1T = createObject (2035, 1423.2880859375, 2602.650390625, 10.8203125) -- add "T"
						setElementPosition ( Asiento1T, x1,y1,z1)
						attachElements( Asiento1T, vehicle, 0.95, 0.6, 0, 0, 0, 0 )  --Fila 1 A
						outputChatBox ("Asiento1")
		else if Asiento2 == 0 then
						Asiento2 = 1
						outputChatBox ("Asiento2")
						local vehicle = getPedOccupiedVehicle( client ) 
						x1, y1, z1 = getElementPosition ( client )
						Asiento2T = createObject (2035, 1421.958984375, 2624.4677734375, 11.392612457275)
						setElementPosition ( Asiento2T, x1, y1, z1)
						attachElements( Asiento2T, vehicle, 0.5, -0.2, 0, 0, 0, 0 ) --Fila 2 B
        
        function greetingCommand ( playerSource, commandName )
	local x1,y1,z1 = getElementPosition(client )
	setTimer ( SubenPasajeros, 500, 1, client)
    triggerClientEvent ( "onGreetingb", getRootElement(), PasajSuben ) 
end

        
        

 

Asiento = {}
for i=1,21 do
	Asiento[i] = 0
end

function SubenPasajeros(client)
	if CantidadDeAsientos >= 0 then
		if Asiento[1] == 0 then
			Asiento[1] = 1	
			local vehicle = getPedOccupiedVehicle(client)
			local x1,y1,z1 = getElementPosition(client)
			local Asiento1T = createObject(2035,1423.2880859375,2602.650390625,10.8203125)
			setElementPosition(Asiento1T,x1,y1,z1)
			attachElements(Asiento1T,vehicle,0.95,0.6,0,0,0,0)
			outputChatBox('Asiento1')
		else if Asiento[2] == 0 then
			Asiento[2] = 1
			outputChatBox('Asiento2')
			local vehicle = getPedOccupiedVehicle(client)
			local x1,y1,z1 = getElementPosition(client)
			local Asiento2T = createObject(2035,1421.958984375,2624.4677734375,11.392612457275)
			setElementPosition(Asiento2T,x1,y1,z1)
			attachElements(Asiento2T,vehicle,0.5,-0.2,0,0,0,0)
		end
	end
end

function greetingCommand(client)
	setTimer(SubenPasajeros,500,1,client)
	triggerClientEvent('onGreetingb',root,PasajSuben)
end

Try this.

  • Thanks 1
Link to comment
4 minutes ago, Lormateve said:

 

 

it still does not "teleport" the object. Thanks for the simplification, but it does not solve it.

I see that you're attaching elements after setting their position, their position wont matter after you attach them, you need to use setElementAttachedOffsets, this uses the position from the vehicle, so in setElementAttachedOffsets the vehicles position will be 0,0,0. If the object does not appear on your vehicle then it most likely doesn't exist, if you have administrator privileges on the server you are testing with use /debugscript 3 and the print() function do debug variables and elements.
print(isElement(Asiento2T))

Edited by ShayF
Link to comment

 

It's still happening exactly the same, it occurred to me to return with a trigger from client to server, instead of using a timer from server to server. I try it and I tell you.

function SubenPasajeros (client)
	if CantidadDeAsientos >= 0 then
			if Asiento[1] == 0 then
						Asiento[1] = 1		
						local vehicle = getPedOccupiedVehicle( client ) 
						local player = client
							if ( vehicle ) then 
						local pos = {getElementPosition( vehicle )}
						Asiento1T = createObject( 2035, pos[1], pos[2], pos[3] )
						attachElements( Asiento1T, vehicle, 0, 0, 0, 0, 0, 0 )
						setElementAttachedOffsets (Asiento1T,pos[1],pos[2],pos[3],0,0,0)
						
						outputChatBox ("Asiento1")

 

Link to comment

 

Yes, I could make it work with a trigger, since the settimer was out of the question, I ignored it, now with the trigger from client, everything works correctly, without using the setElementAttachedOffsets, thank you very much for the collaboration, I am very grateful! 

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