View Full Version : Loading Labels

21/11/2011, 05:10 PM
Hi , I have a problem with ingame label maker. I made label,pickup,mapicon ingame maker but I don't know how to make a loading system. They are saved with y_ini but i don't know how to make some function like LoadLabels , LoadMapIcons etc... So they can load automatically on each restart.

21/11/2011, 09:53 PM
Read the file, then create the labels directly from the file,

#include <a_samp>
#include <sscanf>

public OnFilterScriptInit()
printf("Loaded labels: %d",LoadLabels());
return 1;

stock LoadLabels()
new File:fh;//declare a file handle
fh = fopen("MySaved.labels",io_read);//open the file "scriptfiles/MySaved.labels" in read-only mode | We do not want to write anything
new string[256];//declare a array for storing our information from each line of the file
new Float:position[3];//Our position of the label..
new Float:Drawdistance;
new Labeltext[128];//Our label text
new color;//the color
new virtualworld;//...
new testLOS;//...
new counter = 0; // just a counter to measure how much labels we added
while(fread(fh,string))//Read till end of file (EOF), put each line in 'string' (1 line at a time) | this is a loop
if(sscanf(string,"xffffiis[128]",color,position[0],position[1],position[2],Drawdistance,virtualworld,testLOS,Labeltext))//extract the data from string to all variables
//data cannot be extracted, wrong format
//succesfully extracted data, adding the label below
return counter;//return the amount of added labels

/* example file content:
0xFFFFFF 0.543 345.345 5764.3457 100.00 0 1 Hello my dear friend!

if you don't understand that code you should first learn something easier (but if you don't undestand sscanf, you can try strtok [not recommended] or just learn how to use it, I'm sure you will need it in the future)

22/11/2011, 12:25 PM
Thanks ! No I'm not a beginner but I just couldn't find to way to load them , thanks :)

I have a different problem now. I pasted your code into my script and when I pasted it and tried to run server it crashes. Without your code it doesn't crash , can you help ? :D

22/11/2011, 05:51 PM
you shouldn't just mindless copy & paste the code, it's for educational purposes (only?)!
Please lookup every function used in the code on the sa-mp wiki.