Creating vehicle on gamemode init, Loading data from file
#1

So, I am *trying* to make a car ownership..
Its going 50/50...

Sometimes Im sitting here with the hands in my hair like "AAARGGG"

Now, I made it so that the car info ( model, color, coordinates etc.. ) save in a file called 1.ini, 2.ini, 3.ini etc...

Now, How to create a car every time the server starts?
Not just one car. All cars that exist..
is this possible?(it should be..)
And if yes, how or what direction should I go.

some piece of code I have for loading(it is probably entirly wrong but whatever..)

pawn Код:
{
    for(new i = 1; i < MAX_VEHICLES; i++)
    {
    format(file4,sizeof(file4), "realityrp/vehicles/%d.ini", i);
    if (!dini_Exists(file4))
    {
        format(file4,sizeof(file4), "realityrp/vehicles/%d.ini", i);
        CarInfo[i][model] = dini_Int(file4, "model");
        CarInfo[i][owner] = dini_Int(file4, "owner");
        CarInfo[i][forsale] = dini_Int(file4, "forsale");
        CarInfo[i][vehx] = dini_Int(file4, "vehx");
        CarInfo[i][vehy] = dini_Int(file4, "vehy");
        CarInfo[i][vehz] = dini_Int(file4, "vehz");
        CarInfo[i][rot] = dini_Int(file4, "rot");
        CarInfo[i][vcol1] = dini_Int(file4, "vcol1");
        CarInfo[i][vcol2] = dini_Int(file4, "vcol2");
        new modv = dini_Int(file4, "model");
        new flx = dini_Int(file4, "vehx");
        new fly = dini_Int(file4, "vehy");
        new flz = dini_Int(file4, "vehz");
        new flr = dini_Int(file4, "rot");
        new fc1 = dini_Int(file4, "vcol1");
        new fc2 = dini_Int(file4, "vcol2");
        PrCar[CarID] = CreateVehicle(modv, flx, fly, flz, flr, fc1, fc2, 6000000);
        return 1;
        }
    }
    return 1;
}
This is the code for the Buying(and setting car info)

pawn Код:
new vehc = GetPlayerVehicleID(playerid);
                new vehmod = GetVehicleModel(vehc);
                new ownedcar;
                format(file9,sizeof(file9),"realityrp/vehicles/Vindex.ini");
                PlayerInfo[playerid][Vehkey] = PlayerInfo[playerid][Vehkey] + 1;
                GivePlayerMoney(playerid, - vehmod);
                dini_IntSet(file9, "topnumber",Index[topnumber] = Index[topnumber] + 1);
                format(file4,sizeof(file3), "realityrp/vehicles/%d.ini", Index[topnumber] + 1);
                dini_Create(file4);
                dini_IntSet(file4, "model", CarInfo[Pcar][model] = vehmod);
                dini_IntSet(file4, "owner", CarInfo[Pcar][owner] = PlayerInfo[playerid][Pid]);
                dini_IntSet(file4, "forsale",CarInfo[Pcar][forsale] = 0);
                dini_IntSet(file4, "vehx",CarInfo[Pcar][vehx] = -1580);
                dini_IntSet(file4, "vehy",CarInfo[Pcar][vehy] = 106);
                dini_IntSet(file4, "vehz",CarInfo[Pcar][vehz] = 4);
                dini_IntSet(file4, "rot",CarInfo[Pcar][rot] = 90);
                dini_IntSet(file4, "vcol1",CarInfo[Pcar][vcol1] = 0);
                dini_IntSet(file4, "vcol2",CarInfo[Pcar][vcol2] = 0);
                SendClientMessage(playerid, COLOR_GREEN, "You bought a car! its at San Fierro Docks");
                PrCar[CarID] = CreateVehicle(CarInfo[Pcar][model],CarInfo[Pcar][vehx],CarInfo[Pcar][vehy],CarInfo[Pcar][vehz],CarInfo[Pcar][rot],CarInfo[Pcar][vcol1],CarInfo[Pcar][vcol2],30000000);
                RemovePlayerFromVehicle(playerid);
                TogglePlayerControllable(playerid, 1);
Anyone have an idea?
Reply
#2

anybody have any idea?
btw its file4 and file9
Reply
#3

one thing i have to say for now is don't use dini... it's slow as fuck. use Y_Ini instead. it's simpler(at least for me lol) and way faster.

and for all cars that exist to be created, you would have to do something similar to this:

pawn Код:
//Variables u will need to spawn the cars


new Float:vehx;//coordinate X
new Float:vehy;//coordinate Y
new Float:vehz;//coordinate Z
new model;//ModelID integer right?
new Float:rot;//rotation
new vcol1;
new vcol2;

new Filename[30];//For the Fexist check

//Loop Starts Here

new i = 0;
Loopstart:
while(i < MAX_VEHICLES)
{
format(Filename, sizeof(Filename), "%d.ini",i);
if(!fexist(Filename))
{
   //i forgot if we can use break; here... can we? if we cant just goto Loopstart;
}
//Code you use to load them for files and put them in variables with whatever system your gonna use(no idea on how to use dini)
CreateVehicle(model, vehx, vehy, vehz, rot, vcol1, vcol2, Whatever_Spawn_Delay_You_Want);
i++;
}
Reply
#4

*bump* milanosie didnt say anything >>
Reply
#5

Yes you would break it if the file doesn't exist...or you could just do

pawn Код:
if(dini_Exists(somefile))
{
    for(new i=0; i<=MAX_VEHICLES; i++)
    {
        //stuff in here
    }
}
There's no point in using a while loop lol
Reply
#6

Quote:
Originally Posted by henry jiggy
Посмотреть сообщение
*bump* milanosie didnt say anything >>
Firstly you don't bump other peoples topics.

Secondly you don't double post before 24hours I suggest you read the forum rules before getting your ass banned.
Reply
#7

You can't add any code to the script IG... BY the way, you can make it create definitions in File, and, in the script, make a function to for example: CreateVehicle(id(make it read from file), posX(make it read from file), bla, bla bla)

Than, a publid named like LoadVehicles, and, when called, this function should read from the files, and using the function i said, create the vehicles.

You should call this function under OnPlayerGameModeInit, so, when server starts, it will load the cars.

Hope you understand, and hope i am not saying shit... :P
Reply
#8

Hum i like While loops bettah, and your code is kinda wrong as he would have 1 file per vehicle and your only checks once if a file exists :P.

Still i forgot if Break just skips 1 iteration or the whole loop...

and snowman im sorry its just that he was online replying to other topics and i needed to get his attention to this one...
Reply


Forum Jump:


Users browsing this thread: