SA-MP Forums Archive
Spawning Multiple Vehicles But Only Need One - 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: Spawning Multiple Vehicles But Only Need One (/showthread.php?tid=258895)



Spawning Multiple Vehicles But Only Need One - AustinJ74 - 02.06.2011

Whole script is not given.
When I go onto my server four vehicles are created where the one vehicle should be.

Enumeration
PHP Code:
enum VehicleInfo {
    
Owner,
    
OwnerType,
    
Model,
    
Float:PosX,
    
Float:PosY,
    
Float:PosZ,
    
Float:PosA,
    
Color1,
    
Color2,
    
Mod0,
    
Mod1,
    
Mod2,
    
Mod3,
    
Mod4,
    
Mod5,
    
Mod6,
    
Mod7,
    
Mod8,
    
Mod9,
    
Mod10,
    
Mod11,
    
Mod12,
    
Mod13,
    
Paintjob,
    
ID
}
new 
vInfo[5000][VehicleInfo]; 
Forwards
PHP Code:
forward LoadVehicle(vehicleid);
forward SaveVehicle(vehicleid);
forward SaveVehicles(); 
OnGameModInit Callback
PHP Code:
public OnGameModeInit()
{
    
// ^^^ Other Crap ^^^ //
    
SetTimer("SaveVehicles"60000true);
    
    
LoadVehicle(0);
    
    return 
1;

Load Vehicle Public
PHP Code:
public LoadVehicle(vehicleid)
{
    new 
file[256];
    
format(file256"Vehicles/%i.ini"vehicleid);
    
format(vInfo[vehicleid][Owner], 256"%s"dini_Get(file"Owner"));
    
vInfo[vehicleid][OwnerType] = dini_Int(file"OwnerType");
    
vInfo[vehicleid][Model] = dini_Int(file"Model");
    
vInfo[vehicleid][PosX] = dini_Float(file"PosX");
    
vInfo[vehicleid][PosY] = dini_Float(file"PosY");
    
vInfo[vehicleid][PosZ] = dini_Float(file"PosZ");
    
vInfo[vehicleid][PosA] = dini_Float(file"PosA");
    
vInfo[vehicleid][Color1] = dini_Int(file"Color1");
    
vInfo[vehicleid][Color2] = dini_Int(file"Color2");
    
vInfo[vehicleid][Mod0] = dini_Int(file"Mod0");
    
vInfo[vehicleid][Mod1] = dini_Int(file"Mod1");
    
vInfo[vehicleid][Mod2] = dini_Int(file"Mod2");
    
vInfo[vehicleid][Mod3] = dini_Int(file"Mod3");
    
vInfo[vehicleid][Mod4] = dini_Int(file"Mod4");
    
vInfo[vehicleid][Mod5] = dini_Int(file"Mod5");
    
vInfo[vehicleid][Mod6] = dini_Int(file"Mod6");
    
vInfo[vehicleid][Mod7] = dini_Int(file"Mod7");
    
vInfo[vehicleid][Mod8] = dini_Int(file"Mod8");
    
vInfo[vehicleid][Mod9] = dini_Int(file"Mod9");
    
vInfo[vehicleid][Mod10] = dini_Int(file"Mod10");
    
vInfo[vehicleid][Mod11] = dini_Int(file"Mod11");
    
vInfo[vehicleid][Mod12] = dini_Int(file"Mod12");
    
vInfo[vehicleid][Mod13] = dini_Int(file"Mod13");
    
vInfo[vehicleid][Paintjob] = dini_Int(file"Paintjob");
    
vInfo[vehicleid][ID] = CreateVehicle(vInfo[vehicleid][Model], vInfo[vehicleid][PosX], vInfo[vehicleid][PosY], vInfo[vehicleid][PosZ], vInfo[vehicleid][PosA], vInfo[vehicleid][Color1], vInfo[vehicleid][Color2], -1);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod0]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod1]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod2]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod3]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod4]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod5]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod6]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod7]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod8]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod9]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod10]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod11]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod12]);
    
AddVehicleComponent(vInfo[vehicleid][ID], vInfo[vehicleid][Mod13]);
    
ChangeVehiclePaintjob(vInfo[vehicleid][ID], vInfo[vehicleid][Paintjob]);
    return 
1;

Save Vehicle Public
PHP Code:
public SaveVehicle(vehicleid)
{
    new 
file[256];
    
format(file256"Vehicles/%i.ini"vehicleid);
    if(!
dini_Exists(file))
    {
        
dini_Create(file);
    }
    
dini_Set(file"Owner"vInfo[vehicleid][Owner]);
    
dini_IntSet(file"OwnerType"vInfo[vehicleid][OwnerType]);
    
dini_IntSet(file"Model"vInfo[vehicleid][Model]);
    
dini_FloatSet(file"PosX"vInfo[vehicleid][PosX]);
    
dini_FloatSet(file"PosY"vInfo[vehicleid][PosY]);
    
dini_FloatSet(file"PosZ"vInfo[vehicleid][PosZ]);
    
dini_FloatSet(file"PosA"vInfo[vehicleid][PosA]);
    
dini_IntSet(file"Color1"vInfo[vehicleid][Color1]);
    
dini_IntSet(file"Color2"vInfo[vehicleid][Color2]);
    
dini_IntSet(file"Mod0"vInfo[vehicleid][Mod0]);
    
dini_IntSet(file"Mod1"vInfo[vehicleid][Mod1]);
    
dini_IntSet(file"Mod2"vInfo[vehicleid][Mod2]);
    
dini_IntSet(file"Mod3"vInfo[vehicleid][Mod3]);
    
dini_IntSet(file"Mod4"vInfo[vehicleid][Mod4]);
    
dini_IntSet(file"Mod5"vInfo[vehicleid][Mod5]);
    
dini_IntSet(file"Mod6"vInfo[vehicleid][Mod6]);
    
dini_IntSet(file"Mod7"vInfo[vehicleid][Mod7]);
    
dini_IntSet(file"Mod8"vInfo[vehicleid][Mod8]);
    
dini_IntSet(file"Mod9"vInfo[vehicleid][Mod9]);
    
dini_IntSet(file"Mod10"vInfo[vehicleid][Mod10]);
    
dini_IntSet(file"Mod11"vInfo[vehicleid][Mod11]);
    
dini_IntSet(file"Mod12"vInfo[vehicleid][Mod12]);
    
dini_IntSet(file"Mod13"vInfo[vehicleid][Mod13]);
    
dini_IntSet(file"Paintjob"vInfo[vehicleid][Paintjob]);
    return 
1;

Save Vehicles Public
PHP Code:
public SaveVehicles()
{
    for(new 
vehicleid 0vehicleid 5000vehicleid++)
    {
        if(
vInfo[vehicleid][Model])
        {
            new 
file[256];
            
format(file256"Vehicles/%i.ini"vehicleid);
            if(!
dini_Exists(file))
            {
                
dini_Create(file);
            }
            
dini_Set(file"Owner"vInfo[vehicleid][Owner]);
            
dini_IntSet(file"OwnerType"vInfo[vehicleid][OwnerType]);
            
dini_IntSet(file"Model"vInfo[vehicleid][Model]);
            
dini_FloatSet(file"PosX"vInfo[vehicleid][PosX]);
            
dini_FloatSet(file"PosY"vInfo[vehicleid][PosY]);
            
dini_FloatSet(file"PosZ"vInfo[vehicleid][PosZ]);
            
dini_FloatSet(file"PosA"vInfo[vehicleid][PosA]);
            
dini_IntSet(file"Color1"vInfo[vehicleid][Color1]);
            
dini_IntSet(file"Color2"vInfo[vehicleid][Color2]);
            
dini_IntSet(file"Mod0"vInfo[vehicleid][Mod0]);
            
dini_IntSet(file"Mod1"vInfo[vehicleid][Mod1]);
            
dini_IntSet(file"Mod2"vInfo[vehicleid][Mod2]);
            
dini_IntSet(file"Mod3"vInfo[vehicleid][Mod3]);
            
dini_IntSet(file"Mod4"vInfo[vehicleid][Mod4]);
            
dini_IntSet(file"Mod5"vInfo[vehicleid][Mod5]);
            
dini_IntSet(file"Mod6"vInfo[vehicleid][Mod6]);
            
dini_IntSet(file"Mod7"vInfo[vehicleid][Mod7]);
            
dini_IntSet(file"Mod8"vInfo[vehicleid][Mod8]);
            
dini_IntSet(file"Mod9"vInfo[vehicleid][Mod9]);
            
dini_IntSet(file"Mod10"vInfo[vehicleid][Mod10]);
            
dini_IntSet(file"Mod11"vInfo[vehicleid][Mod11]);
            
dini_IntSet(file"Mod12"vInfo[vehicleid][Mod12]);
            
dini_IntSet(file"Mod13"vInfo[vehicleid][Mod13]);
            
dini_IntSet(file"Paintjob"vInfo[vehicleid][Paintjob]);
        }
    }
    return 
1;

/setvehicle command used to create vehicle file.
PHP Code:
dcmd_setvehicle(playeridparams[])
{
    if(
pInfo[playerid][Rank] >= 3)
    {
        new 
owner[256], ownertypecolor1color2;
        if(
sscanf(params"siii"ownerownertypecolor1color2))
        {
            
SendClientMessage(playeridCOLOR_PINK"   Usage: /setvehicle [owner] [ownertype] [color1] [color2]");
            
SendClientMessage(playeridCOLOR_PINK"      [Owners] Factions: 1(Police) 2(EMS)");
            
SendClientMessage(playeridCOLOR_PINK"      [Owner Types] 1(Player) 2(Faction) 3(Public)");
        }
        else if(
ownertype || ownertype 3)
        {
            
SendClientMessage(playeridCOLOR_ORANGE"   Invalid Owner Type");
        }
        else if(
color1 || color1 256)
        {
            
SendClientMessage(playeridCOLOR_ORANGE"   Invalid Color1");
        }
        else if(
color2 || color2 256)
        {
            
SendClientMessage(playeridCOLOR_ORANGE"   Invalid Color2");
        }
        else
        {
            for(new 
vehicleid 0vehicleid 5000vehicleid++)
            {
                if(
vInfo[vehicleid][Model] == 0)
                {
                    
format(vInfo[vehicleid][Owner], 256"%s"owner);
                    
vInfo[vehicleid][OwnerType] = ownertype;
                    
vInfo[vehicleid][Model] = GetVehicleModel(GetPlayerVehicleID(playerid));
                    new 
Float:xFloat:yFloat:zFloat:a;
                    
GetVehiclePos(GetPlayerVehicleID(playerid), xyz);
                    
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
                    
vInfo[vehicleid][PosX] = x;
                    
vInfo[vehicleid][PosY] = y;
                    
vInfo[vehicleid][PosZ] = z;
                    
vInfo[vehicleid][PosA] = a;
                    
vInfo[vehicleid][Color1] = color1;
                    
vInfo[vehicleid][Color2] = color2;
                    new 
output[256];
                    
format(output256"   Vehicle File(%i) Created"vehicleid);
                    return 
SendClientMessage(playeridCOLOR_WHITEoutput);
                }
            }
            
SendClientMessage(playeridCOLOR_ORANGE"   Vehicle Limit Reached");
        }
    }
    else
    {
        
SendClientMessage(playeridCOLOR_GREY"   Commmand Doesn't Exists");
    }
    return 
1;

Vehicles/0.ini File - "Owner" should equal nobody no reason why.
PHP Code:
Owner=Nљ’nKЊ
OwnerType
=3
Model
=410
PosX
=1291.799072
PosY
=343.792419
PosZ
=19.206686
PosA
=65.997161
Color1
=3
Color2
=3
Mod0
=0
Mod1
=0
Mod2
=0
Mod3
=0
Mod4
=0
Mod5
=0
Mod6
=0
Mod7
=0
Mod8
=0
Mod9
=0
Mod10
=0
Mod11
=0
Mod12
=0
Mod13
=0
Paintjob
=
This is from my custom script. Please do not steal. Only posted for debugging purposes.


Re: Spawning Multiple Vehicles But Only Need One - Backwardsman97 - 02.06.2011

Fairly memory-heavy array. I'm pretty sure you won't be able to save anything to 'Owner' because that'd be acting as a 3D array and pawn only supports 2D arrays. You could just not use the enumeration and just give them the same name in front. Example.

pawn Code:
new VehicleOwner        [MAX_VEHICLES][MAX_PLAYER_NAME];
new VehicleOwnerType    [MAX_VEHICLES];
new VehicleModel        [MAX_VEHICLES];
new Float:VehiclePosX   [MAX_VEHICLES];
new Float:VehiclePosY   [MAX_VEHICLES];
new Float:VehiclePosZ   [MAX_VEHICLES];
new Float:VehiclePosA   [MAX_VEHICLES];
new VehicleColor1       [MAX_VEHICLES];
new VehicleColor2       [MAX_VEHICLES];
new VehicleMod0         [MAX_VEHICLES];
new VehicleMod1         [MAX_VEHICLES];
new VehicleMod2         [MAX_VEHICLES];
new VehicleMod3         [MAX_VEHICLES];
new VehicleMod4         [MAX_VEHICLES];
new VehicleMod5         [MAX_VEHICLES];
new VehicleMod6         [MAX_VEHICLES];
new VehicleMod7         [MAX_VEHICLES];
new VehicleMod8         [MAX_VEHICLES];
new VehicleMod9         [MAX_VEHICLES];
new VehicleMod10        [MAX_VEHICLES];
new VehicleMod11        [MAX_VEHICLES];
new VehicleMod12        [MAX_VEHICLES];
new VehicleMod13        [MAX_VEHICLES];
new VehiclePaintjob     [MAX_VEHICLES];
Lol it seems like a lot but it should be faster then what you're using now because it only has one multi-dimensional array. Then, for the name situation, you could do this when you load up the vehicles.

pawn Code:
format(VehicleOwner[vehicleid], MAX_PLAYER_NAME, "%s", dini_Get(file, "Owner"));
if(!strlen(VehicleOwner[vehicleid]))
     VehicleOwner[vehicleid] = "Nobody";



Re: Spawning Multiple Vehicles But Only Need One - Mike Garber - 02.06.2011

Quote:
Originally Posted by Backwardsman97
View Post
Fairly memory-heavy array. I'm pretty sure you won't be able to save anything to 'Owner' because that'd be acting as a 3D array and pawn only supports 2D arrays. You could just not use the enumeration and just give them the same name in front. Example.

pawn Code:
new VehicleOwner        [MAX_VEHICLES][MAX_PLAYER_NAME];
new VehicleOwnerType    [MAX_VEHICLES];
new VehicleModel        [MAX_VEHICLES];
new Float:VehiclePosX   [MAX_VEHICLES];
new Float:VehiclePosY   [MAX_VEHICLES];
new Float:VehiclePosZ   [MAX_VEHICLES];
new Float:VehiclePosA   [MAX_VEHICLES];
new VehicleColor1       [MAX_VEHICLES];
new VehicleColor2       [MAX_VEHICLES];
new VehicleMod0         [MAX_VEHICLES];
new VehicleMod1         [MAX_VEHICLES];
new VehicleMod2         [MAX_VEHICLES];
new VehicleMod3         [MAX_VEHICLES];
new VehicleMod4         [MAX_VEHICLES];
new VehicleMod5         [MAX_VEHICLES];
new VehicleMod6         [MAX_VEHICLES];
new VehicleMod7         [MAX_VEHICLES];
new VehicleMod8         [MAX_VEHICLES];
new VehicleMod9         [MAX_VEHICLES];
new VehicleMod10        [MAX_VEHICLES];
new VehicleMod11        [MAX_VEHICLES];
new VehicleMod12        [MAX_VEHICLES];
new VehicleMod13        [MAX_VEHICLES];
new VehiclePaintjob     [MAX_VEHICLES];
Lol it seems like a lot but it should be faster then what you're using now because it only has one multi-dimensional array. Then, for the name situation, you could do this when you load up the vehicles.

pawn Code:
format(VehicleOwner[vehicleid], MAX_PLAYER_NAME, "%s", dini_Get(file, "Owner"));
if(!strlen(VehicleOwner[vehicleid]))
     VehicleOwner[vehicleid] = "Nobody";
What's the point of that?
It's the same thing, it's like if you buy a carton of cigarettes, it's 10 packs of cigarettes in one carton.
But your way is instead 10 packets separately, it's still just as many cigarettes.

To save to the Owner thing, just change the enum to Owner[24], and use format(vInfo[vehicleid][Owner],24,"Owner");