SA-MP Forums Archive
Dcmd igan.. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Dcmd igan.. (/showthread.php?tid=73085)



Dcmd igan.. - robanswe - 12.04.2009

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;
}



Re: Dcmd igan.. - HB - 12.04.2009

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



Re: Dcmd igan.. - robanswe - 12.04.2009

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]; ?


Re: Dcmd igan.. - NigNog1 - 12.04.2009

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.


Re: Dcmd igan.. - robanswe - 12.04.2009

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?


Re: Dcmd igan.. - HB - 12.04.2009

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.


Re: Dcmd igan.. - robanswe - 12.04.2009

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!