Y_ini, load error -
StilThere - 01.06.2011
Why is it that this code doesn't work
Код:
#define MAX_TP 20
new place[8];
INI:Teleports[](playerid, name[], value[]){ // input, output, sizeof, output
INI_String(place, GetString, sizeof(GetString));
return 0;
}
stock ShowTeleports(playerid){
new i;
for(i = 0; i < MAX_TP; i++){
format(place, sizeof(place), "Place%d", i);
INI_Load("Teleports.ini", true, playerid);
printf(GetString);
}
#pragma unused playerid
return 1;
}
file
Код:
Place0 = Tierra Robada
Place1 = San Fierro
Place2 = Los Santos
Place3 = Las Venturas
Place4 = Whetstone
When I do the code above it will print me "Tierra Robada" 20 times while I format the place[] correct. Cause when I do it like this
Код:
#pragma unused TP_Places
new place[8];
INI:Teleports[](playerid, name[], value[]){ // input, output, sizeof, output
INI_String(place, GetString, sizeof(GetString));
return 0;
}
stock ShowTeleports(playerid){
strpack(place, "Place0");
INI_Load("Teleports.ini", true, playerid);
printf(GetString);
strpack(place, "Place1");
INI_Load("Teleports.ini", true, playerid);
printf(GetString);
return 1;
}
it prints "Tierra Robada" and "San Fierro" Although the place[] has the same value here it gives the right result. That's just not fair x3 ! Does this mean I have to configure all the 20 places like that?
Re: Y_ini, load error -
StilThere - 02.06.2011
Yes but how to put all the value[]'s into the array TP_Places[MAX_TP][32] ? This won't work
Код:
new i;
INI:Teleports[](playerid, name[], value[]){ // input, output, sizeof, output
strpack(TP_Places[i], value);
i++;
return 0;
}
It won't get the last value out of the file.. :S
[EDIT] Lol just kidding, it does now. Thanks ******
[EDIT] But how to get floats out of a file this way ******?
Re: Y_ini, load error -
StilThere - 02.06.2011
It seems that the server has to be reloaded to read a file, after it being altered, yes?
Cause this code doesn't work. When I create a new teleport and then click Teleports in the dialog it does not show the created teleport
Код:
Public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
#pragma unused inputtext
switch(dialogid){
case (TP_DIALOG):{
if(response){
switch(listitem){
case 0: return ShowTeleports(playerid);
case 1: return CreateTeleport(playerid);
}
}
}
case (TP_DIALOG + 1):{
if(response){
SetPlayerPos(playerid, TP_Locations[listitem][0], TP_Locations[listitem][1], TP_Locations[listitem][2]);
}
}
case (TP_DIALOG + 2):{
if(response){
ResetINIVars();
INI_Load("Teleports.ini", true, playerid);
format(TelDialogString, sizeof(TelDialogString), "");
new INI:Teleports = INI_Open("Teleports.ini");
INI_SetTag(Teleports, "Names");
new i;
for(i = 0; i < MAX_TP; i++){
if(strlen(TP_Places[i]) == 0){
if(i == MAX_TP){
SendClientMessage(playerid, COLOR_WHITE, "(( [SERVER]: Maximum of teleports has been achieved.))");
INI_Close(Teleports);
return 0;
}
format(TelDialogString, sizeof(TelDialogString), "Place%d", i);
INI_WriteString(Teleports, TelDialogString, inputtext);
INI_Close(Teleports);
return 0;
}
}
INI_Close(Teleports);
}
}
}
return 0;
}
new i_names,
i_c_1,
i_c_2;
INI:Teleports[Names](playerid, name[], value[]){ // input, output, sizeof, output
format(TP_Places[i_names], MAX_TP_NAME, "%s", value);
printf(value);
i_names++;
return 0;
}
INI:Teleports[Coordinates](playerid, name[], value[]){ // input, output, sizeof, output
TP_Locations[i_c_1][i_c_2] = floatstr(value);
if(i_c_2 == 2){
i_c_1++;
i_c_2 = 0;
}
i_c_2++;
return 0;
}
stock ShowTeleports(playerid){
ResetINIVars();
INI_Load("Teleports.ini", true, playerid);
format(TelDialogString, sizeof(TelDialogString), "");
new i;
for(i = 0; i < MAX_TP; i++){
if(strlen(TP_Places[i]) != 0){
format(TelDialogString, sizeof(TelDialogString), "%s%s\n", TelDialogString, TP_Places[i]);
printf(TP_Places[i]);
}
}
ShowPlayerDialog(playerid, TP_DIALOG + 1, DIALOG_STYLE_LIST, "Teleports", TelDialogString, "OK", "Cancel");
return 0;
}
stock CreateTeleport(playerid){
ShowPlayerDialog(playerid, TP_DIALOG + 2, DIALOG_STYLE_INPUT, "Teleport name", "(( Give a brief description of your location. ))", "OK", "Cancel");
return 0;
}
stock ResetINIVars(){
i_names = 0;
i_c_1 = 0;
i_c_2 = 0;
return 1;
}
Re: Y_ini, load error -
StilThere - 06.06.2011
Bump
Re: Y_ini, load error -
StilThere - 06.06.2011
This is the whole code (I changed to ParseFile but the problem stays the same)
Код:
#include <a_samp>
#include <YSI/y_ini>
#define FILTERSCRIPT
#define TP_DIALOG 50
#define MAX_TP_NAME 32
#define MAX_TP 20
new TP_NAME[MAX_TP][MAX_TP_NAME];
public OnPlayerCommandText(playerid, cmdtext[]){
new cmd[32],
idx;
cmd = strtok(cmdtext, idx);
if(strcmp("/teleport", cmd, true) == 0){
return ShowPlayerDialog(playerid, TP_DIALOG, DIALOG_STYLE_LIST, "Teleport menu", "Show teleports\nCreate teleport\nDelete teleport", "OK", "Cancel");
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
if(response){
switch(dialogid){
case (TP_DIALOG):{
switch(listitem){
case 0: ShowTeleports(playerid);
case 1: CreateTeleport(playerid);
}
}
case (TP_DIALOG + 1):{
new INI:teleport = INI_Open("Teleports.ini");
INI_SetTag(teleport, "Names");
INI_WriteString(teleport, "Place0", inputtext);
INI_Close(teleport);
}
}
}
return 0;
}
stock ShowTeleports(playerid){
#pragma unused playerid
INI_ParseFile("Teleports.ini", "load_teleports_%s", .bExtra = false);
printf(TP_NAME[0]);
return 0;
}
stock CreateTeleport(playerid){
return ShowPlayerDialog(playerid, TP_DIALOG + 1, DIALOG_STYLE_INPUT, "Create Teleport", "Give in a short description of your location", "OK", "Cancel");
}
forward load_teleports_Names(name[], value[]);
public load_teleports_Names(name[], value[])
{
INI_String("Place0", TP_NAME[0], MAX_TP_NAME);
return 0;
}
[EDIT] I made a registersystem in which an INI_ParseFile is called when a player logs on. This functions seems to be able to be called everytime a player logs on. I can also create another INI_ParseFile at let ONLY that be performed on every login. However If I want to perform both of them only the first one is really performed on every log on :S
I'm assuming as following:
- INI_ParseFile s may only be called in certain callbacks, and this callback may only contain ONE INI_ParseFile;
- An INI_ParseFile called outside a certain callback can only be called ONCE during the server's uptime.
Is this true? And why (can't I reload the file in the teleport FS)?
PS. Might you want to look at the registersystem, here it is (it's an include in my GameMode, which contains no further INI_ParseFile s):
- GameMode:
http://pastebin.com/vbxy767v
- RegisterSystem include:
http://pastebin.com/z3UDWRhX
Re: Y_ini, load error -
StilThere - 08.06.2011
Refresh
Re: Y_ini, load error -
StilThere - 29.06.2011
Anybody?