Need help making command
#1

Hello guys, well i have been studying some scripts for couple hours now and would llike to know how can do this,
so what i wanna do is when i type /command [playerid] [moneyamount] [reason for the money] its gona give that id some money and its gona show the reason, can somebody give me a lil help with this? thanks very much.
Reply
#2

Код:
dcmd_give(playerid, params[])
{
	new id; new kiekis;
	if (sscanf(params, "dd", id, kiekis)) return SendClientMessage(playerid, GRAY, "[Klaida]: /give [playerid] [ammount]");
	if (IsPlayerConnected(id))
	{
	    if(kiekis >= GetPlayerMoney(playerid))
	    {
	        SendClientMessage(playerid, GRAY, "[Klaida]: you dont have enough money!");
		}
		else
	    {
	        if(id == playerid)
	        {
	            SendClientMessage(playerid,GRAY, "[Klaida]: for yourself cant give!");
	        }
	        else
			{
	    		ac_GivePlayerMoney(playerid, -kiekis);
	    		ac_GivePlayerMoney(id, kiekis);
				new string[128]; new zaid[128]; new siuntejas[128];
				GetPlayerName(id,zaid,sizeof(zaid));
				GetPlayerName(playerid,siuntejas,sizeof(siuntejas));
				format(string,sizeof(string),"[SF-FR]:you give %s money:$%d.",zaid,kiekis);
				SendClientMessage(playerid,YELLOW, string);
				format(string,sizeof(string),"[SF-FR]: %s give you money: %d.",siuntejas,kiekis);
				SendClientMessage(id,YELLOW, string);
				printf(">> %s  perveda %s pinigu: $%d.", siuntejas, zaid, kiekis);
			}
		}
	}
	else
	{
		SendClientMessage(playerid,GRAY,"[error]: player not found");
	}
	return 1;
}
sorry for bad english
Reply
#3

Quote:
Originally Posted by cacauagiar
Посмотреть сообщение
Hello guys, well i have been studying some scripts for couple hours now and would llike to know how can do this,
so what i wanna do is when i type /command [playerid] [moneyamount] [reason for the money] its gona give that id some money and its gona show the reason, can somebody give me a lil help with this? thanks very much.
Yeah, use ZCMD and SSCANF for best results. Download both ZCMD and SSCANF by using the search feature (http://forum.sa-mp.com/search.php). Follow the instructions on the threads for them.

Next, here is a script you could use for this.

pawn Код:
#include <zcmd> // Top of your script
#include <sscanf> // Top of your script

#define white 0xFFFFFFAA // This could go at the top, or underneath the CMD:command line and bracket.

CMD:command(playerid, params[]) // Anywhere in your script below the includes.
{
  // You could check to see if they're admin here. I don't know what your script's variables are like.
  new string[128], giveplayerid, money;
  if(sscanf(params, "ud", giveplayerid, money)) return SendClientMessage(playerid, white, "Invalid syntax.");
  if(IsPlayerConnected(giveplayerid))
  {
      GivePlayerCash(giveplayerid, money);
      format(string, 128, "You have given that player $%d.",money);
      SendClientMessage(playerid, white, string);
     // You could log the transaction here, or provide an admin message.    
  }
  return 1;
}
Reply
#4

Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
Reply
#5

Quote:
Originally Posted by cacauagiar
Посмотреть сообщение
Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
Yeah, you can do any command in STRCMP. I don't suggest you do, but you can.


pawn Код:
#define white 0xFFFFFFAA // top of script

#pragma tabsize 0 // You can delete this, but I used it to get rid of loose indentation warnings.

// Put this code under "OnPlayerCommandText", use ctrl + f to search for it.
new cmd[128], idx;
cmd = strtok(cmdtext, idx);


if(strcmp(cmd, "/command", true) == 0)
{
    new parameterstring[256], messagestring[128],
    giveplayerid, moneytogive;
    parameterstring = strtok(cmdtext, idx);

    // You could check to see if the player is an admin here.

    if(!strlen(parameterstring))
    {
        SendClientMessage(playerid, white, "Invalid syntax.");
        return 1;
    }
    giveplayerid = strval(parameterstring);
        parameterstring= strtok(cmdtext, idx);
        if(!strlen(parameterstring))
        {
        SendClientMessage(playerid, white, "Invalid syntax.");
        return 1;
        }

         moneytogive = strval(parameterstring);
         if (IsPlayerConnected(giveplayerid))
         {
                GivePlayerMoney(giveplayerid, moneytogive);
                format(messagestring, 128, "You gave that player $%d.", moneytogive);
        SendClientMessage(playerid, white, messagestring);
         }
         else
         {
               SendClientMessage(playerid, white, "Invalid player.");
         }
         return 1;
}


strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply
#6

Quote:
Originally Posted by cacauagiar
Посмотреть сообщение
Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
fyi: jail is much tougher to understand, if you want it perfect.

Anyway, you wish it to includeless, so.

Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/jail", true, 5))
{
    if (IsPlayerAdmin(playerid))
    {
        if(!strlen(cmdtext[6]))
        {
            SendClientMessage(playerid, COLOR_WHITE, "Usage: /jail [playerid]");
            return 1;
        }
        new ID = strval(cmdtext[6]);
        new strv[170];
        if(IsPlayerConnected(ID))
        {
            format(strv, 170, "~ You have been jailed");
            SendClientMessage(ID,COLOR_WHITE, strv);
            SetPlayerPos(ID, 264.8763,81.9862,1001.0390);
            SetPlayerInterior(ID, 6);
        }
    }
    return SendClientMessage(playerid, COLOR_WHITE, "Your not rcon admin!");
}
        return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)