SA-MP Forums Archive
Help in command - 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: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help in command (/showthread.php?tid=528303)



Help in command - krytans - 27.07.2014

When i use /poll command it shows random name. For example my name is Edward in game and community Director, if i use /poll questions. it shows Community director Someone's name instead of edward.

Код:
CMD:poll(playerid, params[])
{
	new result[96], alevel[25], string2[128];
	if(PlayerInfo[playerid][pAdmin] <= 2)
	    return SendClientMessage(playerid, COLOR_GRAD2, "   You are not authorized to use that command !");

	if(sscanf(params, "s[96]", result))
	    return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /poll [question]");

	for(new i; i<MAX_PLAYERS; i++)
	{
 		if(IsPlayerConnected(i))
	    {
	    	Vote[i] = 1;
	    	SetTimerEx("PollEnd3", 61000, false, "i", i);
	    	SetTimerEx("PollEnd", 60000, false, "i", i);
	    	SetTimerEx("PollEnd2", 30000, false, "i", i);
	    }
	}

	if(PlayerInfo[playerid][pAdmin] == 2) { alevel = "Junior Administrator"; }
	if(PlayerInfo[playerid][pAdmin] == 3) { alevel = "General Administrator"; }
	if(PlayerInfo[playerid][pAdmin] >= 4 && PlayerInfo[playerid][pAdmin] <= 1336) { alevel = "Senior Administrator"; }
	if(PlayerInfo[playerid][pAdmin] >= 1337 && PlayerInfo[playerid][pAdmin] <= 99998) { alevel = "Head Administrator"; }
	if(PlayerInfo[playerid][pAdmin] == 99999) { alevel = "Executive Administrator"; }
	if(PlayerInfo[playerid][pAdmin] >= 100000) { alevel = "Server Manager"; }
	if(PlayerInfo[playerid][pAdmin] >= 100001) { alevel = "Community Director"; }
	if(PlayerInfo[playerid][pAdmin] >= 100002) { alevel = "Community Founder"; }

    format(string2, sizeof(string2), "*Suggestion Poll: %s %s has started a poll.", alevel, sendername);
	SendClientMessageToAll(COLOR_ORANGE, string2);
    format(string2, sizeof(string2), "Question is:{FFFFFF} %s", result);
	SendClientMessageToAll(COLOR_LIGHTGREEN, string2);
	SendClientMessageToAll(COLOR_LIGHTBLUE, "Type /vote [Yes/No] or Press 'Y' button for Yes - Press 'N' button for No.");
	return 1;
}



Re: Help in command - Threshold - 27.07.2014

That's because you use a global variable called 'sendername' for something that doesn't need to be a global variable at all...

This is the fixed command:
pawn Код:
CMD:poll(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, COLOR_GRAD2, "   You are not authorized to use that command !");
    new result[105];
    if(sscanf(params, "s[105]", result)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /poll [question]");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
        Vote[i] = 1;
        SetTimerEx("PollEnd3", 61000, false, "i", i);
        SetTimerEx("PollEnd", 60000, false, "i", i);
        SetTimerEx("PollEnd2", 30000, false, "i", i);
    }
    new alevel[24], adminname[MAX_PLAYER_NAME], fstr[128];
    switch(PlayerInfo[playerid][pAdmin])
    {
        case 2: alevel = "Junior Administrator";
        case 3: alevel = "General Administrator";
        case 4 .. 1336: alevel = "Senior Administrator";
        case 1337 .. 99998: alevel = "Head Administrator";
        case 99999: alevel = "Executive Administrator";
        case 100000: alevel = "Server Manager";
        case 100001: alevel = "Community Director";
        case 100002: alevel = "Community Founder";
    }
    GetPlayerName(playerid, adminname, sizeof(adminname));
    format(fstr, sizeof(fstr), "*Suggestion Poll: %s %s has started a poll.", alevel, adminname);
    SendClientMessageToAll(COLOR_ORANGE, fstr);
    format(fstr, sizeof(fstr), "Question is:{FFFFFF} %s", result);
    SendClientMessageToAll(COLOR_LIGHTGREEN, fstr);
    SendClientMessageToAll(COLOR_LIGHTBLUE, "Type /vote [Yes/No] or Press 'Y' button for Yes - Press 'N' button for No.");
    return 1;
}