PickupGuide

From SA-MP Wiki

Jump to: navigation, search

Define the pickupid

The first thing to be done when creating pickups is creating a place to store their ID. This will be done in a global variable so it can be set when you create the pickup and read when you pick up a pickup, calling a callback with the ID of the pickup you picked up. For this example we will use the name "mypickup".

new mypickup;

Creating the pickup

There are two ways to create pickups. CreatePickup and AddStaticPickup. AddStaticPickup doesn't return an ID when it is created, can't be destroyed and can only be used under OnGameModeInit, so for this example we will use CreatePickup.

The syntax for CreatePickup is:

Parameters:
(model,type,Float:X,Float:Y,Float:Z,Virtualworld)
modelThe model you'd like to use for the pickup.
typeThe pickup spawn type, see further down this page.
Float:XThe X-coordinate for the pickup to show.
Float:YThe Y-coordinate for the pickup to show.
Float:ZThe Z-coordinate for the pickup to show.
VirtualworldThe virtual world ID of the pickup. A value of -1 will cause the pickup to display in all virtual worlds.


For this example we will create a cash pickup at Grove Street.

Now we need to decide on a model to appear in the world, there are lots of models to choose from, some are listed on the wiki here, some aren't and you will need to use an editor to find the IDs, fortunately there is a specific list of common pickup models here from which we can choose model number 1274.

Finally we need a type for the pickup, on the same page with the pickup models is a list of pickup types describing what the various ones do. We want this pickup to disappear when you pick it up, so you can't pick it up repeatedly, but to reappear after a few minutes so you can pick it up again, type 2 does just this.

Pickups are most commonly created when the script starts, in OnGameModeInit or OnFilterScriptInit depending on the script type, however it can go in any function (for example you could create a weapon drop script which would use OnPlayerDeath to create weapon pickups).

So here is the code to create our pickup, and store the ID in 'mypickup':

mypickup = CreatePickup(1274, 2, 2491.7900, -1668.1653, 13.3438, -1);

Choosing what it does

When you enter a pickup, OnPlayerPickUpPickup is called, passing playerid (the player that picked up a pickup) and pickupid, the ID of the pickup that was picked up.

In here we can add code to do something with the player.

Some pickups such as health, armour and weapons are internally coded to work automatically, so there is no need to do anything under OnPlayerPickUpPickup.

When a player picks up our new pickup, we want to give them $100, to do this first we need to check that they have picked up our dollar pickup and not a different one. When we've done that, we can give them the $100:

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == mypickup) // Check that the pickup ID of the pickup they picked up is mypickup
    {
        // It is
        SendClientMessage(playerid, 0xFFFFFFFF, "You received $100!"); // Message the player
        GivePlayerMoney(playerid, 100); // Give the player the money
    }
    // if you need to add more pickups, simply do this:
    else if (pickupid == (some other pickup))
    {
        // Another pickup, do something else
    }
    return 1;
}

Congratulations, you now know how to create and handle pickups!

Personal tools
Navigation
Toolbox
In other languages