[Tutorial] How to make use of Grand Larceny vehicles.
#1

How to make use of Grand Larceny vehicles

[TUTORIAL]

-------------------------------------------------------------------------------------------------------------------------------------

Hello people! How are you? This is my first ever tutorial, don't be so hard on me!

I noticed no one has made a tutorial on how to actually properly load and make use of the vehicles in the default Grand Larceny game mode.

This is a simple tutorial to show you how!


-------------------------------------------------------------------------------------------------------------------------------------

Step 1:

Go to your pawno/include folder and copy any .inc file. Paste it and it should show filename - copy.inc. Now, open that file and delete everything inside it.

Why? Because later on, I will provide a stock. LoadStaticVehiclesFromFile something used in the Grand Larceny game mode. The stock which I provided above makes LoadStaticVehiclesFromFile usable outside of Grand Larceny.


Step 2:

Rename the file to loadvehicles and replace the contents with this:
PHP Code:
stock LoadStaticVehiclesFromFile(const filename[])
{
    new 
File:file_ptr;
    new 
line[256];
    new 
var_from_line[64];
    new 
vehicletype;
    new 
Float:vSpawnX;
    new 
Float:vSpawnY;
    new 
Float:vSpawnZ;
    new 
Float:SpawnRot;
    new 
Color1Color2;
    new 
index;
    new 
vehicles_loaded;
    
file_ptr fopen(filename,filemode:io_read);
    if(!
file_ptr) return 0;
    
vehicles_loaded 0;
    while(
fread(file_ptr,line,256) > 0)
    {
        
index 0;
        
// Read type
          
index token_by_delim(line,var_from_line,',',index);
          if(
index == (-1)) continue;
          
vehicletype strval(var_from_line);
           if(
vehicletype 400 || vehicletype 611) continue;
          
// Read X, Y, Z, Rotation
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
vSpawnX floatstr(var_from_line);
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
vSpawnY floatstr(var_from_line);
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
vSpawnZ floatstr(var_from_line);
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
SpawnRot floatstr(var_from_line);
          
// Read Color1, Color2
          
index token_by_delim(line,var_from_line,',',index+1);
          if(
index == (-1)) continue;
          
Color1 strval(var_from_line);
          
index token_by_delim(line,var_from_line,';',index+1);
          
Color2 strval(var_from_line);
          
AddStaticVehicleEx(vehicletype,vSpawnX,vSpawnY,vSpawnZ,SpawnRot,Color1,Color2,180); // respawn 3 minutes
        
vehicles_loaded++;
    }
    
fclose(file_ptr);
    
printf("Loaded %d vehicles from: %s",vehicles_loaded,filename);
    return 
vehicles_loaded;
}
stock token_by_delim(const string[], return_str[], delimstart_index)
{
    new 
x=0;
    while(
string[start_index] != EOS && string[start_index] != delim) {
        
return_str[x] = string[start_index];
        
x++;
        
start_index++;
    }
    
return_str[x] = EOS;
    if(
string[start_index] == EOSstart_index = (-1);
    return 
start_index;

Step 3:

Go to your game mode and add this:
PHP Code:
#include <loadvehicles> 
Step 4:

Under OnGameModeInit, add LoadStaticVehiclesFromFile("vehicles/file.txt");
I will show all possible vehicle loads below.


Step 5:

Start your server!

-------------------------------------------------------------------------------------------------------------------------------------

There are 19 possible LoadStaticVehicle files

You can tell what the vehicles will be loaded with the file names.
PHP Code:
//Possible Vehicle Loads
LoadStaticVehiclesFromFile("vehicles/bone.txt");
LoadStaticVehiclesFromFile("vehicles/flint.txt");
LoadStaticVehiclesFromFile("vehicles/ls_airport.txt");
LoadStaticVehiclesFromFile("vehicles/ls_gen_inner.txt");
LoadStaticVehiclesFromFile("vehicles/ls_gen_outer.txt");
LoadStaticVehiclesFromFile("vehicles/ls_law.txt");
LoadStaticVehiclesFromFile("vehicles/lv_airport.txt");
LoadStaticVehiclesFromFile("vehicles/lv_gen.txt");
LoadStaticVehiclesFromFile("vehicles/lv_law.txt");
LoadStaticVehiclesFromFile("vehicles/pilots.txt");
LoadStaticVehiclesFromFile("vehicles/red_county.txt");
LoadStaticVehiclesFromFile("vehicles/sf_airport.txt");
LoadStaticVehiclesFromFile("vehicles/sf_gen.txt");
LoadStaticVehiclesFromFile("vehicles/sf_law.txt");
LoadStaticVehiclesFromFile("vehicles/sf_train.txt");
LoadStaticVehiclesFromFile("vehicles/tierra.txt");
LoadStaticVehiclesFromFile("vehicles/trains.txt");
LoadStaticVehiclesFromFile("vehicles/trains_platform.txt");
LoadStaticVehiclesFromFile("vehicles/whetstone.txt"); 
-------------------------------------------------------------------------------------------------------------------------------------

That is pretty much how simple it is! Have fun!
Reply
#2

never mind ignore this
Reply
#3

It's not bad, but in the future, it would help to explain what some of the things do (like what's going on in the LoadStaticVehiclesFromFile function) to avoid more confusion.
Reply
#4

Quote:
Originally Posted by DTV
View Post
It's not bad, but in the future, it would help to explain what some of the things do (like what's going on in the LoadStaticVehiclesFromFile function) to avoid more confusion.
LoadStaticVehiclesFromFile something used in the Grand Larceny game mode. The stock which I provided above makes LoadStaticVehiclesFromFile usable outside of Grand Larceny.

-----

Thank you Sreyas for your encouragement!



-----

Quote:
Originally Posted by JaKe Elite
View Post
never mind ignore this
What?
Reply
#5

Not bad for your first time.
Good job.
Reply
#6

Quote:
Originally Posted by BurnZ
View Post
LoadStaticVehiclesFromFile something used in the Grand Larceny game mode. The stock which I provided above makes LoadStaticVehiclesFromFile usable outside of Grand Larceny.
Such explanations should be in the tutorial, not somewhere hidden in the replies.

"[...] Replace this [...] Add this [...] Copy this [...]" it's just instruction after instruction without making the reasoning clear to the reader. This is a forum for developers and most developers would also like to know WHY you use the code that you use and what it exactly does. Of course, more experienced developers can derive that from reading the code, but I don't see any of them reading this kind of tutorials.

I don't want to discourage you. Your will to contribute to the community is greatly appreciated!
Reply
#7

Quote:
Originally Posted by AndySedeyn
View Post
Such explanations should be in the tutorial, not somewhere hidden in the replies.

"[...] Replace this [...] Add this [...] Copy this [...]" it's just instruction after instruction without making the reasoning clear to the reader. This is a forum for developers and most developers would also like to know WHY you use the code that you use and what it exactly does. Of course, more experienced developers can derive that from reading the code, but I don't see any of them reading this kind of tutorials.

I don't want to discourage you. Your will to contribute to the community is greatly appreciated!
I didn't even think of explaining until that person above asked me to. As I said, this is my first tutorial. Thank you for your guidance.
Reply
#8

UPDATE: Edited the post and added explanations to assist scripters in understanding what they are doing.
Reply
#9

It's a function not a "stock".
Have a look here: https://sampforum.blast.hk/showthread.php?tid=570635
Reply
#10

Quote:
Originally Posted by GoldenLion
View Post
It's a function not a "stock".
Have a look here: https://sampforum.blast.hk/showthread.php?tid=570635
^I didn't know about that! Thanks for the heads up!
Reply
#11

Quote:
Originally Posted by BurnZ
View Post
^I didn't know about that! Thanks for the heads up!
Lmao no problem, I share the link in every thread where people call functions stocks.
The tutorial is OK as it's your first tutorial. :P
Reply
#12

This is a very outdated function.

I've re-written the function to work with sscanf.
Code:
LoadStaticVehiclesFromFile(const filename[])
{
    static
        line[145],

        model,
        Float: x,
        Float: y,
        Float: z,
        Float: r,

        color1,
        color2,

        len,
        count = 0
    ;

    new
        File: handle = fopen(filename, io_read);
    if (!handle)
        return 0;

    while ((len = fread(handle, line)))
    {
        line[len-2] = 0;
        print(line);
        if (sscanf(line, "P<(),>{s[17]}iffffii", model, x, y, z, r, color1, color2))
            continue;
        if (!(399 < model < 612))
            continue;

        AddStaticVehicleEx(model, x, y, z, r, color1, color2, 180); // Respawns in 3 minutes (180 seconds)
        count++;
    }
    fclose(handle);
    
    printf("Loaded %i vehicles from: %s", count, filename);
    return count;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)