[Tutorial] Making a dynamic organization/Fraction
#10

May I add that this is far from dynamic? Dynamic means the script is almost unlimitedly changable ingame, to most of the community members. This is just loading information from a file.. You're limited to 8 vehicles. Could've made that dynamic aswell, so you're not stuck with 8 vehicles. If you add a tutorial, please take your time to make it the most dynamic you can, and use the recent technologies. Also, explain. This would probably do better as a filterscript.

Furthermore the code is just very sloppy. Just take a look at this piece of code I grabbed literally from your snippet:

pawn Code:
if(cars == 1)
    {
    dini_IntSet(filo,"Model1",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X1",X);
    dini_FloatSet(filo,"Y1",Y);
    dini_FloatSet(filo,"Z1",Z);
    dini_FloatSet(filo,"A1",A);
    OrgInfo[orgids][Car1] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 2)
    {
    dini_IntSet(filo,"Model2",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X2",X);
    dini_FloatSet(filo,"Y2",Y);
    dini_FloatSet(filo,"Z2",Z);
    dini_FloatSet(filo,"A2",A);
    OrgInfo[orgids][Car2] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 3)
    {
    dini_IntSet(filo,"Model3",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X3",X);
    dini_FloatSet(filo,"Y3",Y);
    dini_FloatSet(filo,"Z3",Z);
    dini_FloatSet(filo,"A3",A);
    OrgInfo[orgids][Car3] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 4)
    {
    dini_IntSet(filo,"Model4",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X4",X);
    dini_FloatSet(filo,"Y4",Y);
    dini_FloatSet(filo,"Z4",Z);
    dini_FloatSet(filo,"A4",A);
    OrgInfo[orgids][Car4] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 5)
    {
    dini_IntSet(filo,"Model5",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X5",X);
    dini_FloatSet(filo,"Y5",Y);
    dini_FloatSet(filo,"Z5",Z);
    dini_FloatSet(filo,"A5",A);
    OrgInfo[orgids][Car5] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 6)
    {
    dini_IntSet(filo,"Model6",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X6",X);
    dini_FloatSet(filo,"Y6",Y);
    dini_FloatSet(filo,"Z6",Z);
    dini_FloatSet(filo,"A6",A);
    OrgInfo[orgids][Car6] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 7)
    {
    dini_IntSet(filo,"Model7",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X7",X);
    dini_FloatSet(filo,"Y7",Y);
    dini_FloatSet(filo,"Z7",Z);
    dini_FloatSet(filo,"A7",A);
    OrgInfo[orgids][Car7] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
    if(cars == 8)
    {
    dini_IntSet(filo,"Model8",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X8",X);
    dini_FloatSet(filo,"Y8",Y);
    dini_FloatSet(filo,"Z8",Z);
    dini_FloatSet(filo,"A8",A);
    OrgInfo[orgids][Car8] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    }
First of all, this can be optimised by using a loop:
pawn Code:
for(new i;i<8;i++)
{
    format(filo,11,"org_vehicle_%d.ini",i);
    dini_IntSet(filo,"Model",GetVehicleModel(GetPlayerVehicleID(playerid)));
    dini_FloatSet(filo,"X",X);
    dini_FloatSet(filo,"Y",Y);
    dini_FloatSet(filo,"Z",Z);
    dini_FloatSet(filo,"A",A);
    OrgVehInfo[i][Car] = CreateVehicle(GetVehicleModel(GetPlayerVehicleID(playerid)),X,Y,Z,A,-1,-1,-1);
    // I changed the variable above to a variable that would have to be declared:
    // new OrgVehInfo[8][EnumOfVehicle];
    // In combination with an enum this is an understandable way (for beginners) to store information.
}
This just saved you alot of lines of code, and it surely is more easy to oversee.

((Edit: I actually just noticed that the saved variables names have the numbering aswell: Why? It's more easy to save one vehicle per file, and have the same variable names. See example above.))

Then, I'd like to make a comment about the following like, which I also directly took from your snippet:
pawn Code:
format(filo,256,"org%d.ini",i);
Why in gods name use a 256 cell variable if you need way less? Your system has a limit of 13, which means the file name will never exceed 10 cells ("org13.ini"). To be perfectly sure, you could've made this 11 (this allows you to make 999 factions untill you need to resize the variable again). This saves you 245 cells, which means better speed.

I urgently hope you either change this tutorial or completely remove it. IF people even learn from this tutorial, they learn it the wrong way.

Good luck with writing future tutorials.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)