[Include] Controllable Pirateships
#1

With this script you can create controllable pirateships easily.
[ame]www.youtube.com/watch?v=17BGqzWN3is[/ame]

Include File:
pawn Код:
/******************************************************************************/
// Defined Values

#define MAX_PIRATE_SHIP         20
#define INVALID_PIRATE_SHIP     -1

/******************************************************************************/
// Variables

new bool:pirate_Created [MAX_PIRATE_SHIP],
    pirate_Obj          [MAX_PIRATE_SHIP][3],
    pirate_Veh          [MAX_PIRATE_SHIP],
    pirate_PlayerShip   [MAX_PLAYERS] = {INVALID_PIRATE_SHIP, ...};

/******************************************************************************/
// Functions

stock CreatePirateShip(Float:x, Float:y, Float:z, Float:r)
{
    for(new i; i < MAX_PIRATE_SHIP; i ++)
    {
        if(pirate_Created[i])
            continue;

        pirate_Obj[i][0] = CreateObject(8493, x, y, z, 0.0, 0.0, r);//pirtshp01_lvs
        pirate_Obj[i][1] = CreateObject(9159, x, y, z, 0.0, 0.0, r);//pirtshp02_lvs
        pirate_Obj[i][2] = CreateObject(19300, x, y, z, 0.0, 0.0, r);//camera object
        pirate_Veh[i] = CreateVehicle(453, x, y, z, r, -1, -1, -1);//Reefer
        LinkVehicleToInterior(pirate_Veh[i], 1);
        AttachObjectToVehicle(pirate_Obj[i][0], pirate_Veh[i], 0.0, 12.0, 17.0, 0.5, 0.0, 0.0);
        AttachObjectToVehicle(pirate_Obj[i][1], pirate_Veh[i], 0.0, 12.0, 17.0, 0.5, 0.0, 0.0);
        AttachObjectToVehicle(pirate_Obj[i][2], pirate_Veh[i], 0.0, -22.0, 13.0, 0.0, 0.0, 0.0);
        pirate_Created[i] = true;
        return i;
    }
    return INVALID_PIRATE_SHIP;
}

stock DestroyPirateShip(shipid)
{
    if(shipid < 0 || shipid > MAX_PIRATE_SHIP || !pirate_Created[shipid])
        return 0;

    DestroyObject(pirate_Obj[shipid][0]);
    DestroyObject(pirate_Obj[shipid][1]);
    DestroyObject(pirate_Obj[shipid][2]);
    DestroyVehicle(pirate_Veh[shipid]);
    pirate_Created[shipid] = false;
    return 1;
}

IsPirateShipOccupied(shipid)
{
    if(shipid < 0 || shipid > MAX_PIRATE_SHIP || !pirate_Created[shipid])
        return 0;

    for(new playerid; playerid < MAX_PLAYERS; playerid ++)
    {
        if(IsPlayerConnected(playerid) && GetPlayerVehicleID(playerid) == pirate_Veh[shipid])
            return 1;
    }
    return 0;
}

/******************************************************************************/
// Callbacks

pirate_OnPlayerKeyStateChange(playerid, newkeys)
{
    if(!(newkeys & KEY_SECONDARY_ATTACK) || GetPlayerState(playerid) != PLAYER_STATE_ONFOOT)
        return 0;

    for(new i; i < MAX_PIRATE_SHIP; i ++)
    {
        if(!pirate_Created[i])
            continue;

        new Float:x, Float:y, Float:z;
        GetVehiclePos(pirate_Veh[i], x, y, z);
        if(!IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z) || IsPirateShipOccupied(i))
            continue;

        PutPlayerInVehicle(playerid, pirate_Veh[i], 0);
        AttachCameraToObject(playerid, pirate_Obj[i][2]);
        pirate_PlayerShip[playerid] = i;
        return 1;
    }
    return 0;
}

pirate_OnPlayerStateChange(playerid, newstate)
{
    new shipid = pirate_PlayerShip[playerid];
    if(shipid == INVALID_PIRATE_SHIP || newstate == PLAYER_STATE_DRIVER)
        return 0;

    new Float:x, Float:y, Float:z, Float:r;
    GetVehiclePos(pirate_Veh[shipid], x, y, z);
    GetVehicleZAngle(pirate_Veh[shipid], r);
    SetPlayerPos(playerid, x, y, z + 6.0);
    SetPlayerFacingAngle(playerid, r);
    SetCameraBehindPlayer(playerid);
    pirate_PlayerShip[playerid] = INVALID_PIRATE_SHIP;
    return 1;
}

pirate_OnPlayerDisconnect(playerid)
    pirate_PlayerShip[playerid] = INVALID_PIRATE_SHIP;

/******************************************************************************/
Example Filterscript:
pawn Код:
#include <a_samp>
#include <pirate.pwn>

new pirateShip;

public OnFilterScriptInit()
    pirateShip = CreatePirateShip(1640.00, 533.23, -0.41, 81.24);

public OnFilterScriptExit()
    DestroyPirateShip(pirateShip);

public OnPlayerDisconnect(playerid)
    pirate_OnPlayerDisconnect(playerid);
   
public OnPlayerKeyStateChange(playerid, newkeys)
    pirate_OnPlayerKeyStateChange(playerid, newkeys);
   
public OnPlayerStateChange(playerid, newstate)
    pirate_OnPlayerStateChange(playerid, newstate);
Reply
#2

Well, good work but the Speeder isn't the best boat for that. Use Reefer instead.
Reply
#3

Well, you don't see that everyday! Great work!
Reply
#4

It's only good for messing around with a few friends attaching objects to vehicles for practical use is not practical there is sync issues which will launch the player flying and possibly kill them.
Reply
#5

Not bad!
Reply
#6

Quote:
Originally Posted by ThomasTailor93
Посмотреть сообщение
Well, good work but the Speeder isn't the best boat for that. Use Reefer instead.
Thanks. Yeah, i changed it to a reefer

Quote:
Originally Posted by NewerthRoleplay
Посмотреть сообщение
Well, you don't see that everyday! Great work!
Indeed haha, thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)