Re-write a line in dini(+REP)
#1

Hi guys,
Hum, the following cmd is supposed to open up a file, find a string and delete it's text(if the text even exists).
e.g, faction Ballas has been warned, it writes down a warning to their lowest warning available slot
let's say it's 1. So in the factionwarnings file, on Ballas1, it'll change the text from Ballas1="Powergaming" to Ballas="" but for some reason I can't get it working. If it works, then it sometimes remove a warning from a clear slot(without any warnings, the value is ""), or says that the slot is clear when it's not.

PHP код:
COMMAND:rfwarn(playeridparams[])
{
new 
ff[50];
    if(
PlayerInfo[playerid][power] < 11) return SendClientError(playeridCANT_USE_CMD);
    new 
iFactionwidiReasonMAX_STRING ];
    if( 
sscanf params"dds"iFactionwidiReason))  return SCP(playerid"[FactionID] [WarningID] [Reason]");
format(ffsizeof(ff), "%sWarnings"teamsGetTeam(iFaction) ][teamname]);
if(
dini_Int(factionwarningsff) == 0) return SendClientError(playerid"This faction has 0 warnings!");
        
format(iStrsizeof(iStr), "%s%d",  teamsGetTeam(iFaction) ][teamname], wid);
            if(!
strcmp(dini_Get(factionwarningsiStr), "")) return SendClientError(playerid"This slot is empty!");
                
dini_Set(factionwarningsiStr"");
                
                
dini_IntSet(factionwarningsff, (dini_Int(factionwarningsff) -1));
                                
format(iStrsizeof(iStr), "#[Faction Warning] %s has removed a faction-warned from %s. Reason: %s [%d/5]"RPName(playerid),  teamsGetTeam(iFaction) ][teamname], iReasondini_Int(factionwarningsff));
                
SendClientMessageToAdmins(iStrCOLOR_PLAYER_VLIGHTBLUE);
                                 
PlayerLoop(ii)
                     {
                         if(
GetPlayerFaction(ii) == iFaction)
                        
SendClientMessage(iiCOLOR_PLAYER_VLIGHTBLUEiStr);
                    }
             return 
SendClientInfo(playerid"Done");
            
// return 1;

+ REPing

Basically, if you didnt understand so far - I want this command to check whether a line equals to "", if so it should return an error, if not it should set it to "".
Reply
#2

Stop using dini.

Here is the mistake
Код:
if(!strcmp(dini_Get(factionwarnings, iStr), ""))
Everyone thinks that strcmp returns 1 if the string did not match and returns 0 if it matched. Actually that isn't the case, a quick loopup at the wiki will reveal that strcmp returns the position of the first mismatch.

strcmp will return 0 for null strings.

Use isnull instead of strcmp and that will fix the problem.

Also note that Windows is know for playing dirty tricks on new programmers. It might have secretly smuggled carriage returns/new lines into your empty lines.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)