Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Run it when the game starts.
- This loads the basic data that is needed even when a race isn't active.
- */
- LoadRaceTrackData()
- {
- new
- File:idxFile,
- line[256],
- idx;
- if(fexist(RACE_INDEX_FILE))return print("ERROR! Race index file not found!");
- idxFile = fopen(RACE_INDEX_FILE, io_read);
- while(fread(idxFile, line))
- {
- /*
- An index file line might look like this:
- In INI format so there is an = sign to take into account.
- This way, you can easily write back into the file and replace
- lines by using the Race Name as the 'key' in any good INI script.
- And remember, we don't have to load it using an INI script,
- just tell SSCANF to look for an '=' after the first string
- A name
- B weather
- C time
- D best player
- E best time
- ...
- (Look in any of the GTA data files to see where I got this idea from!)
- A = B C D E maybe some other types of data...
- The Big Ear Race 1 = 7, 12, [HLF]Southclaw, 573758, moar numbarz!
- */
- if(sscanf(line, "p<=> s[32] p<,> d d s[24] d",
- // A global array that holds all the race data
- RaceData[idx][race_name],
- RaceData[idx][race_weather],
- RaceData[idx][race_time],
- RaceData[idx][race_bestplayer],
- RaceData[idx][race_besttime] )) printf("ERROR: Race data index %d invalid format", idx);
- else idx++; // Each race gets an ID, but the 'else' is to make sure the ID only increments on valid races.
- }
- return 1;
- }
- /*
- In the folder with the race index file in it, you have all the files named after the races too.
- These contain the coordinates for other crap like objects, checkpoints, pickups all that stuff.
- Those two lines above are exactly the same length!
- You can either use this load function at the start of each race, then unload all the stuff afterwards
- OR
- Load it all into memory on the above function (In the while loop) while the server is starting.
- If there's a lot of data, it would be best to load it at the start, but if there's not much then loading it
- in runtime should be fine.
- */
- LoadRaceData(racename[])
- {
- new
- /*
- 32 is the max race name (You should probably define this as MAX_RACE_NAME I guess)
- The extra is for the file extension and folder
- In this example, I use the folder called "races" and the extension ".dat" so that's an extra 9 characters
- */
- filename[32 + 9],
- File:datFile,
- line[256],
- chckpt_idx, // I like variables being the same length if they are related in some way...
- pickup_idx, // Bad habit I think, but it makes it easier to read for me.
- pickup_idx; // I'm sure Y_Less or Slice would disagree and say it's stupid idea!
- format(filename, sizeof(filename), "races/%s.dat", racename);
- if(!fexist(filename))return printf("ERROR: Race data file '%s' not found!", filename);
- else datFile = fopen(filename, io_read);
- while(fread(datFile, line))
- {
- /*
- I'm assuming you want Checkpoints, Pickups and Objects, here are the parameters for each:
- chckpt(x, y, z)
- object(x, y, z, rx, ry, rz, model)
- pickup(x, y, z, type)
- I can't think of any more params, but you get the idea (Easy to change this anyways)
- */
- // Checkpoints
- if (!sscanf(line, "'chckpt(' p<,> f f p<)> f", /* some array you hold checkpoint positions in*/ )) // As you can see here
- {
- // Create it with whatever you create checkpoints with
- chckpt_idx++;
- }
- // Objects
- else if (!sscanf(line, "'object(' p<,> fff fff p<)> d", /* some array you hold object positions in*/ )) // I am quite obsessive about
- {
- // Create the object and do what you want with it
- object_idx++;
- }
- // Pickups
- else if (!sscanf(line, "'pickup(' p<,> fff p<)> d", /* some array you hold object positions in*/ )) // Lines being the same length if they are similar!
- {
- // Create the pickup etc
- pickup_idx++:
- }
- // Unrecognised lines (Blank lines, comments or broken data lines)
- else
- {
- /*
- If you intend to have blank lines or comments in your data files, leave the else condition out.
- Otherwise, put an error code message on it!
- */
- }
- }
- return 1;
- }
- #endinput
- An example of a simple race file:
- index.ini:
- Chilliad Race=12, 7, Patrik356b, 5375375
- SomeOtherRace=47, 3, Southclaw, 379537635
- -end of file-
- Chilliad Race.dat:
- ; checkpoints (this is a comment!)
- chckpt(5738.3, 3485.38, 3765.36)
- chckpt(3356.3, 3664.38, 4623.36)
- chckpt(3662.3, 4623.38, 4624.36)
- ; some objects
- object(8527.34, 8759.43, 5787.86, 0.0, 90.0, 0.0, 1337)
- object(4652.34, 2676.43, 7437.86, 0.0, 90.0, 0.0, 345)
- object(4326.34, 4326.43, 4363.86, 0.0, 60.0, 90.0, 3756)
- object(3462.34, 7373.43, 4326.86, 180.0, 0.0, 45.0, 2424)
- ; some pickups
- pickup(8386.38, 3673.75, 3863.38, 0)
- pickup(3624.38, 4674.75, 4373.38, 1)
- ; maybe the pickup types are 0 = nitro 1 = repair
- -end of file-
- Randomly generated coordinates, probably mean nothing!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement