14.12.2018, 18:20
Okay, I'm assuming that you are using newest version of MySQL plugin and you have created connection to your database.
To start off, let's define our dialog id:
Then we need to put our dialog into OnPlayerConnect(or anywhere where you want it).
Next, let's handle the dialog response.
Don't forget to replace YOUR_MYSQL_HANDLE with handle that you're using to connect to your database and `table_name` with your table name!
And to end this simple script, create function that checks if that name is valid, and if it is add 1 to `Referrals` column.
To start off, let's define our dialog id:
Код:
#define DIALOG_ID_REFERRAL_CHECK 2137
Код:
public OnPlayerConnect(playerid) {
ShowPlayerDialog(playerid, DIALOG_ID_REFERRAL_CHECK, DIALOG_STYLE_INPUT,"Referral system", "If someone invited you to this server, input his name below", "OK", "Cancel");
//your code here
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
switch(dialogid)
{
case DIALOG_ID_REFERRAL_CHECK:
{
if(!response) {
//here you can put code that will execute when player clicks "Cancel" - the right button;
return 1;
}
else {
//you can add if's checking if user input is empty etc.
new Query[128];
mysql_format(YOUR_MYSQL_HANDLE, Query, sizeof Query,"SELECT * FROM `table_name` WHERE `Username` = '%e'", inputtext);
mysql_tquery(YOUR_MYSQL_HANDLE, Query, "OnReferralNameCheck", playerid, inputtext);
}
}
}
}
And to end this simple script, create function that checks if that name is valid, and if it is add 1 to `Referrals` column.
Код:
forward OnReferralNameCheck(playerid, const name[]);
public OnReferralNameCheck(playerid, const name[])
{
if(cache_num_rows()) {
//user has put right name
new Query[128];
mysql_format(YOUR_MYSQL_HANDLE, Query, sizeof Query,"UPDATE `table_name` SET `Referrals` = `Referrals` + 1 WHERE `Username` = '%e'", name);
mysql_tquery(YOUR_MYSQL_HANDLE, Query);
}
else {
//user has put wrong name
SendClientMessage(playerid, -1, "This user doesn't exist!");
ShowPlayerDialog(playerid, DIALOG_ID_REFERRAL_CHECK, DIALOG_STYLE_INPUT,"Referral system", "If someone invited you here, input his name below", "OK", "Cancel");
}
cache_unset_active();
}

