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; }
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. |
#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;
}
Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
|
#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;
}
Is there anything even more simple? that i wont need an include, like a simple /jail [id] [time] [reason]
|
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; }