Jump to content

[Question] Setting Element Data


kieran

Recommended Posts

Trying super simple script to set a vehicles data and then re-spawn it if the data is true, it SORT of works, but only AFTER the vehicle explodes. -_- Sorry to bother with so many simple scripts. xD 

--This will destroy cars with no data, I want second function to give a vehicle data and if it's true to respawn it :P 
function respawnExplodedVehicle()
	setTimer(destroyElement, 1000, 1, source)
end
addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle)



veh1 = createVehicle( 420, 367.9130859375, 2485.162109375, 17, 0, 0, 90 )--Creating and naming

function vehres()
	veh = setElementData( veh1, "tempdata.check" )
	setVehicleColor ( veh1, 189, 200, 12 )     
	if ( veh == true ) then
	setTimer(respawnVehicle, 1000, 1, source)
	elseif ( veh == false ) then 
	return --trying stuff, thought problem was because the code was in first function

end
end

addEventHandler("onVehicleExplode", getRootElement(), vehres)--respawn it

Debug says it needs argument at argument 3, but I can't think of what to put there... :/ 

 

Edit

Change to 

veh1 = createVehicle( 420, 367.9130859375, 2485.162109375, 17, 0, 0, 90 )
function vehres()
	veh = setElementData( veh1, "tempdata.check", Vehicle )
	setVehicleColor ( veh1, 189, 200, 12 )     
	if ( veh == true ) then
	setTimer(respawnVehicle, 1000, 1, source)
	elseif ( veh == false ) then 
	return

end
end

addEventHandler("onVehicleExplode", getRootElement(), vehres)

But now it says it expects Element at argument one where respawnVehicle is (Line 6). o,o 

Edited by kieran
Link to comment
setElementData(theElement, string theNameOfTheData, theData)

It works like, you define the element which you want to set the data of. Then you define a data name in string, so you can access it later, and lastly you define the data. Which can be a string, a number, an element, an object etc.

--------

respawnVehicle uses only one argument, the vehicle. Use wiki...

respawnVehicle() --Check it and read it carefully.

 

Edited by StormFighter
More
Link to comment
27 minutes ago, StormFighter said:

respawnVehicle uses only one argument, the vehicle. Use wiki...


respawnVehicle() --Check it and read it carefully.

 

I get that, but I want to re-spawn a vehicle if the data is true, and destroy the element if it's false....  It will either re-spawn a vehicle if I don't have destroyElement in, or destroy it if I do add it to destroy it :/ 

Link to comment

No matter how experienced you are, you always use the wiki, I have been scripting for years and I can never memorize the parameter list for dxDrawText and I don't actually have to.. Whenever I need something, I open the wiki and I can see the full list of needed/optional parameters. 

"Debug says it needs argument at argument 3, but I can't think of what to put there..." -> this is when you go to the wiki and look at the examples for that given function, fortunately almost all function have at least 1 example 

  • Like 1
Link to comment

I know @pa3ck, but sometimes I have difficulty understanding the explanations, that's why I personally like videos, you can see what they change and what it does etc, but I think I need to just practice and focus on one thing at a time, I have been trying too much at once...

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