[Tutorial] Bomb Drop
#1

Do you want to create a drop bomb system , in which you will be able to drop a bomb through any type of vehicle , if yes so see this tutorial it will help you to how to create that type of system.
So Lets start ,
1st you need to open new pawno file ,
then at the top of the script type :

pawn Code:
#include    <a_samp>

#define     COL_RED         "{F81414}" // I have defined this color because i will use it in SendClientMessage otherwise when you compile then there come undefined errors.
Step**
Now you need to insert your (public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)) after these codes:
pawn Code:
public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerKeyStateChange(playerid,oldkeys, newkeys)
{
        return 1;
}
then after type :
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
//you need to type it after (gamemodeinit and gamemodexit if you are going to make this function in gamemode) then it will be able to work properly.
after doing this you need to make a code , which will be able to blast a bomb if you press any key which you edited in your script , such as I am going to add fire key for blast .
Okay now next step:
You need to put this code under public OnPlayerKeyStateChange(playerid, newkeys, oldkeys), There I am using if(GetVehicleModel(GetPlayerVehicleID(playerid)) as a condition , it will help you to not get error message at all time when you press fire key , only that time you
will get error when you enter in scripted vehicle. You can change id and you can add more vehicle for this condition. Okay now let's start to create code:

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 577 || GetVehicleModel(GetPlayerVehicleID(playerid)) == 519) //If you enter vehicle id = 577(Andromada) & vehcile id = 519(shamal) then you will be able to explode fire key to do blast .  
    {
       if(newkeys == KEY_FIRE)// it stayed for : if you press fire key like : right click or left alt then you will be able to explode bomb.
       {
        if(IsPlayerInRangeOfPoint(playerid, 300.0,211.8287,1900.4205,17.4513))// its an another condition which stayed for : if you are near the point where you want to explode you can change its floats and radius as you want (IsPlayerInRangeOfPoint(playerid, radius, float:x , float: y, float:z)
                {
                new Float:x, Float:y, Float:z, Float:a, VID; // this line will be able to not get errors(not define "xxx") for floats and vehicle id
                GameTextForAll("~r~the bomb has been ~r~~n~dropped ~n~~w~exploding in ~p~10 sec",5000,3);// if you use this then a msg will be sent all players who is in-game that bomb will explode in 10 second you can change these line as you want
                GetVehiclePos(VID, x, y, z);//it will get the position of vehicle and there vid(vehicleid)
                GetVehicleZAngle(VID, a);//it will get the z-angle of the vehicle
                SetTimerEx("BombExplode", 10000, false, "i", playerid);
// it is the timer for explode ("BombExplode(function)",
//10000(timer in milliseconds),
//false( it will cancel to explode again after 10 seconds if you change it in true then after 10 seconds again there will be a explode in your settled area),
//"i"(i for integer),
//playerid for the player who is trying to do explode
                }else return SendClientMessage(playerid, COLOR_RED, "You need to be near of area51 to explode");//this is a message if you do not complete the requirements to explode then you will get a error message.
//playerid : the player who will get the error message
//color_Red : the color of error message you can change it as you like.
// "You need to be near of area51" its a message text you can add it as which message you wanna to create.
        }
    }
    return 1;// it will complete the function 1(value will be true) and 0(value will be false)
}
Okay now you need to create function that will be able to help in blasting at the point where you want to set blast. you need to type this code bottom of the script.
pawn Code:
forward BombExplode(playerid);// it is a function which will able to do blast , as we know that it is a public function so we need to forwarded it.
public BombExplode(playerid)
{
    new Float:x, Float:y, Float:z;// I have already explained that it is float
    GetPlayerPos(playerid, x, y, z);// It will get the player position
    CreateExplosion(211.8287,1900.4205,17.4513,9,200.0);// There CreateExplosion will create explode where you want to do blast , CreateExplosion(x , y, z, type(what is type of blast you can ****** it), radius)
    return 1;
}
OKAY lets code has completed try it yourself if any type of problem occurred then pm me . but don't forget to create your vehicle .
Reply
#2

Good Job
Reply
#3

You never assigned VID a value.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)