DCMD need help
#1

So i've tried to make a DCMD command that can change an user dini's enum to a certain value.
Example "Setfaction 12 1300" [id] [Factionid]
and in users Faction to be set at 1300
I have made some code,it works,it compiles with no error,but when i type the command the Faction value does not change...Please can you guys give me an advice on how i should code it in order to work?


My code
Код:
dcmd_setfaction(playerid, params[])
{
	new
	giveplayerid,
	amount;
	if (sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /setfaction [playerid] [factionid]");
	else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
	else
	{
    new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!dini_Exists(file))
    {
    SendClientMessage(playerid, 0xFF0000AA, "Player is not registred");
    }
    if(fexist(file))
    {
	PlayerInfo[playerid][pFaction] = amount;
	dini_IntSet(SERVER_USER_FILE, "Faction",PlayerInfo[playerid][pFaction]);
    }
	}
   return 1;
}
Reply
#2

pawn Код:
dcmd_setfaction(playerid, params[])
{
    new giveplayerid, amount;
    if(sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /setfaction [playerid] [factionid]");
    else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!dini_Exists(file))
        {
            SendClientMessage(playerid, 0xFF0000AA, "Player is not registred");
        }
        if(fexist(file))
        {
            PlayerInfo[playerid][pFaction] = amount;
            dini_IntSet(SERVER_USER_FILE, "Faction",amount);
        }
    }
    return 1;
}
First off, just wanted to indent your code. Made it look a bit neater.

Second, could it be because in "dini_IntSet" your setting the "faction" part of the file your pFaction? I'm not sure if that would work, because it may take a certain amount of time for it to process (such as when you use GetPlayerPos after SetPlayerPos, or whatever) so I just set it to the new variable "amount".
Reply
#3

hmm i think it will work,ima try it now,thanks for helping me i did 3 posts and nobody bored with me
Reply
#4

Nope it still dosent works my faction remains 0>...
Reply
#5

I honestly have no idea how I didn't see it before.

pawn Код:
dcmd_setfaction(playerid, params[])
{
    new giveplayerid, amount;
    if(sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /setfaction [playerid] [factionid]");
    else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(giveplayerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!dini_Exists(file))
        {
            SendClientMessage(playerid, 0xFF0000AA, "Player is not registred");
        }
        if(fexist(file))
        {
            PlayerInfo[giveplayerid][pFaction] = amount;
            dini_IntSet(SERVER_USER_FILE, "Faction",amount);
        }
    }
    return 1;
}
You are getting the name of playerid, not giveplayerid, and your setting playerid's faction to the factionid. I just changed it to giveplayerid so it would set the actual players faction.
Reply
#6

i will try it now i think i understand
Reply
#7

goddamit its still not working,the faction value remains 0...(
Reply
#8

Jesus. Sorry for all the posts. Keep thinking I fixed it but didn't

pawn Код:
dcmd_setfaction(playerid, params[])
{
    new giveplayerid, amount;
    if(sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /setfaction [playerid] [factionid]");
    else if(giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(giveplayerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!dini_Exists(file))
        {
            SendClientMessage(playerid, 0xFF0000AA, "Player is not registred");
        }
        if(fexist(file))
        {
            PlayerInfo[giveplayerid][pFaction] = amount;
            dini_IntSet(file, "Faction",amount);
        }
    }
    return 1;
}
Now this, should absolutely work. This is the thing I changed:

pawn Код:
dini_IntSet(SERVER_USER_FILE, "Faction",amount);
to
pawn Код:
dini_IntSet(file, "Faction",amount);
It wasn't checking who's file it was, so it was setting the variable "faction" to the faction id of the file %s.ini (if you had one). ((<-- not sure if thats what it was actually doing)).

Hope I helped.
Reply
#9

Yes,at last,thanks a lot for helping me it works 100%.
And also i've learned now how to modiffy a value,thanks a lot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)