givecash
#1

hey guys i have some problems with /givecash command and i know i fuck up alot but here is forum and ppl who can help for that

here is my command:

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

if(strcmp(cmd, "/givecash", true) == 0) {
new tmp[256];
tmp = strtok(cmdtext, idx);

if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_RED, "USAGE: /givecash [playerid] [amount]");
return 1;
}
giveplayerid = strval(tmp);

tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_RED, "USAGE: /givecash [playerid] [amount]");
return 1;
}
moneys = strval(tmp);

//printf("givecash_command: %d %d",giveplayerid,moneys);

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), "~w~You have sent ~g~$%d.", giveplayer,giveplayerid, moneys);
GameTextForPlayer(playerid,string,5000,5);
SendClientMessage(playerid,LIGHTBLUE,"You Sent $%d to %s (%d)!");

format(string, sizeof(string), "~w~You have recieved ~g~$%d.", moneys, sendername, playerid);
GameTextForPlayer(playerid,string,5000,5);
SendClientMessage(playerid,LIGHTBLUE,"%s (%d) Has Sent You $%d!");
printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
}
else {
SendClientMessage(playerid, COLOR_RED, "Money Sending Fail!.");
}
}
else {
format(string, sizeof(string), "ID %d is not an active player.", giveplayerid);
SendClientMessage(playerid, COLOR_RED, string);
}
return 1;
}

// PROCESS OTHER COMMANDS


return 0;
}

and the problem is, when i type command it crash my server i know i fuck up alot with strings but can you help me to make

when i send money to someone it write on scren You Send (money)
and in client message (chat) should write You Sent (money) to (player name +id)


and when player reciv You Recived (money)
in client message should write (player name +id) Has Sent You (money)

i know i fuck up something with strings cuz they are doing me much problems so i ask here for help, i hope you will help me
and if you dont know what i want i can explain again lol
Reply
#2

Try to debug your code to see where the problem appears or copy the clean /givecash command from lvdm.pwn script and change all 256 cells to 128.
Reply
#3

here's my /givecash command it allows you to type /gc ofc your going to need to edit it to your needs.

Код:
// Give Player Cash
  if ((strcmp("/givecash", cmd, true) == 0) || (strcmp(cmd, "/gc", true) == 0)) // can type both /givecash or /gc
	{
	  tmp = strtok(cmdtext,idx);
	  if (!strlen(tmp))
	  {
	    SendClientMessage(playerid,COLOR_LIGHTBLUE,"* Usage: /givecash [Player ID] [amount]"); // if player didn't type an ID
	    return 1;
		}
	  giveplayerid = strval(tmp);
		tmp = strtok(cmdtext, idx, strlen(cmdtext));
		if (!strlen(tmp))
	  {
	    SendClientMessage(playerid,COLOR_LIGHTBLUE,"* Usage: /givecash [Player ID] [amount]"); // if player didn't type an amount
	    return 1;
		}
		if (!IsPlayerConnected(giveplayerid)) // if player id typed is not connected
		{
		  format(string, sizeof(string), "* ID:%d Was not found on the server.", giveplayerid);
			SendClientMessage(playerid, COLOR_BRIGHTRED, string);
			return 1;
		}
		if (giveplayerid == playerid) 
		{
		  SendClientMessage(playerid,COLOR_BRIGHTRED,"* You cannot send your self money.");
		  return 1;
		}
		if (GetDistanceBetweenPlayers(playerid,giveplayerid) > 5) // this just checks distance will need the public for this if you wish to use it
		{
		  SendClientMessage(playerid,COLOR_BRIGHTRED,"* You are too far from this player to send them money.");
		  return 1;
		}
		new moneys[MAX_PLAYERS]; // indiviual moneys id instead of the global id you made
		moneys[playerid] = strval(tmp);
		if (moneys[playerid] < 1 || moneys[playerid] > 100000) // check if the amount is less than 1 or above 100,000
		{
		  SendClientMessage(playerid,COLOR_BRIGHTRED,"* Please enter a value between 1 and 100000.");
		  return 1;
		}
		if (moneys[playerid] > GetPlayerMoney(playerid))
		{
			SendClientMessage(playerid,COLOR_BRIGHTRED,"* You do not have that much money.");
			return 1;
		}
		GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
		GetPlayerName(playerid, playername, sizeof(playername));
		format(string, sizeof(string), "* You Sent $%d To %s (%d).",moneys[playerid],giveplayer, giveplayerid);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, string); 
		format(string, sizeof(string), "* You Recieved $%d From %s (%d).",moneys[playerid],playername, playerid);
		SendClientMessage(giveplayerid, COLOR_LIGHTBLUE, string);
		GivePlayerMoney(playerid,-moneys[playerid]); // takes the players cash
		GivePlayerMoney(giveplayerid,moneys[playerid]); // gives the receieving player cash 
		PlayerPlaySound(giveplayerid,1085,0.0,0.0,0.0); // plays a sound
		return 1;
	}
i hope this helps as an easier template
Reply
#4

Beaver. I eated one.
Reply
#5

ty guys it works ok for now but i need help with 1 more problem

Код:
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);
	
	if ((strcmp("/givecash", cmd, true) == 0) || (strcmp(cmd, "/gc", true) == 0)) // can type both /givecash or /gc
	  {
	  new tmp[256];
		tmp = strtok(cmdtext, idx);

		if(!strlen(tmp)) {
			SendClientMessage(playerid,ADMIN_RED, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
		giveplayerid = strval(tmp);

		tmp = strtok(cmdtext, idx);
		if(!strlen(tmp)) {
			SendClientMessage(playerid,ADMIN_RED, "USAGE: /givecash [playerid] [amount]");
			return 1;
		}
 		moneys = strval(tmp);

		//printf("givecash_command: %d %d",giveplayerid,moneys);


		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), "~w~You have sent~g~ $%d.", giveplayer,giveplayerid, moneys);
			GameTextForPlayer(playerid,string,2000,5);
			format(string, sizeof(string), "~w~You have recieved~g~ $%d.", moneys, sendername, playerid);
			GameTextForPlayer(playerid,string,2000,5);
			printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
			}
			else {
				SendClientMessage(playerid,ADMIN_RED, "Invalid transaction amount.");
			}
		}
		else {
				format(string, sizeof(string), "Id %d is not an active player.", giveplayerid);
				SendClientMessage(playerid, ADMIN_RED, string);
			}
		return 1;
	}

	// PROCESS OTHER COMMANDS


	return 0;
}
when i am sending money to someone (i test that ) it write YOU RECIVE (money ) when i am sending money lol wtf zomg

what should i do ?
Reply
#6

Fixed ty anyway
Reply
#7

Quote:
Originally Posted by Lajko1
Fixed ty anyway
Glad to see you've found a solution, but you should consider switching to ZCMD or even DCMD, it's so much more efficient, and look how much shorter it is..

This is a ZCMD givemoney command:

pawn Код:
zcmd(givemoney, playerid, params[])
{
    new player, money, string[128];
    new gotmoney[MAX_PLAYER_NAME];
    new givemoney[MAX_PLAYER_NAME];
    GetPlayerName(player, gotmoney, sizeof(gotmoney));
    GetPlayerName(playerid, givemoney, sizeof(givemoney));
    if(!sscanf(params, "ui", player, money))
    {
      if(player != INVALID_PLAYER_ID)
      {
            GivePlayerMoney(player, money);
            GivePlayerMoney(playerid, -money);
            format(string, sizeof(string), ">> You have sent $%d to %s.",money, gotmoney);
            SendClientMessage(playerid, white, string);
            format(string, sizeof(string), ">> You have received $%d from %s.",money, givemoney);
            SendClientMessage(player, white, string);
        }
        else return SendClientMessage(playerid, red, ">> Error: Invalid UserID.");
    }
    else return SendClientMessage(playerid, white, "USAGE: /SetMoney [Player ID/Part of Name] [Amount]");
    return 1;
}
If you do not wish to convert, that's fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)