[Tutorial] How to make a pickup item!
#1

What are pickups?

Pickups are 3D models that can be created and loaded into your world using a couple of script lines that will be explained below.

What can I use pickups for?
Everything! Pickups can be used to spawn cars, show and hide textdraws, teleport players, kill yourself, ban yourself, almost anything!

We will go through the steps of creating a simple healing pickup, although you can do much more.

Step 1: Open pawno.exe, you should know how to use it by now, if you don't please read this article to help you understand what is going on here: PAWN for Beginners.

Step 2: We should begin by defining the pickup, which is done by adding a
Code:
new PickUpNameHere;
this should the very first thing you should do.

Step 3: You should now make up your mind, do you want your pickup to appear to everyone once the server is loaded? Or do you want it to spawn on a special occasion? In this tutorial, I'll be making this pickup available once the server is loaded.

Step 4: We will be using the
Code:
CreatePickup
function in this tutorial.

Begin by defining the pickup, as explained above.
Code:
new HealthPickup;
After this is done, navigate to
Code:
public OnGameModeInit() // Remember, I used this because I want the pickup to appear for everyone from the start.
And create your pickup, you should use the
Code:
CreatePickup
function in the following way;
Code:
HealthPickup = CreatePickup(PickupObject,PickupType,PickupPosX,PickupPosY,PickupPos:Z,Virtualworld);
We will be creating a health pickup that will respawn after some time, so people cannot exploit it for infinite health, or camp on it.

There are many kinds of types, but some of the most used are:
Code:
0The pickup does not always display. If displayed, it can't be picked up and does not trigger OnPlayerPickUpPickup and it will stay after server shutdown.
1 Exists always. Disables pickup scripts such as horseshoes and oysters to allow for scripted actions ONLY. Will trigger OnPlayerPickUpPickup every few seconds.
2 Disappears after pickup, respawns after 30 seconds if the player is at a distance of at least 15 meters.
3 Disappears after pickup, respawns after death.
4 Disappears after 15 to 20 seconds. Respawns after death.
8 Disappears after pickup, but has no effect.
11 Blows up a few seconds after being created (bombs?)
12 Blows up a few seconds after being created.
13 Invisible. Triggers checkpoint sound when picked up with a vehicle, but doesn't trigger OnPlayerPickUpPickup.
14 Disappears after pickup, can only be picked up with a vehicle. Triggers checkpoint sound.
15 Same as type 2.
18 Similar to type 1. Pressing Tab (KEY_ACTION) makes it disappear but the key press doesn't trigger OnPlayerPickUpPickup.
19 Disappears after pickup, but doesn't respawn. Makes "cash pickup" sound if picked up.
20 Similar to type 1. Disappears when you take a picture of it with the Camera weapon, which triggers "Snapshot # out of 0" message. Taking a picture doesn't trigger OnPlayerPickUpPickup.
22 Same as type 3.
We will be using the "heart" object, you can use whatever object you prefer, all of them can be found here.
https://sampwiki.blast.hk/wiki/Objects
Code:
HealthPickup = CreatePickup(1240,2,0,0,0,0); // The pickup will spawn at blueberry, which is the middle of the map.
Step 6: Now that we have successfully created the pickup, we will make it actually do something once a player touches it.

We will be using the callback
Code:
public OnPlayerPickUpPickup(playerid, pickupid)
in this part of the tutorial. OnPlayerPickUpPickup is executed once any player touches a pickup around the world, without this, the entire created pickups are considered useless.

We will now make the pickup heal the player to a hundred percent, the pickup will still disappear if someone has full health, but this can be fixed by checking if he has full health or not.

Code:
    
if(pickupid == HealthPickup) // The callback will check if the pickup that was touched by a player is the one we made, if it's not, it will continue searching for the correct one.
    {
        SetPlayerHealth(playerid, 100); // We will set the player's health to 100 out of 100, which is the maximum health your HUD can show.
    }
Step 7: We are done, press the magical compile button and let your pawno.exe do the rest.

This just one of the infinite things you can do with pickups, enjoy!


Thanks for reading the guide, I hope it was less derpy and stupid than the last one.
Reply


Messages In This Thread
How to make a pickup item! - by Cena44 - 26.06.2012, 06:32
Re: How to make a pickup item! - by Vinninho - 27.12.2012, 07:25
Re: How to make a pickup item! - by Cena44 - 04.05.2014, 13:40
Re: How to make a pickup item! - by Aerotactics - 04.05.2014, 17:14

Forum Jump:


Users browsing this thread: 1 Guest(s)