SA-MP Forums Archive
[Include] Some Small Functions - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Some Small Functions (/showthread.php?tid=355076)



REMOVE PLEASE - milanosie - 28.06.2012

REMOVED

TOTAL BULLCRAP I POSTED.


Re: Some Small Functions - milanosie - 28.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Do you know WHY people claim that dini isn't a very good file system? Because it's slow! Why is it slow? Because it opens, writes, and closes, the file for EVERY operation instead of buffering data for more efficient writes. You figure out why I'm telling you this.

Also, we have a shiny new "Includes" forum - I moved this one there but you might want to pay more attention in the future.
Why are you talking about dini? Nothing to do with this?


And yes, I just noticed. thank you


EDIT:

Код:
   new File:cmdlog = fopen("logs/commands.txt", io_append);
   fwrite(cmdlog, text);
   fwrite(cmdlog, "\r\n");
   fclose(cmdlog);
Yeah, but what else? its a damn log file.

EDIT2:

Working on a solution, would like your opinion once its done


EDIT 3:


What would you think of this? Would this take loads of memory?
I have no experience on this part of coding/scripting, so this might be absolute shit what I'm posting now.



pawn Код:
new logline[MAX_PLAYERS][10][128];
new logamount[MAX_PLAYERS];



public OnPlayerConnect(playerid)
{
    logamount[playerid] = 0;
    canpm[playerid] = 1;
    return 1;
}


forward writecmdlog(text[]);
stock writecmdlog(text[])
{
    if(logamount[playerid] < 10)
    {
        logamount[playerid] ++;
        format(logline[playerid][logamount[playerid]], sizeof(logline[playerid][logamount[playerid]]), text);
    }
    else
    {
        new File:cmdlog = fopen("logs/commands.txt", io_append);
        for(new i=1; i<11; i++)
        {
            fwrite(cmdlog, logline[playerid][i]);
            fwrite(cmdlog, "\r\n");
        }
        fclose(cmdlog);
    }
    return 1;
}
:3

Might be shit though


Re: Some Small Functions - AndreT - 29.06.2012

Hey. For starters, did you actually try compiling with the include?

I might be mistaken, but I think iUSPos is undefined in the function below. Also, stock functions do not need to be forwarded!
pawn Код:
forward GetFirstName(playerid);
stock GetFirstName(playerid)
{
    new name[MAX_PLAYER_NAME],pos;
    GetPlayerName(iPlayer, name, MAX_PLAYER_NAME);
    pos = strfind(name, "_");
    strdel(name, pos, 24), strins(name, " ", iUSPos, 24);
    return name;
}
Furthermore, I don't understand what the strins is supposed to do. Make "Andre_" into "Andre_ " (or something alike)?
Additionally, as a small thing to remember, you do not need to use strdel if you're deleting the end of a string. You can terminate the string otherwise:
pawn Код:
name[pos] = EOS;
// or
name[pos] = '\0';
There's not much difference, but it does not require you to call the function.


Re: Some Small Functions - ipsBruno - 29.06.2012

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Hey. For starters, did you actually try compiling with the include?

I might be mistaken, but I think iUSPos is undefined in the function below. Also, stock functions do not need to be forwarded!
pawn Код:
forward GetFirstName(playerid);
stock GetFirstName(playerid)
{
    new name[MAX_PLAYER_NAME],pos;
    GetPlayerName(iPlayer, name, MAX_PLAYER_NAME);
    pos = strfind(name, "_");
    strdel(name, pos, 24), strins(name, " ", iUSPos, 24);
    return name;
}
Furthermore, I don't understand what the strins is supposed to do. Make "Andre_" into "Andre_ " (or something alike)?
Additionally, as a small thing to remember, you do not need to use strdel if you're deleting the end of a string. You can terminate the string otherwise:
pawn Код:
name[pos] = EOS;
// or
name[pos] = '\0';
There's not much difference, but it does not require you to call the function.
And, enter in server with nick "_YOURNICK" ..

Fix it:
pawn Код:
static
    pos
;
   
pos = strfind(name, "_");
   
if(pos > 2) {
    name[pos] = '\0';
    return name;
}



Re: Some Small Functions - BlackBank - 30.06.2012

Quote:
Originally Posted by ******
Посмотреть сообщение
Do you know WHY people claim that dini isn't a very good file system? Because it's slow! Why is it slow? Because it opens, writes, and closes, the file for EVERY operation instead of buffering data for more efficient writes. You figure out why I'm telling you this.

Also, we have a shiny new "Includes" forum - I moved this one there but you might want to pay more attention in the future.
So you mean that this method is better:
pawn Код:
new File:cmdlog;

public OnGameModeInit()
{
    cmdlog = fopen("logs/commands.txt", io_append);
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    fwrite(cmdlog, cmdtext);
    fwrite(cmdlog, "\r\n");
    return 0;
}

public OnGameModeExit()
{
    fclose(cmdlog);
    return 1;
}
And this method not:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new File:cmdlog = fopen("logs/commands.txt", io_append);
    fwrite(cmdlog, cmdtext);
    fwrite(cmdlog, "\r\n");
    fclose(cmdlog);
    return 0;
}
?