[Tutorial] Creating Gifts SA [X-MAS SPECIAL]
#1

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]; 
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(1905721363.6558,-1581.9050,8.6422, -1);
    
SetTimer("GiftReload"60000true);
    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(playeridpickupid)
{
    new 
str[128], pN[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNsizeof(pN));
    if(
pickupid == gifts[1])
    {
        
format(strsizeof(str), "%s has found a gift!"pN);
        
SendClientMessageToAll(0xFF0000FFstr);
        
SendClientMessage(playerid0xFF0000FF"You have found a gift! You receive 1 score and $10,000!");
        
GivePlayerMoney(playerid10000);
        
SetPlayerScore(playeridGetPlayerScore(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(playeridpNsizeof(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(strsizeof(str), "%s has found a gift!"pN);
SendClientMessageToAll(0xFF0000FFstr); 
Formatting the message to all players that a player has got the gift.

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

PHP Code:
GivePlayerMoney(playerid10000);
SetPlayerScore(playeridGetPlayerScore(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"1000false);
    return 
1;

Here we destroys the current gift

PHP Code:
public RGift(){
    
gifts[1] = CreatePickup(1905721363.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(playerid0xFF0000FF"You have re-spawned all X-MAS gifts around LS!"); // Self Explanatory
    
SetTimer("GiftReload"1000false); // 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 
MAX_GIFTS ++){
    
DestroyPickup(gifts[i]);

Credits

Karan007 - Wrote this tutorial/scripted the code.
SA-MP Team - Created SA-MP.
Jimmy0wns & Zeus - For pointing out some suggestions.

Enjoy
Reply
#2

Not bad, well done.
Reply
#3

Quote:

if you want to add more gifts, continue with the same pattern

Example:
new g2;
new g3;

I would say that this could be done way easier, variable wise it could be done like this:
PHP Code:
new gift[3]; 
which would give you 3 (or 4, can't remember) variables to work with.

None of the less, the tutorial is semi-decent. This is because you're using a font that is quite hard to read for my eyes and so was the color you used. Be sure to explain the functions better next time and try to leave the markup alone, using bold and italic text in some cases can be enough.
Reply
#4

Good tutorial but why not add new gifts[20];? Than

new gift1;
new gift2;
.
.
.
.
new gift19;



Also add in the tutorial that what is "forward". It basically " defined" your new custom "public" callback.

If I'm not wrong, you are respawning the gift after 1 second after destroying it?
Wrong method I think, a player can camp there and abuse till next christmas (LOL, fail attempt to be funny).
Make a player variable and set it to 1 when a player picks up a gift and have a 15 mins cool down before setting it back to 0. I.e player can take the gift.

Nice explanation.
Anyways, welcome back and prefer to write in the default black color, this blue color burns my eyes.
+rep for your efforts and once more, welcome back


Edit: lol jimmyowns ^. It took me time to write, was writing wayy before you :P
Reply
#5

Good job mate.
Reply
#6

Quote:
Originally Posted by [ND]xXZeusXx.
View Post
Wrong method I think, a player can camp there and abuse till next christmas (LOL, fail attempt to be funny).
Indeed. Based on the fact that the position is not random. If that were the case the player would still have to search/travel to the new location.
Reply
#7

Thank you all! Added some of the suggestions.
Reply
#8

"Zeus" Not "Zues" btw. (Credits).

You should also consider my other suggestion, or as Vince said make the positions random within the san andreas.
Reply
#9

Welcome back and, good job.
Reply
#10

@ Zeus: Corrected your name to "Zeus".

@ Vince: This is just a basic one which is just perfect for newbies. I'll look forward to make a random locations based x-mas gifts.

@ Pawnhunter: Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)