SA-MP Forums Archive
[Include] samp-ships - Create ships and assign them to custom routes - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] samp-ships - Create ships and assign them to custom routes (/showthread.php?tid=642692)



samp-ships - Create ships and assign them to custom routes - SimonItaly - 05.10.2017

samp-ships


https://imgur.com/a/NTnI1
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


Re: samp-ships - Create ships and assign them to custom routes - SetPlayerNameTag - 05.10.2017

Good job, marked.


Re: samp-ships - Create ships and assign them to custom routes - StrikerZ - 05.10.2017

Awesome job, keep up!


Re: samp-ships - Create ships and assign them to custom routes - DonaldDuck - 05.10.2017

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


Re: samp-ships - Create ships and assign them to custom routes - Crystallize - 05.10.2017

That is fucking dope.
Well done dude.


Re: samp-ships - Create ships and assign them to custom routes - cuber - 05.10.2017

Great release tbh.


Re: samp-ships - Create ships and assign them to custom routes - Mr.Vince™ - 05.10.2017

GOOD JOB MATE!!!
+REPP


Re: samp-ships - Create ships and assign them to custom routes - TopShooter2 - 05.10.2017

I'll surely use it, good job.


Re: samp-ships - Create ships and assign them to custom routes - Eoussama - 05.10.2017

Amazing, keep up the good work.