Mysql database
#1

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?
Reply
#2

Hello.
Add this in your mysql database
PHP код:
pUsedgift 
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

Reply
#3

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 .... 
??
Reply
#4

By returning a value in an if statement (and anywhere else in a function really), you:
  1. terminate the function that the if-statement is in (when the if-statement is executed);
  2. 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.
Reply
#5

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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)