VC:MP 0.4 (Beta) > Script Discussion

Can we use XML for 0.4?

(1/1)

Honey.:
Hi,

I wanted to ask whether we can use XML files for 0.4.If yes that please tell me the basic functions and if no then please tell me the best replace for XML.I wanted to use it for this :


--- Quote from: stormeus ---To save the path of the bus, you'd have to run a timer every 100ms and save it in an XML file or hash table with its own ID, which is created by making a variable that starts at zero and adding 1 every time the timer runs (so you'd get BusLoc0, BusLoc1, BusLoc2, etc.).

To load the bus' path, you'd load the XML file and read it in a while loop, with a counter that starts at 0 and increases every time the loop runs. As long as the loop can find an XML node with the name BusLoc<COUNTER>, it will write each location into a table that is stored in the server's memory.

You would then create a timer that runs every 100ms, the same rate you were saving the locations at, and move a vehicle to the next position in the table until it reaches the end and resets itself to BusLoc0.

--- End quote ---

Flockshot:
I dont know about XML but you can use .ini file if you want to save location

save by

--- Code: ---WriteIniString( "yourfile.ini", "Position", "Pos", format( "%.4f %.4f %.4f", player.Pos.x, player.Pos.y, player.Pos.z ) );

--- End code ---
and get by

--- Code: ---local coord = ReadIniString( "yourfile.ini", "Position", "Pos" );

--- End code ---

They are from Warcheif.

If you want a timer that save the pos automaticly than you also have to make a integer outside the timer and add 1 to it at the end of timer.


--- Code: ---local i=0;

function mytimer(player)
{
WriteIniString( "yourfile.ini", "Position" + i, "Pos" + i , format( "%.4f %.4f %.4f", player.Pos.x, player.Pos.y, player.Pos.z ) );
i++
}

--- End code ---
dont forget to add i in the Position and Pos.we add it so the name dont match with any previous save as it will replace the previous other than making a new.
For reading u will use a for loop and u will ++ the number and get the positon.
also dont forget to split it in x,y,z
by

--- Code: ---local splitpos = split( coord, " " );
local pos = Vector(split[0].tofloat(), split[1].tofloat(), split[2].tofloat());

--- End code ---

Navigation

[0] Message Index

Go to full version