23.12.2015, 12:54
(
Last edited by Karan007; 24/12/2015 at 12:53 PM.
)
X-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];
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;
}
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;
}
PHP Code:
new str[128], pN[MAX_PLAYER_NAME];
PHP Code:
GetPlayerName(playerid, pN, sizeof(pN));
PHP Code:
if(pickupid == g1)
{
PHP Code:
format(str, sizeof(str), "%s has found a gift!", pN);
SendClientMessageToAll(0xFF0000FF, str);
PHP Code:
SendClientMessage(playerid, 0xFF0000FF, "You have found a gift! You receive 1 score and $10,000!");
PHP Code:
GivePlayerMoney(playerid, 10000);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
|-----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]);
}
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;
}
PHP Code:
public RGift(){
gifts[1] = CreatePickup(19057, 2, 1363.6558,-1581.9050,8.6422, -1);
}
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;
}
PHP Code:
#define MAX_GIFTS 2
new gifts[MAX_GIFTS];
for( new i = 0 ; i < MAX_GIFTS ; i ++){
DestroyPickup(gifts[i]);
}
Karan007 - Wrote this tutorial/scripted the code.
SA-MP Team - Created SA-MP.
Jimmy0wns & Zeus - For pointing out some suggestions.
Enjoy