SA-MP Forums Archive
[Easy] Scripting question, related to cmd, help please. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Easy] Scripting question, related to cmd, help please. (/showthread.php?tid=252632)



[Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

Hello,

As you might know I am new to scripting, and I'm like editing a gamemode, roleplay one and I'd like to have something like /givecash or /setcash to a player, could someone give me a code for that command please?

Thanks in advance, Clueless


Re: [Easy] Scripting question, related to cmd, help please. - berz - 02.05.2011

Here is for /givemoney commands.
Код:
 if(strcmp(cmd, "/givemoney", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /givemoney [playerid/PartOfName] [money]");
				return 1;
			}
			new playa;
			new money;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			money = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1340) // u can change pAdmin]>= level u are using. 
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
			            //ConsumingMoney[playa] = 1;
						SafeGivePlayerMoney(playa, money);
						GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						format(string, 256, "AdmWarning: %s has admin-given %s $%d.", sendername,giveplayer,money);
						ABroadCast1(COLOR_YELLOW,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
			}
		}
		return 1;
	}

Here /money command, with that u can set someones money to what number u want.
Код:
if(strcmp(cmd, "/money", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /money [playerid/PartOfName] [money]");
				return 1;
			}
			new playa;
			new money;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			money = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1340) // Here change pAdmin level ( owner ) if u are using some other level for it
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
						SafeResetPlayerMoney(playa);
						//ConsumingMoney[playa] = 1;
						SafeGivePlayerMoney(playa, money);
						GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						format(string, 256, "AdmWarning: %s has set %s money to $%d.", sendername,giveplayer,money);
						ABroadCast1(COLOR_YELLOW,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
			}
		}
		return 1;
	}

Good luck and have fun!


Re: [Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

Where do I need to post that mate?


Re: [Easy] Scripting question, related to cmd, help please. - Retardedwolf - 02.05.2011

Learn using zcmd with sscanf. An example is given in this particular wiki post.


Re: [Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

I have zcmd plugin on my script, how can I add a /givecash now?
I want it to be admin givable, not player.. like an high lvl admin can set you money..


Re: [Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

Quote:
Originally Posted by berz
Посмотреть сообщение
Here is for /givemoney commands.
Код:
 if(strcmp(cmd, "/givemoney", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /givemoney [playerid/PartOfName] [money]");
				return 1;
			}
			new playa;
			new money;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			money = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1340) // u can change pAdmin]>= level u are using. 
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
			            //ConsumingMoney[playa] = 1;
						SafeGivePlayerMoney(playa, money);
						GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						format(string, 256, "AdmWarning: %s has admin-given %s $%d.", sendername,giveplayer,money);
						ABroadCast1(COLOR_YELLOW,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
			}
		}
		return 1;
	}

Here /money command, with that u can set someones money to what number u want.
Код:
if(strcmp(cmd, "/money", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /money [playerid/PartOfName] [money]");
				return 1;
			}
			new playa;
			new money;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			money = strval(tmp);
			if (PlayerInfo[playerid][pAdmin] >= 1340) // Here change pAdmin level ( owner ) if u are using some other level for it
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
						SafeResetPlayerMoney(playa);
						//ConsumingMoney[playa] = 1;
						SafeGivePlayerMoney(playa, money);
						GetPlayerName(playa, giveplayer, sizeof(giveplayer));
						GetPlayerName(playerid, sendername, sizeof(sendername));
						format(string, 256, "AdmWarning: %s has set %s money to $%d.", sendername,giveplayer,money);
						ABroadCast1(COLOR_YELLOW,string,1);
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
			}
		}
		return 1;
	}

Good luck and have fun!
Where?


Re: [Easy] Scripting question, related to cmd, help please. - xir - 02.05.2011

pawn Код:
COMMAND:setmoney(playerid, params[])
{
    new id, amount, name[MAX_PLAYER_NAME], string[128];
    if (sscanf(params, "ud", id, amount)) SendClientMessage(playerid, -1, "Usage: /givecash <playerid/name> <amount of cash>");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "This player is not connected");
    else
    {
        GetPlayerName(playerid, name, sizeof(name));
        GivePlayerMoney(id, amount);
        format(string, sizeof(string), "You recived $%d from Admin %s",amount, name);
        SendClientMessage(id, -1, string);
    }
    return 1;
}



Re: [Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

Where do I need to put that mate?


Re: [Easy] Scripting question, related to cmd, help please. - xir - 02.05.2011

First, do you have any strcmp in your gamemode?
Second, you said you wanted that for admins? Do you have an admin system or you use RCON?


Re: [Easy] Scripting question, related to cmd, help please. - Clueless - 02.05.2011

I have admin system, and zcmd, and yes I got strcmp, I just need a admin command, only able to be done by lvl 6 admin, to give a player a desired ammount of cash