Dcmd igan..
#1

Ok this code does work but i wondering if this is fully optimised... If not pls tell me woot I can make better. I try to learn dcmd

Код:
dcmd_givecash(playerid, params[])
{
	new
	sendername[MAX_PLAYER_NAME],
	giveplayer[MAX_PLAYER_NAME],
	giveplayerid,
	playermoney,
	string[128],
	moneys;
	if (sscanf(params, "dd", giveplayerid, moneys))
	{
	SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	return 1;
  }
	if (IsPlayerConnected(giveplayerid))
	{
	GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
	GetPlayerName(playerid, sendername, sizeof(sendername));
	playermoney = GetPlayerMoney(playerid);
	if (moneys > 0 && playermoney >= moneys)
	{
	GivePlayerMoney(playerid, (0 - moneys));
	GivePlayerMoney(giveplayerid, moneys);
	format(string, sizeof(string), "You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
	SendClientMessage(playerid, COLOR_YELLOW, string);
  	format(string, sizeof(string), "You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
	SendClientMessage(giveplayerid, COLOR_YELLOW, string);
	printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
	} else {
	SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount."); }
	} else {
	format(string, sizeof(string), "%d is not an active player!", giveplayerid);
	SendClientMessage(playerid, COLOR_YELLOW, string);
	}
	return 1;
}
Reply
#2

There are some things.
Код:
new
	sendername[MAX_PLAYER_NAME],
	giveplayer[MAX_PLAYER_NAME],
	giveplayerid,
	playermoney,
	string[128],
	moneys;
could be:
Код:
new sendername[24], giveplayer[24], giveplayerid, playermoney, string[128], moneys;
You should also change:
Код:
if (sscanf(params, "dd", giveplayerid, moneys))
	{
	SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	return 1;
  }
to:
Код:
if(sscanf(params, "dd", giveplayerid, moneys)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
Don't know why, but its just my way of coding. The amount of lines is smaller, which makes your file less big. Also it looks more professional
Reply
#3

This was a nice idea I think I steal it Tanks... But one thing why new sendername[24], giveplayer[24]; insted of new sendername[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME]; ?
Reply
#4

Quote:
Originally Posted by иєσz
There are some things.
Код:
new
	sendername[MAX_PLAYER_NAME],
	giveplayer[MAX_PLAYER_NAME],
	giveplayerid,
	playermoney,
	string[128],
	moneys;
could be:
Код:
new sendername[24], giveplayer[24], giveplayerid, playermoney, string[128], moneys;
You should also change:
Код:
if (sscanf(params, "dd", giveplayerid, moneys))
	{
	SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	return 1;
  }
to:
Код:
if(sscanf(params, "dd", giveplayerid, moneys)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
Don't know why, but its just my way of coding. The amount of lines is smaller, which makes your file less big. Also it looks more professional
That wouldn't make ANY difference.
Reply
#5

Quote:
Originally Posted by Stevelo
Quote:
Originally Posted by иєσz
There are some things.
Код:
new
	sendername[MAX_PLAYER_NAME],
	giveplayer[MAX_PLAYER_NAME],
	giveplayerid,
	playermoney,
	string[128],
	moneys;
could be:
Код:
new sendername[24], giveplayer[24], giveplayerid, playermoney, string[128], moneys;
You should also change:
Код:
if (sscanf(params, "dd", giveplayerid, moneys))
	{
	SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
	return 1;
  }
to:
Код:
if(sscanf(params, "dd", giveplayerid, moneys)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid] [amount]");
Don't know why, but its just my way of coding. The amount of lines is smaller, which makes your file less big. Also it looks more professional
That wouldn't make ANY difference.
No and ? It look nicer and why did you post that and not a optimised code?
Reply
#6

Quote:
Originally Posted by Stevelo
That wouldn't make ANY difference.
Quote:
Originally Posted by Roban[swe
]
i wondering if this is fully optimised... If not pls tell me woot I can make better.
Quote:
Originally Posted by Roban[swe
]
But one thing why new sendername[24], giveplayer[24]; insted of new sendername[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME]; ?
Names won't be longer then 24 characters, MAX_PLAYER_NAME is like 28 or something? I'm not sure tho. Its just my way of coding.
Reply
#7

Quote:
Originally Posted by иєσz
Quote:
Originally Posted by Stevelo
That wouldn't make ANY difference.
Quote:
Originally Posted by Roban[swe
]
i wondering if this is fully optimised... If not pls tell me woot I can make better.
Quote:
Originally Posted by Roban[swe
]
But one thing why new sendername[24], giveplayer[24]; insted of new sendername[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME]; ?
Names won't be longer then 24 characters, MAX_PLAYER_NAME is like 28 or something? I'm not sure tho. Its just my way of coding.
Ok... Tanks for all help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)