SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 23/12/2015, 12:54 PM   #1
Karan007
Gangsta
 
Karan007's Avatar
 
Join Date: Feb 2015
Posts: 539
Reputation: 67
Default Creating Gifts SA [X-MAS SPECIAL]

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

Last edited by Karan007; 24/12/2015 at 12:53 PM.
Karan007 is offline   Reply With Quote
Old 23/12/2015, 01:03 PM   #2
MartinSwag
Little Clucker
 
MartinSwag's Avatar
 
Join Date: Aug 2015
Location: The Netherlands
Posts: 40
Reputation: 2
Default Re: Creating Gifts SA [X-MAS SPECIAL]

Not bad, well done.
MartinSwag is offline   Reply With Quote
Old 23/12/2015, 01:17 PM   #3
Jimmy0wns
Gangsta
 
Join Date: Sep 2012
Location: Netherlands
Posts: 686
Reputation: 208
Default Re: Creating Gifts SA [X-MAS SPECIAL]

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.
Jimmy0wns is offline   Reply With Quote
Old 23/12/2015, 01:18 PM   #4
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,547
Reputation: 170
Default Re: Creating Gifts SA [X-MAS SPECIAL]

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
__________________
Ritzy2K is offline   Reply With Quote
Old 23/12/2015, 01:20 PM   #5
[UE]Milan
High-roller
 
[UE]Milan's Avatar
 
Join Date: Jan 2012
Location: Right in front of forum.sa-mp.com
Posts: 1,208
Reputation: 160
Default Re: Creating Gifts SA [X-MAS SPECIAL]

Good job mate.
[UE]Milan is offline   Reply With Quote
Old 23/12/2015, 06:07 PM   #6
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Creating Gifts SA [X-MAS SPECIAL]

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.
__________________
Vince is offline   Reply With Quote
Old 24/12/2015, 08:24 AM   #7
Karan007
Gangsta
 
Karan007's Avatar
 
Join Date: Feb 2015
Posts: 539
Reputation: 67
Default Re: Creating Gifts SA [X-MAS SPECIAL]

Thank you all! Added some of the suggestions.
Karan007 is offline   Reply With Quote
Old 24/12/2015, 09:14 AM   #8
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,547
Reputation: 170
Default Re: Creating Gifts SA [X-MAS SPECIAL]

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

You should also consider my other suggestion, or as Vince said make the positions random within the san andreas.
__________________
Ritzy2K is offline   Reply With Quote
Old 25/12/2015, 04:10 AM   #9
iKarim
Banned
 
Join Date: Oct 2015
Posts: 579
Reputation: 142
Default Re: Creating Gifts SA [X-MAS SPECIAL]

Welcome back and, good job.
iKarim is offline   Reply With Quote
Old 25/12/2015, 03:27 PM   #10
Karan007
Gangsta
 
Karan007's Avatar
 
Join Date: Feb 2015
Posts: 539
Reputation: 67
Default Re: Creating Gifts SA [X-MAS SPECIAL]

@ 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
Karan007 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What gifts did you get? Saurik Everything and Nothing 28 07/01/2015 08:48 AM
Special Steam Gifts (Free games to win) Dripac Everything and Nothing 10 21/12/2011 10:35 PM
Gifts! Dr_Killer_23 Help Archive 3 16/11/2009 07:45 PM


All times are GMT. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.