PickupGuide

From SA-MP Wiki

Revision as of 00:51, 16 October 2009; view current revision
←Older revision | Newer revision→
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;
Important note: PickupIDs are bugged in 0.2X. This issue is fixed in 0.3 versions and above


Creating the pickup

There are two ways to create pickups: CreatePickup and AddStaticPickup, AddStaticPickup doesn't return an ID, can't be destroyed and can only be used under OnGamgModeInit, 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 ID you'd like 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 an awful lot 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 ot up, so you can't pick it up repeatedly, but to reappear after a few minutes so you can use it again, i.e. we want pickup type 2.

The code for creating pickups often goes 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 pickups based on a dead player's weapons). The final code is:

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 who picked up a pickup) and pickupid (The pickup ID). In here we can add code to do something with the player, note that some pickups, for example weapon and health pickups, work automatically.

When a player picks up our new pickup we want to give them $10000, to do this first we need to check that they've pickup up the correct pickup, not just any pickup, then if they have give them the money:

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 $10000!"); // Message the player
        GivePlayerMoney(playerid, 10000); // Give the player the money
    }
    else if (pickupid == (some other pickup))
    {
        // Another pickup, do something else
    }
    return 1;
}