Hey, ich versuche in meinem langfiles system einzubauen, dass man eine andere zeilde im File direkt einbauen kann.
Hier der zuständige Code:
stock GetLangVar(Lang[3],Name[60],const Format[],Str[],length,{Float,_}:...)
{
new FileDest[80], key[256], Data[850];
if(strfind(Name, ":", true) != -1) //Find an FileVar
{
new pos = strfind(Name, ":", true);
new FileVar[15];
strmid(FileVar,Name,0,pos);
strdel(Name,0,pos+1);
format(FileDest, sizeof(FileDest), "DTLangFiles/%s_%s_%s.txt",DT_lf_prefix, FileVar, Lang);
}
else
{
format(FileDest, sizeof(FileDest), "DTLangFiles/%s_%s.txt",DT_lf_prefix, Lang);
}
if(fexist(FileDest))
{
new File: LangFile = fopen(FileDest, io_read);
if(LangFile)
{
new checker = 0;
new str[256];
while(checker != 2)
{
if( !fread(LangFile, str, sizeof(str)) ){checker=2;break;}
if(checker== 0 && str[0]!='%')
{
key = dtlf_ini_GetKey(str);
if(strfind(str, "\n") != -1) { strdel(str, strlen(str)-1, strlen(str)); }
if(strcmp(key, Name, true) == 0)
{
format(Data, sizeof(Data), "%s", dtlf_ini_GetValue(str));checker=1;
}
} else if(checker==1) {
if(str[0] == '%' && str[1] == 'h' && str[2] == '%')
{
if(strfind(str, "\n") != -1) { strdel(str, strlen(str)-1, strlen(str)); }
if(strfind(str, "%h%") != -1) { strdel(str, strfind(str, "%h%"), strlen("%h%")); }
format(Data, sizeof(Data), "%s%s", Data,str);
} else {
checker=2;break;
}
}
}//END WHILE
}
fclose(LangFile);
} else {format(Str,length,"ERROR: Can't find Lang Files \"%s\"",FileDest); printf("ERROR: Can't find Lang Files \"%s\"",FileDest);return 0;}
while(strfind(Data, "%n%") != -1)
{
new pos = strfind(Data, "%n%");
new len2 = strlen("%n%");
strdel(Data, pos, (pos+len2));
strins(Data, "\n", pos);
}
while(strfind(Data, "%x") != -1)
{
new pos = strfind(Data, "%x",false);
new len2 = strfind(Data, "%",false,pos+1);
new Var[60];
printf("Data \"%s\"",Data);
strmid(Var,Data,pos+2,len2);
printf("Var \"%s\"",Var);
strdel(Data, pos, len2);
print("Debug #1");
new Var2[200];
print("Debug #2");
GetLangVarInt(Lang,Var,"",Var2,sizeof(Var2));
printf("Var2 \"%s\"",Var2);
strins(Data, Var2, pos);
printf("Data \"%s\"",Data);
}
//Replace %sName% with string
new NumArgs = numargs()-5;
if(NumArgs == 0)
{
format(Str,length,"%s",Data);
return 1;
}
new count;
new tmp[25][30];
new idx;
new stop = 0;
while(stop == 0 && count < NumArgs)
{
tmp[count] = dtlf_strtok(Format, idx);
if(strlen(tmp[count]) == 0 && count == 0)
{
stop = 1;
format(Str,length,"%s",Data);
return 1;
}
if(strlen(tmp[count]) == 0) {stop = 1; break;}
count++;
}
if(count == 0)
{
format(Str,length,"%s",Data);
return 1;
}
for (new i = 0;i<=count;i++)
{
if(i>=NumArgs){break;}
new pos = strfind(Data, tmp[i], true);
new len2 = strlen(tmp[i]);
if(pos != -1)
{
strdel(Data, pos, (pos+len2));
new val[90];
if(tmp[i][1] == 's')
{
new index = 0;
while(index < sizeof(val))
{
new chari = getarg(i+5, index++);
if (chari == 0) break; // 0 is end of string
format(val,sizeof(val),"%s%c",val,chari);
}
}
if(tmp[i][1] == 'd')
{
new chari = getarg(i+5,0);
format(val,sizeof(val),"%d",chari);
}
if(tmp[i][1] == 'f')
{
new Float:chari = Float:getarg(i+5);
format(val,sizeof(val),"%f",chari);
}
strins(Data, val, pos);
}
}
format(Str,length,"%s",Data);
return 1;
}
stock GetLangVarInt(Lang[3],Name[60],const Format[],Str[],length,{Float,_}:...)
{
printf("Lang %s Name %s Leng: %d",Lang,Name,length);
new FileDest2[80], key2[256], Data2[850];
print("Debug #00");
if(strfind(Name, ":", true) != -1) //Find an FileVar
{
print("Debug #01");
new pos2 = strfind(Name, ":", true);
print("Debug #02");
new FileVar2[15];
print("Debug #03");
strmid(FileVar2,Name,0,pos2);
print("Debug #04");
strdel(Name,0,pos2+1);
print("Debug #05");
format(FileDest2, sizeof(FileDest2), "DTLangFiles/%s_%s_%s.txt",DT_lf_prefix, FileVar2, Lang);
}
else
{
print("Debug #06");
format(FileDest2, sizeof(FileDest2), "DTLangFiles/%s_%s.txt",DT_lf_prefix, Lang);
}
print("Debug #07");
printf("File %s",FileDest2);
if(fexist(FileDest2))
{
new File: LangFile2 = fopen(FileDest2, io_read);
if(LangFile2)
{
new checker2 = 0;
new str2[256];
while(checker2 != 2)
{
if( !fread(LangFile2, str2, sizeof(str2)) ){checker2=2;break;}
if(checker2== 0 && str2[0]!='%')
{
key2 = dtlf_ini_GetKey(str2);
if(strfind(str2, "\n") != -1) { strdel(str2, strlen(str2)-1, strlen(str2)); }
if(strcmp(key2, Name, true) == 0)
{
format(Data2, sizeof(Data2), "%s", dtlf_ini_GetValue(str2));checker2=1;
}
} else if(checker2==1) {
if(str2[0] == '%' && str2[1] == 'h' && str2[2] == '%')
{
if(strfind(str2, "\n") != -1) { strdel(str2, strlen(str2)-1, strlen(str2)); }
if(strfind(str2, "%h%") != -1) { strdel(str2, strfind(str2, "%h%"), strlen("%h%")); }
format(Data2, sizeof(Data2), "%s%s", Data2,str2);
} else {
checker2=2;break;
}
}
}//END WHILE
}
fclose(LangFile2);
} else {format(Str,length,"ERROR: Can't find Lang Files \"%s\"",FileDest2); printf("ERROR: Can't find Lang Files \"%s\"",FileDest2);return 0;}
while(strfind(Data2, "%n%") != -1)
{
new pos2 = strfind(Data2, "%n%");
new len22 = strlen("%n%");
strdel(Data2, pos2, (pos2+len22));
strins(Data2, "\n", pos2);
}
//Replace %sName% with string
new NumArgs2 = numargs()-5;
if(NumArgs2 == 0)
{
format(Str,length,"%s",Data2);
return 1;
}
new count2;
new tmp2[25][30];
new idx2;
new stop2 = 0;
while(stop2 == 0 && count2 < NumArgs2)
{
tmp2[count2] = dtlf_strtok(Format, idx2);
if(strlen(tmp2[count2]) == 0 && count2 == 0)
{
stop2 = 1;
format(Str,length,"%s",Data2);
return 1;
}
if(strlen(tmp2[count2]) == 0) {stop2 = 1; break;}
count2++;
}
if(count2 == 0)
{
format(Str,length,"%s",Data2);
return 1;
}
for (new i2 = 0;i2<=count2;i2++)
{
if(i2>=NumArgs2){break;}
new pos2 = strfind(Data2, tmp2[i2], true);
new len22 = strlen(tmp2[i2]);
if(pos2 != -1)
{
strdel(Data2, pos2, (pos2+len22));
new val2[90];
if(tmp2[i2][1] == 's')
{
new index2 = 0;
while(index2 < sizeof(val2))
{
new chari2 = getarg(i2+5, index2++);
if (chari2 == 0) break; // 0 is end of string
format(val2,sizeof(val2),"%s%c",val2,chari2);
}
}
if(tmp2[i2][1] == 'd')
{
new chari2 = getarg(i2+5,0);
format(val2,sizeof(val2),"%d",chari2);
}
if(tmp2[i2][1] == 'f')
{
new Float:chari2 = Float:getarg(i2+5);
format(val2,sizeof(val2),"%f",chari2);
}
strins(Data2, val2, pos2);
}
}
format(Str,length,"%s",Data2);
return 1;
}
Hier die Txt (DTDH_Dia_DE.txt):
ButtonWeit=Weiter
ButtonAbr=Abbrechen
ButtonZur=Zurück
MainDia=%xDia:CapCfg%%n%%xDia:CapHouse%%n%%xDia:CapInterriors%
CapHouse=Häuser
CapCfg=Configuration
CapInterriors=Interriors
AHouseDia=Editieren%n%Haus löschen%n%Alle Häuser löschen%n%Haus hinzufügen
Beim ausführendes codes:
GetLangVar(LangVar,"Dia:MainDia","",string,sizeof(string))
bekomme ich dies in den serverlog:
[21:14:30] Data "%xDia:CapCfg%
%xDia:CapHouse%
%xDia:CapInterriors%"
[21:14:30] Var "Dia:CapCfg"
[21:14:30] Debug #1
[21:14:30] Debug #2
[21:14:30] Lang DE Name Dia:CapCfg Leng: 200
D.h: der code schafft es nicht im stock neue Variablen zu erstellen??
Ich verzweifle garde, habe den stock ja schon kopiert und alle variablennamen geändert...