How to change the name of a file in dini?
#1

Hey there. I want to make a changename command, but for that i need to know how to make dini or whatever change the file name...

Like, my file is Ricardo_Rodrigues.ini, i want it Ricardo_Manuel.ini. How i do edit that IG without the need of changing it manuale by changing the file name?

Thanks.
Reply
#2

use frename
Reply
#3

There is no such function in sa-mp... At least wiki don't have any information on such function.
Reply
#4

i think dutils.inc has frename
Reply
#5

You have to make the new file and delete the original file.

fremove is buggy in SA-MP and from my experiments it only works a small fraction of the time, use a file manager for a set of more reliable functions for file removing.
Reply
#6

This is how i create changename command

pawn Код:
CMD:changename(playerid, params[])
{
    new string[128],
        newname[MAX_PLAYER_NAME],
        oldname[MAX_PLAYER_NAME],
        location[254],
        id;
    if(pData[playerid][Login] == 0) return SendClientMessage(playerid, COLOR_RED, "*** Please login first! ***");
    if(pData[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "*** You are not Junior Administrator ***");
    if(sscanf(params, "us[24]", id, newname)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /changename [playerid] [newname]");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change the name of higher administrator! ***");
    format(location, 254, pPath, newname);
    format(oldname,  MAX_PLAYER_NAME, "%s", dini_Get(DataPath(id), "Name"));
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "*** Player not connected ***");
    if(pData[playerid][Admin] < pData[id][Admin]) return SendClientMessage(playerid, COLOR_RED, "*** You cannot change name higher administrator! ***");
    if(fexist(location))
    {
        SendClientMessage(playerid, COLOR_RED, "*** That player name exists or you're changing the newname to a oldname ***");
    }
    else
    {
        format(string, sizeof(string), "Administrator %s(%d) has change %s name to %s(%d)", GetpName(playerid), playerid, GetpName(id), newname, id);
        SendClientMessageToAll(COLOR_GREEN, string);
        format(string, sizeof(string), "*** You change %s name to %s(%d)", GetpName(id), newname, id);
        SendClientMessage(playerid, COLOR_GREEN, string);
        format(string, sizeof(string), "*** Administrator %s(%d) has change your name to %s", GetpName(playerid), playerid, newname);
        SendClientMessage(id, COLOR_GREEN, string);
        pData[id][AccID] = dini_Int(DataPath(id), "AccID");
        pData[id][Pass] = dini_Int(DataPath(id), "Password");
        pData[id][Jail] = dini_Int(DataPath(id), "Jail");
        new jailreason[92];
        format(jailreason, 92, "%s", dini_Get(DataPath(id), "JailReason"));
        new jailby[24];
        format(jailby, 24, "%s", dini_Get(DataPath(id), "JailBy"));
        pData[id][Mute] = dini_Int(DataPath(id), "Mute");
        new mutereason[92];
        format(mutereason, 92, "%s", dini_Get(DataPath(id), "MuteReason"));
        new muteby[24];
        format(muteby, 24, "%s", dini_Get(DataPath(id), "MuteBy"));
        pData[id][NoPM] = dini_Int(DataPath(id), "NoPM");
        pData[id][Banned] = dini_Int(DataPath(id), "Banned");
        new banreason[92];
        format(banreason, 92, "%s", dini_Get(DataPath(id), "Reason"));
        new banby[24];
        format(banby, 24, "%s", dini_Get(DataPath(id), "BanBy"));
        pData[id][Admin] = dini_Int(DataPath(id), "Admin");
        pData[id][VIP] = dini_Int(DataPath(id), "VIP");
        pData[id][Score] = dini_Int(DataPath(id), "Score");
        pData[id][Cookies] = dini_Int(DataPath(id), "Cookies");
        pData[id][Cash] = dini_Int(DataPath(id), "Cash");
        pData[id][Deaths] = dini_Int(DataPath(id), "Deaths");
        pData[id][Kills] = dini_Int(DataPath(id), "Kills");
        dini_Remove(DataPath(id));
        dini_Create(location);
        dini_Set(location, "Name", newname);
        dini_IntSet(location, "AccID", pData[id][AccID]);
        dini_Set(location, "IP", IP);
        dini_IntSet(location, "Password", pData[id][Pass]);
        dini_IntSet(location, "Jail", pData[id][Jail]);
        dini_Set(location, "JailReason", jailreason);
        dini_Set(location, "JailBy", jailby);
        dini_IntSet(location, "Mute", pData[id][Mute]);
        dini_Set(location, "MuteReason", mutereason);
        dini_Set(location, "MuteBy", muteby);
        dini_IntSet(location, "NoPM", pData[id][NoPM]);
        dini_IntSet(location, "Banned", pData[id][Banned]);
        dini_Set(location, "Reason", banreason);
        dini_Set(location, "BanBy", banby);
        dini_IntSet(location, "Admin", pData[id][Admin]);
        dini_IntSet(location, "VIP", pData[id][VIP]);
        dini_IntSet(location, "Score", pData[id][Score]);
        dini_IntSet(location, "Cookies", pData[id][Cookies]);
        dini_IntSet(location, "Cash", pData[id][Cash]);
        dini_IntSet(location, "Deaths", pData[id][Deaths]);
        dini_IntSet(location, "Kills", pData[id][Kills]);
        SetPlayerName(id, newname);
        format(string, sizeof(string), "ADMMSG: Administrator %s(%d) has use /changename to %s(%d) | New Name: %s", GetpName(playerid), playerid, GetpName(id), id, newname);
        ReadADMCMD(playerid, COLOR_BLUE, string);
    }
    return 1;
}
i know its bad way but it totally work fine
Reply
#7

Thanks. Will create this way too.. xD
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)