ViRuZGamiing Posted December 4, 2014 Posted December 4, 2014 Hi guys, I'm trying to figure out the setElementData, i've read the wiki and now's my question. I want to assign some ElementData called ID to a vehicle (which would be possible for me) But! I want to do it like on the second car it needs to get the next ID + 1. Example: Vehicle Banshee bought! ID = 1 Next Vehicle! ID = 2 I hope you'll understand what I'm trying to say. Regards Viruz
Et-win Posted December 4, 2014 Posted December 4, 2014 Well: currentID = 0 -- currentID = currentID + 1 setElementData(theElement, "ID", currentID)
ViRuZGamiing Posted December 4, 2014 Author Posted December 4, 2014 Oh lol, it's just like C# Thx, i'll try it and let you know if I bump onto any problems
ViRuZGamiing Posted December 4, 2014 Author Posted December 4, 2014 Okay nice, it works great. I've attached the data Owner and ID to the bought vehicle. I've noticed that the Data goes away on resource restart, is it possible to keep it? Regards
Et-win Posted December 4, 2014 Posted December 4, 2014 You can save all cars in a XML file or even better a database, but databases are not my thing yet.
ViRuZGamiing Posted December 4, 2014 Author Posted December 4, 2014 I don't use databases, I know they're the best to use and it can be used in every script. XML seems quite hard, if I could get some basics going on XML I could try it. Are you known with XML?
Et-win Posted December 4, 2014 Posted December 4, 2014 Yes. And XML is quite easy. Just start looking at the Wiki to the XML functions and you will know soon how it works. Maybe you even can use account data.
ViRuZGamiing Posted December 4, 2014 Author Posted December 4, 2014 I've made this already, could I use this to implement it into an XML, and I will take a look at the XML Functions. function saveYourCar (thePlayer) local vehicle = getPedOccupiedVehicle (thePlayer) if (vehicle == false) then outputChatBox("Your not in a vehicle") else local idData = getElementData(vehicle, "ID") local ownerData = getElementData(vehicle, "Owner") if (thePlayer == ownerData) then local vPX, vPY, vPZ = getElementPosition(vehicle) setElementData(thePlayer, "vehPositionX", vPX) setElementData(thePlayer, "vehPositionY", vPY) setElementData(thePlayer, "vehPositionZ", vPZ) outputChatBox("Position Saved!", thePlayer) else outputChatBox("This vehicle doesn't belong to you!", thePlayer) end end end addCommandHandler("save", saveYourCar)
Et-win Posted December 4, 2014 Posted December 4, 2014 If you want to save vehicles for a player, you can use account data. Just put everything of the vehicle (position, id, etc) into a table and put the table into the player's account. Later you can call it and then you can use functions like setElementPosition and such. (Check or the player is logged in!)
Feche1320 Posted December 4, 2014 Posted December 4, 2014 Use fromJSON and toJSON, way easier than XML.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now