Loop through all dini files and load cars.
#1

How to do this? Currently in my "scriptfiles/Users" folder I have my users files. And If a user has his own personal car, then the following lines are there:

pawn Код:
CarModelID=562
CarX=2229.580078
CarY=58.193901
CarZ=179.025405
So, how to loop through all the files, get these floats, ints, and spawn a car Elegy(model id 562) at coordinates X Y Z?
Reply
#2

You even need one more line for the Car Angle in this saving thingy.

To Spawn a Car for player when the Player Connects and destroys when he exits the server?
Use this stock anywhere you want to spawn the cars for every logged in player.
pawn Код:
stock GivePlayerCar()
{
for(new i=0;i>=MAX_PLAYERS;i++)
{
    AddStaticVehicle(PlayerInfo[i][CarModelID] ,PlayerInfo[i][CarX] ,PlayerInfo[i][CarY] ,PlayerInfo[i][CarZ] ,PlayerInfo[i][CarA] , 0, 1);

}
}
Note: Please Change PlayerInfo[i][CarX] to Your_Enum_Name[i][CarX] and so on.
Reply
#3

Ballu Miaa, that is not what he's trying to do. Read the topic title, it mentions looping through all existing dini files to spawn players' vehicles. However, getting a directory listing is impossible using SA-MP native functions. A plugin is required to retrieve the files in a directory.

You could somehow modify your server infrastructure to lets say, contain vehicle data in a file like "scriptfilers/Vehicles/1.txt", then 2.txt and so forth. This would actually let you "predict" the file names. Still, such file parsing is rather slow (and I don't recommend looping through these files during regular runtime activity, perhaps on gamemode load only). Alternatively I might suggest using SQLite or MySQL for storing the data like this.
Reply
#4

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Ballu Miaa, that is not what he's trying to do. Read the topic title, it mentions looping through all existing dini files to spawn players' vehicles. However, getting a directory listing is impossible using SA-MP native functions. A plugin is required to retrieve the files in a directory.

You could somehow modify your server infrastructure to lets say, contain vehicle data in a file like "scriptfilers/Vehicles/1.txt", then 2.txt and so forth. This would actually let you "predict" the file names. Still, such file parsing is rather slow (and I don't recommend looping through these files during regular runtime activity, perhaps on gamemode load only). Alternatively I might suggest using SQLite or MySQL for storing the data like this.
Uhh I though he meant that. My bad
Reply
#5

That is rather impossible. You can't loop through user files and open them. What you can do, save the vehicles in a different folder, in order (File name like: 1.ini; 2.ini; 3.ini; 4.ini; 5.ini; etc etc). That way you can loop through all files and open one at a time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)