26.07.2013, 18:47
From the title , and since this is in help.. That means I need help in making a /givecash command for normal players.
Pwease help.
Thanks.
Pwease help.
Thanks.
#include <a_samp>
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define GIVECASH_DELAY 5000 // Time in ms between /givecash commands.
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
new playermoney;
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
new cmd[256];
new giveplayerid, moneys, idx;
cmd = strtok(cmdtext, idx);
new player;
if(strcmp(cmd, "/givecash", true) == 0) {
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash <id> <amount>");
return 1;
}
giveplayerid = strval(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash <id> <amount>");
return 1;
}
moneys = strval(tmp);
if (IsPlayerConnected(giveplayerid))
{
if(player==playerid)
{
SendClientMessage(playerid, 0xE40C0CFF, "You cannot send money to yourself.");
return 1;
}
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
playermoney = GetPlayerMoney(playerid);
if(moneys > 50000 || moneys < 1) return SendClientMessage(playerid,0xE40C0CFF,"Invalid ammount.");
if (moneys > 0 && playermoney >= moneys)
{
GivePlayerMoney(playerid, (0 - moneys));
GivePlayerMoney(giveplayerid, moneys);
format(string, sizeof(string), "» You sent $%d to %s (ID:%d).", moneys,giveplayer,giveplayerid );
SendClientMessage(playerid, 0xE89B5BBB, string);
format(string, sizeof(string), "» %s (ID:%d) sent you $%d.", sendername,playerid ,moneys );
SendClientMessage(giveplayerid, 0xE89B5BBB, string);
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else
{
SendClientMessage(playerid, 0xE40C0CFF, "You don't have that much money.");
}
}
else
{
SendClientMessage(playerid, 0xE40C0CFF, "Player not found.");
}
return 1;
}
return 0;
}
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;
}
CMD:givecash(playerid, params[])//if you are using ZCMD > credits to zeex....
{
//first we are creating some variables that will help us much
new Target, value;//we've created the target who will be givn the money and the value (how much they will take)
if(sscanf(params, "ds", Target, value)) return SendClientMessage(playerid, -1, "SYNTAX: /givecash [playerid] [ammount]");
//now, we've used sscanf to detect if the player has entered wrong syntax
// d > Target
//s > value
// -1 > color white.
GivePlayerMoney(playerid, -value);//we put the "-" to reduce the value from his money
GivePlayerMoney(Target, value);//now we are giving that value to the target
//we've done the transfer
//Additional, let's put some messages (by format)
new str[50];//added a new variable (string)
format(str, sizeof(str), "ID(%d) has given you $%d",playerid, value);
SendClientMessage(playerid, -1, str);
//read about formats , it's easy :D
return 1;
}
Thnx Red, or R3D
But I don't use ZCMD I use the normal format and dcmd. |
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(givecash, 8, cmdtext);
return 1;
}
dcm_givecash(playerid, params[])//if you are using ZCMD > credits to zeex....
{
//first we are creating some variables that will help us much
new Target, value;//we've created the target who will be givn the money and the value (how much they will take)
if(sscanf(params, "ds", Target, value)) return SendClientMessage(playerid, -1, "SYNTAX: /givecash [playerid] [ammount]");
//now, we've used sscanf to detect if the player has entered wrong syntax
// d > Target
//s > value
// -1 > color white.
GivePlayerMoney(playerid, -value);//we put the "-" to reduce the value from his money
GivePlayerMoney(Target, value);//now we are giving that value to the target
//we've done the transfer
//Additional, let's put some messages (by format)
new str[50];//added a new variable (string)
format(str, sizeof(str), "ID(%d) has given you $%d",playerid, value);
SendClientMessage(playerid, -1, str);
//read about formats , it's easy :D
return 1;
}
dcmd_givecash(playerid,params[])
{
new string[128];
new ID;
new cmdreason;
new pname[MAX_PLAYER_NAME];
new tname[MAX_PLAYER_NAME];
if(sscanf(params,"uii",ID,cmdreason))
{
SendClientMessage(playerid,COLOR_ERROR,"[USAGE] /givecash (Player Name/ID) (Amount)");
return 1;
}
if(!IsPlayerConnected(ID))
{
format(string,sizeof(string),"[ERROR] The player ID you entered is not connected to the server.");
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}
GetPlayerName(playerid,pname,sizeof(pname));
GetPlayerName(ID,tname,sizeof(tname));
GivePlayerMoney(ID, cmdreason);
format(string,sizeof(string),"[CASH] Administrator %s(%d) has given you cash. [Amount: %d$]",pname,playerid,cmdreason);
SendClientMessage(ID,COLOR_PINK,string);
format(string,sizeof(string),"[CASH] You have given %s(%d) cash. [Amount: %d$]",tname,ID,cmdreason);
SendClientMessage(playerid,COLOR_PINK,string);
return 1;
}