[Tutorial] Simple Pickup
#1

We begin by opening a brand new pawno window, and opening the script of your choosing. This is a very easy function to do in pawn, but can be very helpful in game, for all kinds of gamemodes. With pickups, you can make them show a player text, or even teleport the player, all up to you, the scripter. Let us begin:

Step one:
Now that we have opened our Pawno window, and opened our script, press CTRL+F, and look search for:
pawn Code:
public OnGameModeInit()
In this is everything that you want to load when your gamemode starts, or initiates. Now we begin the coding, we want to create a new pickup:

Step Two:
Inside of the public function type this:

CreatePickup(pickupmodel, pickuptype, coordx, coordy, coordz, virtualworld);

Now you must change the pickupmodel, pickuptype, coordx, coordy, coordz, and virtualworld to your choosing, here is a example:
pawn Code:
CreatePickup(1318, 23, 0, 0, 0, 0);
If you don't know the virtual world, keep it at 0... To get the right model and type, click on the pickuptype and pickupmodel and it will take you to a link.

Now we have created a pickup, but we have not distinguished this pickup from any other... So if we want to give this pickup a function, we can't, at this time. So to make this pickup special, we give it a name, to do so go to where you created it, and before the
pawn Code:
CreatePickup
add this:
pawn Code:
new pickupname =
So it would look something like this:
pawn Code:
new pickupone = CreatePickup(1318, 23, 0, 0, 0, 0);
Now our script understands that pickupone, is the one it created.

Step Three:
Now we want to make our pickup do a special task, when the player picks it up, so now press CTRL+F again, and search for:
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
Now type this inside of it:
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickupone)
    {
        SendClientMessage(playerid, COLOR_WHITE, "You picked me up!");
        return 1;
    }
    return 1;
}
Now when our player picks up the this pickup we named pickupone, it will send him the message we put... But we can also make it teleport them or even kill them, here are some examples of what you can do:

Kill or set their health:
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickupone)
    {
        SetPlayerHealth(playerid, 0);
        return 1;
    }
    return 1;
}
Teleport them:
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickupone)
    {
        SetPlayerPos(playerid, 1, 1, 1);
        return 1;
    }
    return 1;
}
Give them a weapon:
pawn Code:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickupone)
    {
        GivePlayerWeapon(playerid, 24, 9999);
        return 1;
    }
    return 1;
}
Overall you can see how this can be quite a useful part of your scripting. With this you can have many possibilities and make many different outcomes come true, good luck with your scripting, and have fun!
Reply
#2

WoW nice
Reply
#3

Thank you for your comment
Reply
#4

thanks malco for help players i like helpers like you and good luck for your others tuto and fs thanks
Reply
#5

Nice tutorial. Good for newbies like me. Thanks a lot !
Reply
#6

That's really hard man, thank for the tutorial ................

No no, just joking nice [TuT]. I think is nice explained

---Sozz for Bad eng ---
Reply
#7

Good tutorial
Reply
#8

Thank you all very much for the nice feedback.
Reply
#9

How to destroy pickups and let them respawn after 5 minutes?
Reply
#10

Well you need two things to destroy and make it respawn in 5 minutes:
pawn Code:
SetTimerEx("PickupRespawn", 300000, false);
and
pawn Code:
DestroyPickup(pickupone);
So something like this:
pawn Code:
forward PickupRespawn;

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickupone)
    {
        DestroyPickup(pickupone);
        SendClientMessage(playerid, COLOR_WHITE, "You picked me up!");
        SetTimerEx("PickupRespawn", 300000, false);
        return 1;
    }
    return 1;
}

public PickupRespawn()
{
    pickupone = CreatePickup(1318, 23, 0, 0, 0, 0);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)