Mysql database - 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)
+--- Thread: Mysql database (
/showthread.php?tid=621840)
Mysql database -
PepsiCola23 - 15.11.2016
Hello guys,i came back and i started to script again but i kinda forgot something.
So i got some cmd like /getgift that players can get after 50 hours on server.
I made the function that counts the hours,everything is ok.
I make a progressbar to show how much you have til` you can /getgift,but how can i check if the player already used the CMD? so they cant use the cmd over and over after they reached 50 level.
i Though about making a new column in mysql with Gift and 2 options Yes/No
and when the player connects,a function checks if the player didnt use the cmd,and then it shows him the progress bar.......or,if he already used it [ yes on mysql database] it doesnt show it to him.
how can i make this ? any ideas?
Re: Mysql database -
Pearson - 15.11.2016
Hello.
Add this in your mysql database
Then add this in your playerdata enum something like this
PHP код:
enum PlayerInfo
{
pUsedgift
}
Then create function which get data from sql.
Then add this in head of cmd.
PHP код:
if(PlayerInfo[playerid][pGiftused] != 1)
{
//YOUR CODE
}
Re: Mysql database -
PepsiCola23 - 15.11.2016
ok i did this but it works,but what is the difference between
PHP код:
if(PlayerInfo[playerid][pGiftused] != 1) return ..... code
and
PHP код:
if(PlayerInfo[playerid][pGiftused] == 1) return ....
??
Re: Mysql database -
AndySedeyn - 15.11.2016
By returning a value in an if statement (and anywhere else in a function really), you:
- terminate the function that the if-statement is in (when the if-statement is executed);
- can treat everything outside that if statement as the else statement; i.e:
PHP код:
someFunction() {
if(someCondition)
// Terminate the function
return true;
// code under this is ONLY executed when that if statement evaluates to false, thus it can be considered the 'else' statement for that if statement.
return false;
}
One could debate that, if the return value in the if statement is the same as the function's end return value, then the else statement should be used:
PHP код:
someFunction() {
if(someCondition)
// Terminate the function
return true;
// code
return true; // return value is true which is the same as in the if block
}
PHP код:
someFunction() {
if(someCondition) {
// code
}
else {
// code
}
return true;
}
I think that's what you meant.
Re: Mysql database -
AjaxM - 16.11.2016
Quote:
Originally Posted by PepsiCola23
ok i did this but it works,but what is the difference between
PHP код:
if(PlayerInfo[playerid][pGiftused] != 1) return ..... code
and
PHP код:
if(PlayerInfo[playerid][pGiftused] == 1) return ....
??
|
PHP код:
if(PlayerInfo[playerid][pGiftused] != 1) return ...
This code means: If the the player's pGiftused value is
NOT 1 then it will return ...
PHP код:
if(PlayerInfo[playerid][pGiftused] == 1) return ....
This code means: If the player's pGiftused value is
equal to 1 then it will return ....
That's all!