05.10.2017, 09:09
About
Back when I managed a San Fierro-based roleplay server, I wanted to create some cargo ships passing through the sea and the bay for adding realism and life to the city.
This include aims to create these ships dynamically and assigning them to custom routes.
Functions
Create a new ship
It currently supports only the smallest cargo ship object (10230).
Edit the ship's textures
This function changes the textures of the ship's body.
This function edits the ship's containers referring to the enum below.
This enums refers to the original colour of the containers.
Destroy a ship
Create a new route
Destroy a route
Assign a route to a ship
Stop ship's current route
Callbacks
OnShipRouteCompleted gets called whenever a ship concludes its route.
Defines
Usage
Example script that creates a ship moving from Angel Pine to Easter Basin.
Requirements
- Streamer Plugin
- foreach or YSI\y_iterate
- (probably) Zeex's Pawn compiler. I haven't tried it with SA-MP one.
Thanks
- adri1 / Pottus: this old post about rotations and offsets
- ziggi : stealed his topic layout because it looks good.
Download
- GitHub: https://github.com/SimonItaly/samp-ships
Back when I managed a San Fierro-based roleplay server, I wanted to create some cargo ships passing through the sea and the bay for adding realism and life to the city.
This include aims to create these ships dynamically and assigning them to custom routes.
Functions
Create a new ship
It currently supports only the smallest cargo ship object (10230).
PHP Code:
stock CreateShip(Float:x, Float:y, Float:z, Float:rot,
Float:rot_step = SHIP_ROT_STEP,
Float:mov_speed = SHIP_MOV_SPEED,
timer_step = SHIP_TIMER_STEP)
This function changes the textures of the ship's body.
PHP Code:
stock SetShipBodyMaterial(ship_id, objectid, txd[], material[], color = 0xFFFFFFFF)
PHP Code:
stock SetShipContainerMaterial(ship_id, container_type, objectid_body, txd_body[], material_body[],
objectid_doors, txd_doors[], material_doors[], color = 0xFFFFFFFF)
PHP Code:
enum
{
CONTAINER_RED = 0,
CONTAINER_BLUE,
CONTAINER_YELLOW
}
PHP Code:
stock DestroyShip(ship_id)
PHP Code:
CreateRoute(const Float:new_route[][2], size = sizeof(new_route))
PHP Code:
stock DestroyRoute(route_id)
PHP Code:
stock StartRouteForShip(route_id, ship_id)
PHP Code:
stock StopRouteForShip(ship_id)
OnShipRouteCompleted gets called whenever a ship concludes its route.
PHP Code:
forward OnShipRouteCompleted(ship_id, route_id, steps);
Directive | Default value | Can be redefined |
SHIP_STREAMER_SD | 1000.0 | yes |
SHIP_STREAMER_DD | 1000.0 | yes |
MAX_SHIPS | 10 | yes |
MAX_ROUTES | 5 | yes |
MAX_ROUTE_POINTS | 10 | yes |
SHIP_ROT_STEP | 0.1 | yes |
SHIP_MOV_SPEED | 5.0 | no |
SHIP_TIMER_STEP | 15 | no |
Example script that creates a ship moving from Angel Pine to Easter Basin.
PHP Code:
#include <a_samp>
#include "samp-ships"
static
route_forward,
route_backwards;
stock Float:array_reverse(const Float:list[][2], size)
{
new
pos,
len = size-1,
Float:result[MAX_ROUTE_POINTS][2];
while ( (len >= 0 && pos < sizeof(result)) &&
( (result[pos][0] = list[len][0]) && (result[pos][1] = list[len][1]) ) )
{
pos++;
--len;
}
return result;
}
public OnFilterScriptInit()
{
new ship_id = CreateShip(-3279.01855, -3034.28296, 7.33, 0.0);
SetShipBodyMaterial(ship_id, 10789, "xenon_sfse", "bluemetal02", 0xFFFFFFFF);
SetShipContainerMaterial(ship_id, CONTAINER_RED, 10230, "freight_sfe", "frate64_blue",
8883, "vgsefreight", "frate_doors64128");
SetShipContainerMaterial(ship_id, CONTAINER_BLUE, 10230, "freight_sfe", "frate64_blue",
8883, "vgsefreight", "frate_doors64128");
SetShipContainerMaterial(ship_id, CONTAINER_YELLOW, 10230, "freight_sfe", "frate64_blue",
8883, "vgsefreight", "frate_doors64128");
new const Float:route[][2] =
{
{-3279.01855, -3034.28296},
{-3325.52783, 1171.91589},
{-2982.63477, 1687.91125},
{-1907.10254, 1776.17517},
{-1340.10999, 1364.19568},
{-1342.35938, 869.20868},
{-1211.62256, 638.47266},
{-990.97693, 602.15613},
{-1431.59937, 191.26247}
};
//Route 1
route_forward = CreateRoute(route, sizeof(route));
//Route 2 = reverse of route 1
route_backwards = CreateRoute(array_reverse(route, sizeof(route)), sizeof(route));
StartRouteForShip(route_forward, ship_id);
}
public OnShipRouteCompleted(ship_id, route_id, steps)
{
printf("\nShip %d finished route %d in %d steps\n",
ship_id, route_id, steps);
if(route_id == route_forward)
{
StartRouteForShip(route_backwards, ship_id);
}
else if(route_id == route_backwards)
{
StartRouteForShip(route_forward, ship_id);
}
return 1;
}
- Streamer Plugin
- foreach or YSI\y_iterate
- (probably) Zeex's Pawn compiler. I haven't tried it with SA-MP one.
Thanks
- adri1 / Pottus: this old post about rotations and offsets
- ziggi : stealed his topic layout because it looks good.
Download
- GitHub: https://github.com/SimonItaly/samp-ships