22.08.2013, 02:23
Hello, I created a dynamic function in which it works something like this:
FIRST:
If the settings file doesn't exist, it will create it in the scriptfiles folder. Here is what it will write in it:
Then, when someone writes a command like "/createslot TESTSLOT1", it will write in that file into something like this:
Then when someone writes that command some more like "/createslot TESTSLOT2", it will write in that file into something like this:
and so on... The reason why I made it like this:
is for me to create some sort of loop which will check if that SlotName[Number] is empty (I made a function like /deleteslot [NUMBER] and it will delete the SlotName[Number] in the file for example /deleteslot 2 will become:
and I can create some sort of loop which is functioning like this:
CheckTheLine:
Long story short, I don't know how to read each line and find if the line is empty so I created this whole thing, if you understand this topic, tell me if there is a way to do this instead of using this whole thing system that I made. Trust me, you do not want me to tell the complexity of the problem.
FIRST:
If the settings file doesn't exist, it will create it in the scriptfiles folder. Here is what it will write in it:
Code:
[Slots] Created Slots = 0
Code:
[Slots] Created Slots = 1 [1] SlotName1 = TESTSLOT1
Code:
[Slots] Created Slots = 2 [1] SlotName1 = TESTSLOT1 [2] SlotName2 = TESTSLOT2
Code:
[Slots] Created Slots = [CREATE SLOTS] [NUMBER] SlotName[NUMBER] = TESTSLOT1 [NUMBER] SlotName[NUMBER] = TESTSLOT2
Code:
[Slots] Created Slots = 2 [1] SlotName1 = TESTSLOT1 [2] SlotName2 =
pawn Code:
//global:
new slotname[128];
new FoundTheLine[128];
stock LoopThroughAllSlotLines()
{
for(new i = 1; i < TOTAL_CREATED_SLOTS && EndTheLoop == 0; i++)
{
format(slotname,sizeof(slotname),"SlotName%d",i);
INI_ParseFile(ConfigFile, "CheckTheLine", .bExtra = true, .extra = i);
}
//found it:
printf("% is empty!",FoundTheLine);
return 1;
}
pawn Code:
forward CheckTheLine(i, name[], value[]);
public CheckTheLine(i, name[], value[])
{
INI_String(slotname,TheGroupName,256);
if (strlen(TheGroupName) == 0)
{
FoundEmptyLine = TheGroupName;
EndTheLoop = 1;
}
return 1;
}