[Easy] Scripting question, related to cmd, help please.
#1

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
Reply
#2

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!
Reply
#3

Where do I need to post that mate?
Reply
#4

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

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..
Reply
#6

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?
Reply
#7

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;
}
Reply
#8

Where do I need to put that mate?
Reply
#9

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?
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)