Little help with strmid - 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)
+--- Thread: Little help with strmid (
/showthread.php?tid=281672)
Little help with strmid -
FireCat - 07.09.2011
If I have to words in Forbidenwords ex:
Totalwords=2
Word_1=Fuck
Word_2=Shit
It only loads the first word

Why?
pawn Код:
function LoadForbidenWords()
{
INI_Open("FAdmin/Logs/Forbidenwords.txt");
if(INI_ReadInt("Totalwords") == 0) return 0;
new totalwords = INI_ReadInt("Totalwords");
new string[64];
new key[20];
for(new i = 1; i < totalwords;i++)
{
format(string, sizeof(string), "Word_%i", i), INI_ReadString(key,string),strmid(ForbidenWords[i], key, 0, 20, sizeof(ForbidenWords));
printf("Words loaded: %s",ForbidenWords[i]);
}
INI_Close();
return 1;
}
Re: Little help with strmid -
[WSF]ThA_Devil - 07.09.2011
pawn Код:
function LoadForbidenWords()
{
INI_Open("FAdmin/Logs/Forbidenwords.txt");
if(INI_ReadInt("Totalwords") == 0) return 0;
new totalwords = INI_ReadInt("Totalwords");
new string[64];
new key[20];
for(new i = 0; i < totalwords+1;i++)
{
format(string, sizeof(string), "Word_%i", i), INI_ReadString(key,string),strmid(ForbidenWords[i], key, 0, 20, sizeof(ForbidenWords));
printf("Words loaded: %s",ForbidenWords[i]);
}
INI_Close();
return 1;
}
problem was in loop.. you must start from 0!
problem 2 u format string but you don't do anything with it
EDIT1: You need add 1 more into varriable totalwords like you have 2 words but u must have 3!
Re: Little help with strmid -
Vince - 07.09.2011
I don't think it's a good idea to use ini files for something like this. The name of the key is not important and therefor using ini is pointless. Using plain text file:
pawn Код:
new
File:handle = fopen("FAdmin/Logs/Forbidenwords.txt", io_read),
word[32],
i;
if(handle)
{
while(fread(handle, word))
{
if(i >= sizeof(ForbiddenWords)) // Out of bounds protection
{
printf("Warning: Could not load more than %d words. Destination array is too small!");
break;
}
strcpy(ForbidenWords[i], word);
i++;
}
fclose(handle);
printf("Words loaded: %d", i);
}
else printf("Forbidden words file not found, or it could not be opened!");
pawn Код:
stock strcpy(dest[], const source[], maxlength=sizeof dest)
{
strcat((dest[0] = EOS, dest), source, maxlength);
}
I just typed this out of my head, but I think it would work.