SA-MP Forums Archive
Vehicles spawning from a file - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicles spawning from a file (/showthread.php?tid=156399)



Vehicles spawning from a file - Faith - 22.06.2010

Hello,

So I have a private vehicle ownership system. You can park it and it saves the coords to a file, in this format:
149=Your_Name 546.5502 -1279.4332 17.2482 295.4557, 526

Vehicleid=Owner's name, X, Y, Z, A, model

Now the question is how to make it spawn at the saved coords in-case the server restarts / crashes? I just can't think of anything... Any help?

Much appreciated,




Re: Vehicles spawning from a file - Faith - 22.06.2010

I currently have this... As you can see it takes information from the file to create the vehicles. The problem is the loop.
It only creates the first vehicle on the list and even so, the vehicle ID it takes is messed up... The #define MAX_VEHS is at 200.

Any idea of what could be wrong and a fix? Thanks



pawn Код:
for(new i = 0; i < MAX_VEHS; i++)
    {
      new Float:X, Float:Y, Float:Z, Float:A, color1, color2, model;
        new veh[5], get_veh[128], pos;

        for(new v = 0; v < 7; v++)
        {
            format(veh, sizeof(veh), "%d", i);
            format(get_veh, sizeof(get_veh), "%s", dini_Get("vehs", veh));
            pos = strfind(get_veh, " ", true);
            strdel(get_veh, 0, pos + 1);

            if(v == 0)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, pos, strlen(get_veh));

                X = strval(get_veh);
            }

            if(v == 1)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, pos, strlen(get_veh));

                Y = strval(get_veh);
            }

            if(v == 2)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, pos, strlen(get_veh));

                Z = strval(get_veh);
            }

            if(v == 3)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                A = strval(get_veh);
            }
            if(v == 4)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

        pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                color1 = strval(get_veh);
            }
            if(v == 5)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

        pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                color2 = strval(get_veh);
            }
            if(v == 6)
            {
                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

        pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                pos = strfind(get_veh, " ", true);
                strdel(get_veh, 0, pos + 1);

                model = strval(get_veh);
            }
 }

        Cars[i] = CreateVehicle(model, X, Y, Z, A, color1, color2, -1);
        }



Re: Vehicles spawning from a file - (SF)Noobanatior - 22.06.2010

in the file are the values split by " " or ","?
and have you tryed printing model,x,y,z,a,c1,c2 just before you make the car to see what there values are


Re: Vehicles spawning from a file - Faith - 22.06.2010

it's split by " "

And ill try printing and edit this post.

This is how it prints: [14:28:03] 562, 1141407744, -996155392, 1099431936, 1133740032, 1, 1
model, X, Y, Z, A, color1, color2

Only problem is that it prints 200 times (The size of MAX_VEHS)... and it takes a very high vehicle ID. Is there a way to only create the vehicles that are in the file?


Re: Vehicles spawning from a file - (SF)Noobanatior - 22.06.2010

Код:
if(!dini_Isset(filename[],key[]))continue;
will check if the key exists and if not continue the loop
but if you have cars in order from 0 then you might be better to use "break"
as once the key dosent exist then there are no more veh lines so kill the loop
Код:
if(!dini_Isset(filename[],key[]))break;



Re: Vehicles spawning from a file - Faith - 22.06.2010

Thanks, it seems to work.

You're always of great help, Noobanatior, appreciate it. Keep going this way, people like you make this community great.


Re: Vehicles spawning from a file - (SF)Noobanatior - 22.06.2010

not a problem