SA-MP Forums Archive
command issue - 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: command issue (/showthread.php?tid=487024)



command issue - Gecko75 - 11.01.2014

I made this command. /setfaction
When you enter /setfaction name [id] or something, it doesn't return any message at all.

even if I put in a name and ID, it doesnt do anything at all.
Код:
CMD:setfaction(playerid, params[])
{
	new factionid, choice[32], type;
	if(!CheckAdmin(playerid, ADMIN_LEVEL_3)) return NotAuthMSG(playerid);
	if(isnull(params))
	{
		SCM(playerid, COLOR_GREY,     "Usage: /setfaction [param] [factionid]");
		SCM(playerid, COLOR_LIGHTRED, " name, type, uniform, spawn");
		SCM(playerid, COLOR_LIGHTRED, " rankamount, leaderrank, joinrank");
		return 1;
	}
	
	if(strcmp(params, "name", true) == 0)
	{
	    new name[64];
	    if(sscanf(params,"s[32]dis[64]", params, factionid, type, name))
		{
		    SCM(playerid, COLOR_GREY,     "Usage: /setfaction name [factionid] [type] [name]");
		    SCM(playerid, COLOR_LIGHTRED, "Types: 1 - Department Name | 2 - Full Name");
		    return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, COLOR_LIGHTRED, "That faction doesn't exist.");
		switch(type)
		{
	    	case 1:
	    	{
		        format(Factions[factionid][fName2], 10, "%s", name);
				format(msg, sizeof(msg), "You have changed faction %d's Department Name to %s.", factionid, name);
				SCM(playerid, COLOR_GREEN, msg);
				format(query, sizeof(query), "UPDATE `factions` SET `name2` = '%s' WHERE `id` = %d", name, Factions[factionid][fID]);
				mysql_function_query(dbHandle, query, false, "", "");
			}
			case 2:
			{
			    format(Factions[factionid][fName], 128, "%s", name);
				format(msg, sizeof(msg), "You have changed faction %d's name to %s.", factionid, name);
				SCM(playerid, COLOR_GREEN, msg);
				format(query, sizeof(query), "UPDATE `factions` SET `name` = '%s' WHERE `id` = %d", name, Factions[factionid][fID]);
				mysql_function_query(dbHandle, query, false, "", "");
			}
			default: return SCM(playerid, COLOR_GREY, "Only types 1-2.");
		}
		return 1;
	}
	if(strcmp(params, "type", true) == 0)
	{
	    if(sscanf(params,"s[32]dd", params, factionid, type))
		{
		    SCM(playerid, COLOR_GREY,     "Usage: /setfaction type [factionid] [type]");
		    SCM(playerid, COLOR_LIGHTRED, "Types: 1 - LAW | 2 - FD/EMS | 3 - Criminal");
		    return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, COLOR_LIGHTRED, "That faction doesn't exist.");
		Factions[factionid][fType] = type;
		format(msg, sizeof(msg), "You have changed faction %d's type to %d.", factionid, type);
		SCM(playerid, COLOR_GREEN, msg);
		format(query, sizeof(query), "UPDATE `factions` SET `type` = %d WHERE `id` = %d", type, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	if(strcmp(params, "uniform", true) == 0)
	{
	    new Float:x, Float:y, Float:z;
		if(sscanf(params,"s[32]d", params, factionid))
		{
			SCM(playerid, COLOR_GREY, "Usage: /setfaction uniform [factionid] - Sets the faction's uniform spot to your POS.");
			return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, COLOR_LIGHTRED, "That faction doesn't exist.");
		GetPlayerPos(playerid, x, y, z);
		Factions[factionid][fUniformX] = x;
		Factions[factionid][fUniformY] = y;
		Factions[factionid][fUniformZ] = z;
		format(msg, sizeof(msg), "You have changed faction %d's uniform to your position.", factionid);
		SCM(playerid, COLOR_GREEN, msg);
		DestroyDynamicPickup(Factions[factionid][fPickUp]);
		Factions[factionid][fPickUp] = CreateDynamicPickup(1239, 1, x, y, z, -1, -1, -1, 100.0);
		format(query, sizeof(query), "UPDATE `factions` SET `uniformx` = %f, `uniformy` = %f, `uniformz` = %f WHERE `id` = %d", x, y , z, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	if(strcmp(params, "spawn", true) == 0)
	{
	    new Float:x, Float:y, Float:z;
		if(sscanf(params,"s[32]d", params, factionid))
		{
			 SCM(playerid, COLOR_GREY, "Usage: /setfaction spawn [factionid] - Sets the faction's spawn to your POS.");
			 return 1;
		}

		GetPlayerPos(playerid, x, y, z);
		new interior = GetInterior(playerid);
		Factions[factionid][fX] = x;
		Factions[factionid][fY] = y;
		Factions[factionid][fZ] = z;
		Factions[factionid][fSpawnInt] = interior;
		format(msg, sizeof(msg), "You have changed faction %d's spawn to your position.", factionid);
		SCM(playerid, COLOR_GREEN, msg);
		format(query, sizeof(query), "UPDATE `factions` SET `spawnx` = %f, `spawny` = %f, `spawnz` = %f, `spawnint` = %d WHERE `id` = %d", x, y , z, interior, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	if(strcmp(params, "rankamount", true) == 0)
	{
	    new amount;
		if(sscanf(params,"s[32]dd", params, factionid, amount))
		{
		    SCM(playerid, COLOR_GREY, "Usage: /setfaction rankamount [factionid] [amount] - Sets the amount of ranks a faction can own");
		    return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, COLOR_LIGHTRED, "That faction doesn't exist.");
		Factions[factionid][fRankAmount] = amount;
		format(msg, sizeof(msg), "You have changed faction %d's rank amount to %d.", factionid, amount);
		SCM(playerid, COLOR_GREEN, msg);
		format(query, sizeof(query), "UPDATE `factions` SET `rankamount` = %d WHERE `id` = %d", amount, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	if(strcmp(params, "leaderrank", true) == 0)
	{
	    new rank;
		if(sscanf(params,"s[32]dd", params, factionid, rank)) 
		{
		    SCM(playerid, COLOR_GREY, "Usage: /setfaction leaderrank [factionid] [rank] - Sets the rank ID to the leader ID.");
		    return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, COLOR_LIGHTRED, "That faction doesn't exist.");
		Factions[factionid][fLeaderRank] = rank;
		format(msg, sizeof(msg), "You have changed faction %d's leader rank to %d.", factionid, rank);
		SCM(playerid, COLOR_GREEN, msg);
		format(query, sizeof(query), "UPDATE `factions` SET `leaderrank` = %d WHERE `id` = %d", rank, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	if(strcmp(params, "joinrank", true) == 0)
	{
	    new rank;
		if(sscanf(params,"s[32]dd", params, factionid, rank))
		{
		    SCM(playerid, COLOR_GREY, "Usage: /setfaction joinrank [factionid] [rankid] - Sets the default joining rank for the faction");
		    return 1;
		}
		if(!Factions[factionid][fON]) return SCM(playerid, -1, "Invalid faction.");
		Factions[factionid][fJoinRank] = rank;
		format(msg, sizeof(msg), "You have changed faction %d's join rank to %d.", factionid, rank);
		SCM(playerid, COLOR_GREEN, msg);
		format(query, sizeof(query), "UPDATE `factions` SET `joinrank` = %d WHERE `id` = %d", rank, Factions[factionid][fID]);
		mysql_function_query(dbHandle, query, false, "", "");
		return 1;
	}
	return 1;
}



Re: command issue - dominik523 - 11.01.2014

Try to get choice on the beginning of your command? And then compare it with strcmp.
pawn Код:
CMD:setfaction(playerid, params[])
{
    new factionid, choice[32], type;
    if(!CheckAdmin(playerid, ADMIN_LEVEL_3)) return NotAuthMSG(playerid);
    if(sscanf(params, "s[32]", choice))
    {
        SCM(playerid, COLOR_GREY,     "Usage: /setfaction [param] [factionid]");
        SCM(playerid, COLOR_LIGHTRED, " name, type, uniform, spawn");
        SCM(playerid, COLOR_LIGHTRED, " rankamount, leaderrank, joinrank");
        return 1;
    }
if(strcmp(choice, "name", true) == 0)
    {