[Tutorial] How to make Repair and Nos pickups.
#1

Hey, this is going to be my first tutorial on this forum so don't be harsh!
This tutorial is made for newbies.
In this tutorial i will show you readers how to make Repair & Nos pickups for cars.




pawn Код:
#define filterscript
#include <a_samp>
new repairpickup, nospickup;
Add this first of all.
repairpickup and nospickup is what we will call our pickups.


pawn Код:
public OnFilterScriptInit()
{
    print("Pickup FS");
    respawnnos();
    respawnrepair();
    return 1;

}
This will print Pickup FS in the serverconsole, and spawn the pickups.


pawn Код:
public OnFilterScriptExit()
{
    DestroyPickup(nospickup);
    DestroyPickup(repairpickup);
    return 1;
}
This will destroy the pickups when you unload your filterscript.


pawn Код:
forward respawnnos();
public respawnnos()
{
    nospickup = CreatePickup(1009,14,X,Y,Z,-1);//NOS
}

forward respawnrepair();
public respawnrepair()
{
    repairpickup = CreatePickup(1240,14,X,Y,Z,-1);//Repair
}
This will add the respawner functions. Replace X,Y,Z with your own coords.
nospick and repairpickup is what we added earlier and they are made for asigning an ID to the pickups, which we can use for using, respawning and deleting the pickups.

CreatePickup(Model,type,X,Y,Z,Virtual world)
The model is what it looks like.
1240 is a heart.
1009 is a NOS tube.

The type is how it will work.
Type 14 means that it will only work when the player picks it up with a car.

X,Y,Z is the coords. X is horizontal, Y is Vertical and Z is height.


Moving on.
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == nospickup)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                DestroyPickup(nospickup);
                SetTimer("respawnnos",500,false);
                switch(GetVehicleModel( GetPlayerVehicleID(playerid) ))
                {
                    case 449,448,461,462,463,468,471,509,510,521,522,523,581,586,481,450,441,464,465,501,564,594,611,610,608,607,606,595,592,593,591,590,584,577,570,569,563,554,548,538,537,520,519,513,512,511,497,493,488,487,484,476,473,472,496,460,452,447,446,435,432,430,417,409,407:
                    return SendClientMessage(playerid,0xFF0000AA,"You can not add nos to this vehicle!");
                }
                AddVehicleComponent(GetPlayerVehicleID(playerid),1010);
                PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
            }
        }
    }
    if(pickupid == repairpickup)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                DestroyPickup(repairpickup);
                SetTimer("respawnrepair",500,false);
                switch(GetVehicleModel( GetPlayerVehicleID(playerid) ))
                {
                    case 509,510,481,449,450,441,464,465,501,564,594,611,610,608,607,606,595,592,593,591,590,584,577,570,569,563,554,548,538,537,520,519,513,512,511,497,493,488,487,484,476,473,472,496,460,452,447,446,435,432,430,417,409,407:
                    return SendClientMessage(playerid,0xFF0000AA,"You can not repair this vehicle!");
                }
                SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
                RepairVehicle(GetPlayerVehicleID(playerid));
                PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
            }
        }
    }
    return 1;
}
This is what will happen when you pickup the pickups.


pawn Код:
if(pickupid == nospickup)
First of it checks if you picked up the nospickup. If you did; It proceeds.


pawn Код:
if(IsPlayerInAnyVehicle(playerid))
it checks if you are in a vehicle, if you are; it proceeds.


pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
it checks if you are the driver of the vehicle, if you are; it proceeds, again.


pawn Код:
switch(GetVehicleModel( GetPlayerVehicleID(playerid) ))
{
case 449,448,461,462,463,468,471,509,510,521,522,523,581,586,481,450,441,464,465,501,564,594,611,610,608,607,606,595,592,593,591,590,584,577,570,569,563,554,548,538,537,520,519,513,512,511,497,493,488,487,484,476,473,472,496,460,452,447,446,435,432,430,417,409,407:
return SendClientMessage(playerid,0xFF0000AA,"You can not add nos to this vehicle!");
}
This is the point where it checks which VehicleID you have. If you dont have any of those above it proceeds.
But if you do you get the message "You can not add nos to this vehicle"
Those ID's above are Planes, Helis, Bikes and bicycles and some other misc. vehicles.


pawn Код:
AddVehicleComponent(GetPlayerVehicleID(playerid),1010);
This adds NOS to your vehicle

pawn Код:
SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
RepairVehicle(GetPlayerVehicleID(playerid));
This is for the Repair pickup. The first one sets your carhealth to 1000,
GetPlayerVehicleID detects what ID your car has that you sit in at the moment.
And RepairVehicle repairs the visual damage (components)


pawn Код:
DestroyPickup(nospickup);
This Destroys the NOS pickup


pawn Код:
SetTimer("respawnnos",500,false);
This spawns it again.


pawn Код:
PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
This executes a sound.

Full script here.
pawn Код:
#define filterscript
#include <a_samp>
new repairpickup, nospickup;
public OnFilterScriptInit()
{
    print("Pickup FS");
    respawnnos();
    respawnrepair();
    return 1;
}

public OnFilterScriptExit()
{
    DestroyPickup(nospickup);
    DestroyPickup(repairpickup);
    return 1;
}

forward respawnnos();
public respawnnos()
{
    nospickup = CreatePickup(1009,14,2063.7432,1344.5387,10.6719,-1);//NOS
}

forward respawnrepair();
public respawnrepair()
{
    repairpickup = CreatePickup(1240,14,2069.7778,1343.7512,10.6797,-1);//Repair
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == nospickup)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                DestroyPickup(nospickup);
                SetTimer("respawnnos",500,false);
                switch(GetVehicleModel( GetPlayerVehicleID(playerid) ))
                {
                    case 449,448,461,462,463,468,471,509,510,521,522,523,581,586,481,450,441,464,465,501,564,594,611,610,608,607,606,595,592,593,591,590,584,577,570,569,563,554,548,538,537,520,519,513,512,511,497,493,488,487,484,476,473,472,496,460,452,447,446,435,432,430,417,409,407:
                    return SendClientMessage(playerid,0xFF0000AA,"You can not add nos to this vehicle!");
                }
                AddVehicleComponent(GetPlayerVehicleID(playerid),1010);
                PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
            }
        }
    }
    if(pickupid == repairpickup)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                DestroyPickup(repairpickup);
                SetTimer("respawnrepair",500,false);
                switch(GetVehicleModel( GetPlayerVehicleID(playerid) ))
                {
                    case 509,510,481,449,450,441,464,465,501,564,594,611,610,608,607,606,595,592,593,591,590,584,577,570,569,563,554,548,538,537,520,519,513,512,511,497,493,488,487,484,476,473,472,496,460,452,447,446,435,432,430,417,409,407:
                    return SendClientMessage(playerid,0xFF0000AA,"You can not repair this vehicle!");
                }
                SetVehicleHealth(GetPlayerVehicleID(playerid),1000);
                RepairVehicle(GetPlayerVehicleID(playerid));
                PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
            }
        }
    }
    return 1;
}
Reply
#2

Why create a public for creating pickups?...

Otherwise, nice.
Reply
#3

Quote:
Originally Posted by iGetty
Посмотреть сообщение
Why create a public for creating pickups?...

Otherwise, nice.
To respawn the pickups.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)