SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 09/10/2009, 11:35 AM   #1
Lajko1
High-roller
 
Join Date: Oct 2008
Posts: 1,235
Reputation: 17
Default givecash

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
Lajko1 is offline  
Old 09/10/2009, 01:04 PM   #2
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 6,340
Reputation: 365
Default Re: givecash

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.
Correlli is offline  
Old 09/10/2009, 02:52 PM   #3
Beaver07
Big Clucker
 
Join Date: Sep 2007
Posts: 171
Reputation: 0
Default Re: givecash

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

Code:
// 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
Beaver07 is offline  
Old 09/10/2009, 04:51 PM   #4
SinisterCrime-
Big Clucker
 
Join Date: Jul 2007
Posts: 52
Reputation: 0
Default Re: givecash

Beaver. I eated one.
SinisterCrime- is offline  
Old 09/10/2009, 06:40 PM   #5
Lajko1
High-roller
 
Join Date: Oct 2008
Posts: 1,235
Reputation: 17
Default Re: givecash

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

Code:
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 ?
Lajko1 is offline  
Old 09/10/2009, 06:43 PM   #6
Lajko1
High-roller
 
Join Date: Oct 2008
Posts: 1,235
Reputation: 17
Default Re: givecash

Fixed ty anyway
Lajko1 is offline  
Old 09/10/2009, 10:06 PM   #7
(.Aztec);
Huge Clucker
 
Join Date: Mar 2009
Posts: 425
Reputation: 2
Default Re: givecash

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 Code:
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.
__________________
Account Inactive

(.Aztec); will no longer be used by me. I am changing my username to an old forum account i've had registered for a while, but never used.

My username has been changed to Sky4D
(.Aztec); is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
/givecash 02manchestera Help Archive 3 14/03/2010 02:51 PM
Givecash bug Puzi Help Archive 5 07/03/2010 01:23 AM
PLease help with /givecash Scoots Help Archive 28 27/03/2009 11:42 AM
givecash CJ101 Help Archive 1 19/02/2009 02:05 PM
/givecash amrour Help Archive 5 15/02/2009 03:55 PM


All times are GMT. The time now is 09:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.