unstunting

Off Topic => Scripting Discussion => Topic started by: Marsigne on May 19, 2012, 11:00:08 pm


Title: How to make a score system [1 score every minute]
Post by: Marsigne on May 19, 2012, 11:00:08 pm
First step

In the first step I will show how to create a global variable that will control (and will be needed) the constants and the timer.
Now we will add this at the top of the script. Warning: must be on top of script but not above a_samp!! or else will give error. why on the top of the script? to make it a GLOBAL variable.

Code: [Select]
new GiveScoreTimer[MAX_PLAYERS];
with this new global variable we will control the score timer. the [MAX_PLAYERS] consist that will be to entire players (in other words, up to max players)
Warning: The new global variable must be at the end with the ; (semi colon). why? it is self explanatory, it is like the sentence. it finish the lines, or else it wont finish and will ruin an error.

Second step

In the second step I will show how to convert a variable to a timer and explain the functions.

Code: [Select]
GiveScoreTimer[playerid] = SetTimerEx ("GivePlayerScore", 1000*60, true, "d", playerid);
Now we converted the variable into a timer. I will explain the steps.

Code: [Select]
GiveScoreTimer[playerid]
The GiveScoreTimer is the variable, but you say, why playerid there?  well, playerid is for the player, but this works DEPENDING on where you put it to work. We will show later where will be put.

Code: [Select]
SetTimerEx ("GivePlayerScore", 1000*60, true, "d", playerid);
This is the converted timer. "GivePlayerScore" tells which variable will be used for the timer. the 1000*60 is 1000 x 60 = 60,000 that is 60 seconds in decimal. "true" is self explanatory. and playerid is for the player DEPENDING where you put it.

Third step

In the third step I will show where to put it and WHY put it there. As i said before, the playerid works DEPENDING on where you put it, now I will show you where to put it. Why to put it there? because there will work the playerid FOR all players.

Code: [Select]
public OnPlayerConnect(playerid)
{
    return 1;
}

Here you will put your converted timer so once the player connects the timer will run FOR the player (playerid). Now understand why playerid here, right? Now, we will do this....

Code: [Select]
public OnPlayerConnect(playerid)
{
    GiveScoreTimer[playerid] = SetTimerEx ("GivePlayerScore", 1000*60, true, "d", playerid);
    return 1;
}

Yes, put the converted timer above the return 1;. why? self explanatory, must be the timer before the public constant returns. if you put it after the return, it will return, THEN it will do the timer, so, it will be nothing.

Fourth step

In the fourth step I will show how to stop the timer once the player disconnects.
Now you will ask, but? when the timer stops? I tell you, It won't stop! But don't die, this can be fixed with just 1 constant!
go to here...

Code: [Select]
public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

Here is the part when the player disconnect. Now you say, How I stop it? Which constant? Wait, let me talk, I will do it just right now.

Code: [Select]
KillTimer(GiveScoreTimer[playerid]);
This constant is to "Kill" the timer, in other words, it stop the timer.
Now, We will do this...

Code: [Select]
public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(GiveScoreTimer[playerid]);
    return 1;
}

As I told before, it must be above the return, so it can return.

Fifth step

In the fourth step I will show to do a "score" in each minute. and of course, where.
Now you say, but... What will give me once a minute? Nothing? Wait, let me do the last step, to do the function to do a "score" every minute as I set it up on the timer.

Now in this part, we will do a forward, because we will make a custom function.
Let's go up all the script and put this....

Code: [Select]
forward GivePlayerScore(playerid);
Here this function will forward the public function. after you do this, as this is a public function, you can put this everywhere you put it DOWN (of course) the global variable and the a_samp. Here it is the code...

Code: [Select]
public GivePlayerScore(playerid)
{
    return 1;
}

Here we created the public function. Now here will set up the player score every minute as set up on the timer.

Now we will do this....

Code: [Select]
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
Now I will explain these steps.

Code: [Select]
SetPlayerScore
Here we "set" the player score to something... Let's follow...

Code: [Select]
(playerid, GetPlayerScore(playerid) + 1)
The playerid, of course, is to give the score to the player. and GetPlayerScore(playerid) + 1 is to give +1 score to the player.

Conclusion:
Nice tutorial, huh? Here I showed you how to create a score system. You can comment, You can suggest me to do other scripts, and I will do others too!
Title: Re: How to make a score system [1 score every minute]
Post by: мυ∂υℓ_вacнα on May 20, 2012, 12:51:34 am
Hmmm realy good but i need the whole script as pastabin or pawno ?
Title: Re: How to make a score system [1 score every minute]
Post by: Marsigne on May 20, 2012, 11:54:56 pm
Hmmm realy good but i need the whole script as pastabin or pawno ?
Does your server have an score system?
Title: Re: How to make a score system [1 score every minute]
Post by: мυ∂υℓ_вacнα on May 21, 2012, 10:47:41 am
Hmmm realy good but i need the whole script as pastabin or pawno ?
Does your server have an score system?
Of course it hasss ....
Title: Re: How to make a score system [1 score every minute]
Post by: Gamer on May 28, 2012, 04:00:38 am
Who are Owner's?
Title: Re: How to make a score system [1 score every minute]
Post by: Marsigne on May 30, 2012, 09:38:11 pm
Who are Owner's?
Owner of what?
Title: Re: How to make a score system [1 score every minute]
Post by: мυ∂υℓ_вacнα on February 24, 2013, 01:59:25 am
+1 ... + this will be added i think