Making an easy /pay [playerid/name] [amount] system -
knackworst - 11.09.2011
/pay commmand tutorial:
What does it do??
It's basically a command to give other players money, u can only give the player money, if you have the amount of money that u want to give...
So you cant do this: /pay misterplayer 1000000 if you only have got 1$
My goal, is that after you have read this tutorial, you can create much commands like these yourself : )
Ok So let's get started:
Step 1:
First of all, we are going to use DCMD
we only need a define
pawn Code:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
now, I have no idea what the hell that means, I think there are only a few people who know what it means (you don't need to know what it means to make commands using DCMD...)...
anyways, this is just one define u need in your script to use dcmd.
Ok, so now, u can use DCMD.
We will also need scanf.
Wich can be downloaded here:
https://sampforum.blast.hk/showthread.php?tid=120356
just follow the instructions to install and download
Step 2:
Now we are going to make the command...
put this anywhere in your script:
pawn Code:
dcmd_pay(playerid,params[])
{
return 1;
}
this is the command, change Pay in to whatever you want to name your command...
ok, so now we are going to add statics.
statics, are almost the same as new, except that static can only be used in one command, and new in your entire script...
static ID;
ok, so this is a static to make something that will track, who you wanna pay
(there are more statics ofcourse, but i'll add them only when necesairy so I won't confuse you)
now add this under the first bracket:
pawn Code:
if (sscanf(params, "ii", ID,amount)) return SendClientMessage(playerid, 0xff0000aa, "* Usage: /pay [playerid] [amount]");
ok so this are the params, the first "i" stands for the player u wanna pay, and the second "i" for the amount.
this is what makes this type of commands different from the normal commands, u used to make.
Now we can use everything that a player insert after the /pay [something here] [something here]
ofcourse for the amount we need to make a new static, so your static line should look like this now:
ok, so the return SendClientMessage(playerid,...) is just a message that u will get when you are not using the command correctly...
Now we are going to make limitations, so the player cannot give more money than he has, and the player cannot pay theirselves...
ok so add this under the if(scanff(params...
pawn Code:
if (amount > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xff0000aa, "* You do not have enough money to pay that player!");
pawn Code:
if(amount > GetPlayerMoney(playerid))
this checks if the amount that the player has inserted in the second "i" is more than his own amount of money.
pawn Code:
return SendClientMessage(playerid, 0xff0000aa, "* You do not have enough money to pay that player!");
This sends a message that you are trying to give the player more than you have...
Next limitation we are going to create is that the player cannot give the other player less than 1$
so add this:
pawn Code:
if (amount <= 0) return SendClientMessage(playerid, 0xff0000aa, "* You can't pay less than 1!");
under
pawn Code:
if (amount > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xff0000aa, "* You do not have enough money to pay that player!");
so:
this checks if the player has inserted an amount equal to 0 or less than 0
pawn Code:
return SendClientMessage(playerid, 0xff0000aa, "* You can't pay less than 1!");
This sends a message that the player has tried to give 0 or less than 0
Next Limitation: now let's make sure that the player cannot give money to themselves...
so add this:
pawn Code:
if (playerid == ID) return SendClientMessage(playerid, 0xff0000aa, "* You can't pay yourselve!");
under our other if statements
this means when the player who types the command = playerid executes the command on himself...
so the playerid is always the commnad user
the ID is always the one u do the command on.
and then the return SendClientMessage is the message u get when you wnna pay yourself again...
Next We are going to create something that gives the player a message when he/she pays someone and a message to the player who gets the money...
for that add this:
pawn Code:
GetPlayerName(ID, name2, sizeof(name2));
format(string8,sizeof(string8),"{FFFF00}|- You have paid %s $%i -|",name2,amount);
SendClientMessageToAll(COLOR_RED,string8);
GetPlayerName(playerid, name, sizeof(name));
format(string7,sizeof(string7),"{FFFF00}* %s(%d) Has paid you: $%i",name,playerid,amount);
SendClientMessage(ID,COLOR_RED,string7);
under our if statements.
Ok so here we are going to use strings, to tell the player how much he gave and who he gave it too.
Same for the player who gets the money
because we are going to use strings, we need to make new statics.
so your static line should look like this now:
pawn Code:
static ID, amount, name[MAX_PLAYERS], string7[200], name2[MAX_PLAYERS], string8[200];
pawn Code:
GetPlayerName(ID, name2, sizeof(name2));
this will insert the name of the player you gave the money too in our string.
NOTE: It's important that it's GetPlayerName(ID
if you do this: GetPlayerName(playerid
you will get the name of the player who does the command...
pawn Code:
format(string8,sizeof(string8),"{FFFF00}|- You have paid %s $%i -|",name2,amount);
SendClientMessageToAll(COLOR_RED,string8);
Ok, so here we choose the text for the player, at the end of this format you can see name2,amount
this will insert the string "name2" in the %s, so ingame it will give: You have Paid playeryoupaid
The amount, will insert the amount that the player wants to pay into the %i
we did not have to create a string for the amount, because its already used it in the scanf params
and then the SendClientMessageToAll, will just be the format we have created
NOTE: You might see COLOR_RED, if you haven't define it in your script yet you will get an error: undefined symbol: COLOR_RED
just change the COLOR_RED into a color code or into a red color define you have already defined in your script...
Ok, now last we need to give the player the money...
for that add:
pawn Code:
SetPlayerMoney(ID, GetPlayerMoney(ID) +amount);
SetPlayerMoney(playerid, GetPlayerMoney(playerid) -amount);
under the string things
pawn Code:
SetPlayerMoney(ID, GetPlayerMoney(ID) +amount);
this sets the player that has been paid's money to the amount the command user has entered...
pawn Code:
SetPlayerMoney(playerid, GetPlayerMoney(playerid) -amount);
this will set the command user money minus the amount he entered, if you don't do this the player who uses the command's money will remain the same...
Step 3:
now, the last step:
Go to your OnPlayerCommandText callback and add this:
Code:
dcmd(pay,3,cmdtext);
and now compile your script, and it should work : )
if you get errors, please reply!
Final look:
pawn Code:
dcmd_pay(playerid,params[])
{
static ID, amount, name[MAX_PLAYERS], string7[200], name2[MAX_PLAYERS], string8[200];
if (sscanf(params, "ii", ID,amount)) return SendClientMessage(playerid, 0xff0000aa, "* Usage: /pay [playerid/name] [amount]");
if (amount > GetPlayerMoney(playerid)) return SendClientMessage(playerid, 0xff0000aa, "* You do not have enough money to pay that player!");
if (amount <= 0) return SendClientMessage(playerid, 0xff0000aa, "* You can't pay less than 1!");
if (playerid == ID) return SendClientMessage(playerid, 0xff0000aa, "* You can't pay yourselve!");
GetPlayerName(ID, name2, sizeof(name2));
format(string8,sizeof(string8),"{FFFF00}|- You have paid %s $%i -|",name2,amount);
SendClientMessageToAll(COLOR_RED,string8);
GetPlayerName(playerid, name, sizeof(name));
format(string7,sizeof(string7),"{FFFF00}* %s(%d) Has paid you: $%i",name,playerid,amount);
SendClientMessage(ID,COLOR_RED,string7);
GivePlayerMoney(ID,amount);
GivePlayerMoney(playerid,-amount);
return 1;
}
I hope I have learned you how to use commands like these: /command [something here]
in this tutorial : )
if you want to make these commands with more params just add another "i" or "d" or "u" or a different scanf param, and u can use it
Thanks!
Re: Making an easy /pay [playerid/name] [amount] system -
Wesley221 - 11.09.2011
Nice tutorial, and nice explained
Maybe add why you use 'static' instead of 'new'
And also, why do you need dini for this? You can just add the dcmd line manually, and dont really need dini for that i think?
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 11.09.2011
Quote:
Originally Posted by Wesley221
Nice tutorial, and nice explained
Maybe add why you use 'static' instead of 'new'
And also, why do you need dini for this? You can just add the dcmd line manually, and dont really need dini for that i think?
|
oh, I thought I did explain, anyways thanks I'll edit
and about that dini, I did not know at all :O lol I feel kinda dumb now
Re: Making an easy /pay [playerid/name] [amount] system -
Wesley221 - 11.09.2011
Oh excuses, you did explain static.
Quote:
statics, are almost the same as new, except that static can only be used in one command, and new in your entire script...
|
My bad
Re: Making an easy /pay [playerid/name] [amount] system -
FireCat - 11.09.2011
You could explain more tbh.
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 11.09.2011
what part should I explain more about?
Re: Making an easy /pay [playerid/name] [amount] system -
Prumpuz - 11.09.2011
Quote:
First of all, we are going to use DCMD, for that u will have to download dini.
The chance that u already have dini is pretty big, (especially if you have downloaded an admin script for your server already)
If you don't have dini yet, just look for a download link on the internet, or download LuxAdmin, it has the dini file included.
|
You don't have to download dini to have Dcmd. Searching on ****** for "sa-mp dcmd" will find it. It is on the wiki page and it's only a single define line.
Quote:
Now that you have your dini, thing u are going to add this on top of your GM:
#include <dini>
it should be under #include <a_samp>
or under your other includes that you have installed yet.
|
Where are you using dini in this tutorial, what does dini have anything to do with it?
Quote:
Next we need a define
pawn Code:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
now, I have no idea what the hell that means, I think there are only a few people who know what it means (you don't need to know what it means to make commands using DCMD...)...
anyways, this is just one define u need in your script to use dini.
|
What? Dini works fine without the Dcmd command processor.
pawn Code:
if (sscanf(params, "ii", ID,amount)) return SendClientMessage(playerid, 0xff0000aa, "* Usage: /pay [playerid/name] [amount]");
It says in the sscanf topic that "u" is used for playerid. I know that "i" works as well, but I would think that it's recommended to use "u".
pawn Code:
GetPlayerName(ID, name2, sizeof(name2));
format(string8,sizeof(string8),"{FFFF00}|- You have paid %s $%i -|",name2,amount);
SendClientMessageToAll(COLOR_RED,string8);
GetPlayerName(playerid, name, sizeof(name));
format(string7,sizeof(string7),"{FFFF00}* %s(%d) Has paid you: $%i",name,playerid,amount);
SendClientMessageToAll(COLOR_RED,string7);
Why send the messages to all players?
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 11.09.2011
yes, ok I'll remove that dini thing
and thnks for the sendclientmessagetoall thing
Re: Making an easy /pay [playerid/name] [amount] system -
Prumpuz - 11.09.2011
Ohh and by the way, your code only works as /pay [playerid], not /pay [playerid/name].
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 11.09.2011
yes, I know :/ I think changing the first i to u will change that
Re: Making an easy /pay [playerid/name] [amount] system -
Davz*|*Criss - 12.09.2011
Nice, Good tutorial Knack.
Re: Making an easy /pay [playerid/name] [amount] system -
NickTaSpy - 25.10.2011
pawn Code:
C:\Documents and Settings\Nikos\Фб ЭггсбцЬ мпх\Downloads\GTA_SA_Portable\gamemodes\Test3.pwn(3457) : error 017: undefined symbol "dcmd_pay"
C:\Documents and Settings\Nikos\Фб ЭггсбцЬ мпх\Downloads\GTA_SA_Portable\gamemodes\Test3.pwn(3461) : error 017: undefined symbol "params"
C:\Documents and Settings\Nikos\Фб ЭггсбцЬ мпх\Downloads\GTA_SA_Portable\gamemodes\Test3.pwn(3481) : warning 225: unreachable code
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Errors.
I get these errors after I place the script.(I followed all steps and then replaced with Final Look)
I have put the #include with scanf or however its called.Any ideas?Also where I have to put that thing under public OnPlayerCommandText(playerid, cmdtext[])
(I have found this line with public OnPlayer.... in my gamemode)
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 25.10.2011
Have u defined the dcmd line?
Re: Making an easy /pay [playerid/name] [amount] system -
Elka_Blazer - 25.10.2011
NICE
DDD
Re: Making an easy /pay [playerid/name] [amount] system -
Kurvits - 29.10.2011
Thats a really good tutorial. I learned alot.
I just started with scripting and that was the thing i looked for.
Sorry about my english.
Re: Making an easy /pay [playerid/name] [amount] system -
Kostas' - 03.11.2011
One suggestion.
pawn Code:
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, COLOR_RED, "[ERROR] {FFFFFF}Player is not connected!");
Because if the id isn't connected player and I use the /pay 12 5000, it GivePlayerMoney -5000.
Re: Making an easy /pay [playerid/name] [amount] system -
knackworst - 03.11.2011
Thanks for the tips!
Re: Making an easy /pay [playerid/name] [amount] system -
Kostas' - 03.11.2011
Quote:
Originally Posted by knackworst
Thanks for the tips!
|
Np!
Re: Making an easy /pay [playerid/name] [amount] system - Astralis - 19.11.2011
goodly explained. Well done . This is nice tutorial.
5/5
Re: Making an easy /pay [playerid/name] [amount] system -
stylerof619 - 19.11.2011
hey i got a Problem with this command
dcmd(pay,3,cmdtext);
it shows me this :
C:\Users\Dome\Desktop\pawnetc\gamemodes\menutest.p wn(106) : warning 225: unreachable code
C:\Users\Dome\Desktop\pawnetc\gamemodes\menutest.p wn(106) : error 017: undefined symbol "dcmd"
C:\Users\Dome\Desktop\pawnetc\gamemodes\menutest.p wn(274) : warning 203: symbol is never used: "dcmd_pay"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
i forgot the Code for the pawnquotes