[Tutorial] How To Make A Simple Pickup
#1

How To Make A Simple Pickup


Hello guys, today I will be showing you how to make a simple pickup

First, your going to want to define the include 'a_samp' at the top of your script, this include gets to access functions like SendClientMessage, SendClientMessageToAll, SetWeather, SetWorldTime, SetTimer, SetTimerEx, all those functions that are in 'a_samp' include.

pawn Code:
#include <a_samp>
Next, we're going to want to define the pickup's name.
Place this maybe at the bottom of your color defines as I recommend.
pawn Code:
new pickup; // You can change the word 'pickup' to a different name, but don't remove the ';', it's very important.
Now, we will have to create a armor pickup.
Place this code in 'OnGameModeInit'.

pawn Code:
public OnGameModeInit()
{
    pickup = CreatePickup(1242, 2, 1930.9042,-1776.4119,13.5469, 0);
    return 1;
}
Okay, so this code, pickup = CreatePickup(1242, 2, 1930.9042,-1776.4119,13.5469, 0);
basically means to create a pickup, with a armor model, and the '2', is the type of the pickup, this '2' type of pickup is pickupable, but it will respawn after some time.The 3rd parameter to the 5th parameter is the X, Y, Z position, the postion the pickup will spawn.After the last parameter is the virtual world, the pickup will only be in virtual world 0.


You can see the types of models here.

Types of pickups:
Code:
0 - The pickup does not display.
1 - Not pickupable, exists all the time. (Suitable for completely scripted pickups using OnPlayerPickUpPickup)
2 - Pickupable, respawns after some time.
3 - Pickupable, respawns after death
4 - Disappears shortly after created (perhaps for weapon drops?)
5 - Disappears shortly after created (perhaps for weapon drops?)
8 - Pickupable, but has no effect. Disappears automatically.
11 - Blows up a few seconds after being created (bombs?)
12 - Blows up a few seconds after being created.
13 - Slowly decends to the ground.
14 - Pickupable, but only when in a vehicle.
15 - Pickupable, respawns after death
19 - Pickupable, but has no effect (information icons?)
22 - Pickupable, respawns after death.
23 - Pickupable, but doesn't disappear on pickup.
_____________________________________________
Refer here: PickupTypes
Parameters for the function, 'CreatePickup'
Code:
CreatePickup(model, type, Float:X, Float:Y, Float:Z, Virtualworld);
Next, we will have to add what happens when they pickup the pickup.
Which we will use a callback called 'OnPlayerPickUpPickup'.
If you have trouble finding that callback in your script, do as the following:
Press CTRL+F, a box will pop up, type in the blank 'OnPlayerPickUpPickup', click 'OK', and it will direct you to the callback, 'OnPlayerPickUpPickup'

pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickup)
    {
        SetPlayerArmour(playerid, 100);
        GameTextForPlayer(playerid, "ARMOR REFILLED!", 3000, 6);
    }
    return 1;
}
So, this code basically means if the player pickups a pickup named 'pickup' which is the armor pickup we've created in the callback 'OnGameModeInit', it will set the player's armor to 100 percent, and a game text will pop up on the player's screen saying 'ARMOR REFILLED!' for 3000 seconds, in milliseconds. But it is acutally 3 seconds, and the '6' is the style of the text.
You can refer here for GameTextStyles


Final Code:
pawn Code:
#include <a_samp>

new pickup; // You can change the word 'pickup' to a different name, but don't remove the ';', it's very important.

public OnGameModeInit()
{
    pickup = CreatePickup(1242, 2, 1930.9042,-1776.4119,13.5469, 0);
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickup)
    {
        SetPlayerArmour(playerid, 100);
        GameTextForPlayer(playerid, "ARMOR REFILLED!", 3000, 6);
    }
    return 1;
}
That's pretty much it guys, a how to make a simple pickup tutorial.
Reply
#2

Thank you very much it really helped me Rep +
Reply
#3

Quote:
Originally Posted by Mr.Faqahat
View Post
Thank you very much it really helped me Rep +
Thanks for the feed back, and I'm glad it helped you in scripting. Keep Learning.
Reply
#4

Nice Tutorial
Reply
#5

Ok I did this now how do I actually add it to the game?
Reply
#6

Nice one.. Helped me out alot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)