Dynamic Cars?
#1

I'm wondering how one would go about doing Dynamic Cars/Houses/etc.

What i mean is, say you have a bunch of vehicles created by CreateVehicle.

If i have Player[playerid][vID] - the vehicle id stored by CreateVehicle
How would i go about keeping that car saved? I know in a file but i just can't understand how the format in the file would be.
Can someone help me out with that? (I'm using dini for stats/etc.)
Reply
#2

My setup is using dini, all the cars are stored into their own file in a folder called 'Cars' in my scriptfiles folder. I assume you know how to use dini? Basically I stored the X, Y, Z, Angle, ect. all into each cars file. like inside the folder there is files based on the cars ID

1.ini
2.ini
3.ini
etc.


Then the script runs through and loads all the cars up

You could do something like that or only store like Owner=Lavamike

inside each vehicle id






Something like that
Reply
#3

Quote:
Originally Posted by Lavamike
My setup is using dini, all the cars are stored into their own file in a folder called 'Cars' in my scriptfiles folder. I assume you know how to use dini? Basically I stored the X, Y, Z, Angle, ect. all into each cars file. like inside the folder there is files based on the cars ID

1.ini
2.ini
3.ini
etc.


Then the script runs through and loads all the cars up

You could do something like that or only store like Owner=Lavamike

inside each vehicle id






Something like that
Great idea, i'll do that.
Thanks!
Reply
#4

Quote:
Originally Posted by efeX
Great idea, i'll do that.
Thanks!
No problem, i'll give you a few things I ran into when making it

1) To convert normal car spawns or w.e like CreateVehicleEx(..) I just made a second function like CreateVehicleFile(with the same stuff as the normal) and the stock just takes all the information and puts it into the file

2) When spawning the cars I use a timer of 2 ms to loop through (as I found anything lower or a loop causes the server to lock up) But i've been fine running a 24/7 server using a 2 second timer loop. Maybe this has something to do with RAM, you might need to adjust it.

3) I also have a master list in the Cars folder called Main.ini
Inside it just has the total amount of vehicles and then a list of each vehicle ID's name

ex. first few lines:


VNUM=372
CarsLoaded=1

Car1=Greenwood
Car2=Greenwood
Car3=Mesa
Car4=Mesa
Car5=Clover
Car6=PCJ-600
Car7=PCJ-600
Car8=PCJ-600
Car9=PCJ-600
Car10=Boxville
Car11=Boxville
Car12=Boxville


4) If it helps here is my LoadCars public which I call after half a second of the Cars filterscript loading. You can refer to it if you run into any trouble

pawn Код:
public LoadCars()
{
  if(dini_Int("Vehicles/Main.ini","CarsLoaded") == 1)
  {
    UnloadCars();
    return 1;
  }
  new VNumber = dini_Int("Vehicles/Main.ini", "VNUM") + 1;
  if(Cars == VNumber)
  {
    goto CarDone;
  }
  else
  {
    new Lol1[30];
    new Float:X,Float:Y,Float:Z,Model,Float:Angle,Color1,Color2;
    format(Lol1, sizeof(Lol1), "Vehicles/%i.ini",Cars);
    if(dini_Exists(Lol1))
    {
      Model = dini_Int(Lol1, "Model");
      X = dini_Float(Lol1, "X");
      Y = dini_Float(Lol1, "Y");
      Z = dini_Float(Lol1, "Z");
      Angle = dini_Float(Lol1, "Angle");
      Color1 = dini_Int(Lol1, "Color1");
      Color2 = dini_Int(Lol1, "Color2");
      CreateVehicle(Model, X, Y, Z, Angle, Color1, Color2, 300);
      dini_IntSet(Lol1, "Spawned",1);
    }
    Cars = Cars + 1;
    SetTimer("LoadCars", 2, 0);
    //LoadCars();
    return 1;
  }
  CarDone:
  dini_IntSet("Vehicles/Main.ini","CarsLoaded",1);
  Cars = 0;
  print("\n\nCars Loaded");
  print("\n\nChecking For Unspawned Cars...");
  CarCheck();
  return 1;
}
By the way, CarCheck(); public just runs through to see if the car was spawned successfully according to all the details, just to make sure no errors occured or something was skipped over, and if it wasn't spawned correctly it will spawn it correctly.




By the way, a nice thing about storing all cars on file is the ease of adding new cars and changing things

Like you can add a new car that will always spawn every time you start your server by making a command
or you can change a vehicle model or a paintjob without ever leaving game.

This means no running in and out of game to your script and messing with colors and such. Less fuss.



Come to think of it maybe I will release the script, i'll think about it.






Good luck!
-Mike
Reply
#5

Thanks for the additional help, but wouldn't all those format and new variables cause some sort of memory hog?
If it gets called 100 times, that would be a lot of variables (or does pawn delete local variables after the function is done)?
Reply
#6

Quote:
Originally Posted by efeX
Thanks for the additional help, but wouldn't all those format and new variables cause some sort of memory hog?
If it gets called 100 times, that would be a lot of variables (or does pawn delete local variables after the function is done)?
Well it's storing it all in the same array anyway, it's not like I make a new array for every single car :P

As far as I am aware it overwrites the array if you set it to something else
Reply
#7

Oh yeah, duh me. It most likely overwrites the array :P

Anyways, I got it working, thanks for the help!

*Moves on to House system*
Reply
#8

Nice, btw I decided to release my Car filterscript

http://forum.sa-mp.com/index.php?topic=105540.0


Even though you already created yours you may use this if you need to :P



Good luck with the houses :P
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)