[Include] samp-ships - Create ships and assign them to custom routes
#1

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).
PHP Code:
stock CreateShip(Float:xFloat:yFloat:zFloat:rot,
                 
Float:rot_step SHIP_ROT_STEP,
                 
Float:mov_speed SHIP_MOV_SPEED,
                 
timer_step SHIP_TIMER_STEP
Edit the ship's textures
This function changes the textures of the ship's body.
PHP Code:
stock SetShipBodyMaterial(ship_idobjectidtxd[], material[], color 0xFFFFFFFF
This function edits the ship's containers referring to the enum below.
PHP Code:
stock SetShipContainerMaterial(ship_idcontainer_typeobjectid_bodytxd_body[], material_body[],
                                                        
objectid_doorstxd_doors[], material_doors[], color 0xFFFFFFFF
This enums refers to the original colour of the containers.
PHP Code:
enum
{
    
CONTAINER_RED 0,
    
CONTAINER_BLUE,
    
CONTAINER_YELLOW

Destroy a ship
PHP Code:
stock DestroyShip(ship_id
Create a new route
PHP Code:
CreateRoute(const Float:new_route[][2], size sizeof(new_route)) 
Destroy a route
PHP Code:
stock DestroyRoute(route_id
Assign a route to a ship
PHP Code:
stock StartRouteForShip(route_idship_id
Stop ship's current route
PHP Code:
stock StopRouteForShip(ship_id
Callbacks
OnShipRouteCompleted gets called whenever a ship concludes its route.
PHP Code:
forward OnShipRouteCompleted(ship_idroute_idsteps); 
Defines
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
Usage
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 >= && 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.282967.330.0);
    
SetShipBodyMaterial(ship_id10789"xenon_sfse""bluemetal02"0xFFFFFFFF);
    
SetShipContainerMaterial(ship_idCONTAINER_RED10230"freight_sfe""frate64_blue",
                                         
8883"vgsefreight""frate_doors64128");
    
SetShipContainerMaterial(ship_idCONTAINER_BLUE10230"freight_sfe""frate64_blue",
                                         
8883"vgsefreight""frate_doors64128");
    
SetShipContainerMaterial(ship_idCONTAINER_YELLOW10230"freight_sfe""frate64_blue",
                                         
8883"vgsefreight""frate_doors64128");
    new const 
Float:route[][2] =
    {
        {-
3279.01855, -3034.28296},
        {-
3325.527831171.91589},
        {-
2982.634771687.91125},
        {-
1907.102541776.17517},
        {-
1340.109991364.19568},
        {-
1342.35938869.20868},
        {-
1211.62256638.47266},
        {-
990.97693602.15613},
        {-
1431.59937191.26247}
    };
    
    
//Route 1
    
route_forward CreateRoute(routesizeof(route));
    
//Route 2 = reverse of route 1
    
route_backwards CreateRoute(array_reverse(routesizeof(route)), sizeof(route));
    
StartRouteForShip(route_forwardship_id);
}
public 
OnShipRouteCompleted(ship_idroute_idsteps)
{
    
printf("\nShip %d finished route %d in %d steps\n",
                    
ship_idroute_idsteps);
    if(
route_id == route_forward)
    {
        
StartRouteForShip(route_backwardsship_id);
    }
    else if(
route_id == route_backwards)
    {
        
StartRouteForShip(route_forwardship_id);
    }
    return 
1;

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
Reply
#2

Good job, marked.
Reply
#3

Awesome job, keep up!
Reply
#4

I was looking for this, keep it up! +rep
Reply
#5

That is fucking dope.
Well done dude.
Reply
#6

Great release tbh.
Reply
#7

GOOD JOB MATE!!!
+REPP
Reply
#8

I'll surely use it, good job.
Reply
#9

Amazing, keep up the good work.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)