-MAS SPECIAL - GIFTS CREATING |TUTORIAL|

Hello all,

so i'm back after a long ban! And i'll start with a simple tutorial! So, as christmas is near, everyone is wanting to add some christmas gifts around the cities to enhance their servers. So, it is easy, and NOT difficult at all! Without waiting, let's start the tutorial!

STEP 1 - Gifts Variable

So, we should create variables for the pickups.(Gifts)

PHP Code:
new gifts[1];
if you want to add more gifts, continue increasing the number which is currently 1.

STEP 2 - Adding Forwards For Functions

We are now going to use some public functions. Explications of the forwarded function will be done later.

For now, here we go.

PHP Code:
forward GiftReload();
forward RGift();
STEP 3 - Creating Gifts

Now that we have all the variables, we will now CREATE the gifts. (Pickup)
The gifts should be created OnGameModeInit because OnGameModeInit gets called when the server is started. And so, this is what we need! We need to create the gifts when the server starts.

Here we go.

PHP Code:
public OnGameModeInit()
{
gifts[1] = CreatePickup(19057, 2, 1363.6558,-1581.9050,8.6422, -1);
SetTimer("GiftReload", 60000, true);
return 1;
}
The reason why i have set the timer is that, because we need to reload the gifts EVERY 1 minutes! The reason why i didn't create it again when the player have picked up the gifts is the player can stands there and become a billionaire in minutes! (Abuse)

STEP 3 - Rewarding

Now, we need to give him the reward when he enters the gifts. So, the code is below!

PHP Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
new str[128], pN[MAX_PLAYER_NAME];
GetPlayerName(playerid, pN, sizeof(pN));
if(pickupid == gifts[1])
{
format(str, sizeof(str), "%s has found a gift!", pN);
SendClientMessageToAll(0xFF0000FF, str);
SendClientMessage(playerid, 0xFF0000FF, "You have found a gift! You receive 1 score and $10,000!");
GivePlayerMoney(playerid, 10000);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
DestroyPickup(g1);
}
return 1;
}
Now we are going to split this code a bit.

PHP Code:
new str[128], pN[MAX_PLAYER_NAME];
In this code we are defining the string which we will be using later and you'll notice pN[MAX_PLAYER_NAME]. This is for storing the player's name.
PHP Code:
GetPlayerName(playerid, pN, sizeof(pN));
Getting the player's name who has got the gift.

PHP Code:
if(pickupid == g1)
{
Here we are checking which pickup he picked up. And if he picked up one of the gifts then it continues.

PHP Code:
format(str, sizeof(str), "%s has found a gift!", pN);
SendClientMessageToAll(0xFF0000FF, str);
Formatting the message to all players that a player has got the gift.

PHP Code:
SendClientMessage(playerid, 0xFF0000FF, "You have found a gift! You receive 1 score and $10,000!");
Notifying the player what he received as reward.

PHP Code:
GivePlayerMoney(playerid, 10000);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
Giving him $10,000 & 1 scores. (You can change it to your rewards)

|-----ADDITIONAL NOTES-----|
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
Why did i use GetPlayerScore in SetPlayerScore?
-Reason is, if we don't use it, then it will set the player's score to
1 removing all of his scores and by using GetPlayerScore we check how much
scores her have and then adding 1 score.
|-------------------------------|
[/FONT]

PHP Code:
DestroyPickup(gifts[1]);
}
Here we destroys the pickup for no abuses and then close the braces!

STEP 4 - Reloading Gifts

And now we are going to reload the gifts!

Refer to STEP 3 for the timer added on OnGameModeInit for the gifts reloading!

PHP Code:
public GiftReload()
{
DestroyPickup(gifts[1]);
SetTimer("RGift", 1000, false);
return 1;
}
Here we destroys the current gift

PHP Code:
public RGift(){
gifts[1] = CreatePickup(19057, 2, 1363.6558,-1581.9050,8.6422, -1);
}
Now, we re-create the gifts.


STEP 5 - EXTRA COMMAND

So, if you want to make a command for admins to reload the gifts, so it's simple! Here you go.

PHP Code:
CMD:rgifts(playerid,params[]){
if(!IsPlayerAdmin(playerid)) return 0; // Checks if he is RCON logged in - Add your admin params
SendClientMessage(playerid, 0xFF0000FF, "You have re-spawned all X-MAS gifts around LS!"); // Self Explanatory
SetTimer("GiftReload", 1000, false); // Sets a 1 second timer to respawn all the gifts (Check STEP 4 for gift reloading)
return 1;
}

NOTE: TO DESTROY ALL THE GIFTS, YOU COULD SIMPLY USE A LOOP AS FOLLOWS!

PHP Code:
#define MAX_GIFTS 2

new gifts[MAX_GIFTS];

for( new i = 0 ; i < MAX_GIFTS ; i ++){
DestroyPickup(gifts[i]);
}