SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 10/03/2015, 01:11 AM   #1
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,168
Reputation: 361
Default [UPDATE] Dynamic surfaces - Create your own surface with just one line

What is this?

With this include you can dynamically create your own surface by inputting starting X and Y and ending X and Y positions, along with the model of the object, height, X and Y object offsets and other additional parameters. You can easily edit your surface once you've created it, or you can destroy it. Read more about functions and their parameters below.



Credits:

- Incognito for streamer plugin,
- Y_Less for foreach/iterator include.



Pictures:







How to use this?

Scroll down and download the "surface.inc" include file and place it into the "\pawno\include\" folder and do the same thing with "streamer.inc" and "foreach.inc" files.

Open your script and put this ...:
Code:
#include <streamer>
#include <foreach>
#include <surface>
... right after the:
Code:
#include <a_samp>

Also make sure to download the foreach include and streamer plugin and other necessary files with it.

Example:
Code:
// Sand objects (covers the whole San Andreas map plus the sea surrounding it, 5184 objects in total).
CreateSurface(19548, 125.0, 125.0, 35.0, -4500.0, -4500.0, 4500.0, 4500.0, .d_stream = 1000.0);



Functions:


CreateSurface
Information: Use this function to create a surface on the server.

Input parameters:

Main parameters:

@object_model - model ID of the object which will be used to create the surface.
@Float: x_off - object's X offset.
@Float: y_off - object's Y offset.
@Float: height - height of our surface.
@Float: x_start - starting X position of our surface.
@Float: y_start - starting Y position of our surface.
@Float: x_end - ending X position of our surface.
@Float: y_end - ending Y position of our surface.

Additional parameters:
@Float: x_rot - X rotation for objects (it's 0.0 by default).
@Float: y_rot - Y rotation for objects (it's 0.0 by default).
@Float: z_rot - Z rotation for objects (it's 0.0 by default).
@world - the virtual world of our surface (it's -1 by default).
@interior - the interior of our surface (it's -1 by default).
@player - use this if you want to create the surface only for a specific player (it's -1 by default).
@Float: d_stream - streaming distance for objects (it's 200.0 by default).
@Float: d_draw - drawing distance for objects (it's 0.0 by default).

returns - the function returns the ID of the dynamically created surface. It returns -1 if there is a fail in creation, which means there are too many surfaces created. It returns -2 if one of the starting and ending positions (X, Y) is the same (the script will also fail to create the surface).

Example:
Code:
// Breakable glass surface at "The Farm" (1978 objects in total).
new
		s_id = CreateSurface(1649, 4.4, 3.31, 129.0, -1195.0, -1065.0, -1007.0, -916.0, .d_stream = 1000.0, .x_rot = 270.0);


DestroySurface
Information: Use this function to destroy the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns true (1) if the surface was successfully destroyed and false (0) if the surface doesn't exist.

Example:
Code:
DestroySurface(s_id);


SetSurfaceTexture
Information: Use this function to set the material texture for every object created for surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@m_index - the material index on the surface to change.
@txd_model - the modelid on which the replacement texture is located.
@txd_name[] - the name of the txd file which contains the replacement texture.
@texture_name[] - the name of the texture to use as the replacement.
@m_color - the object color to set, as an integer or hex in ARGB color format, using 0 keeps the existing material color (it's 0 by default).

returns - the function returns true (1) if the material texture was successfully applied and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceTexture(s_id, 0, 17944, "lngblok_lae2", "white64bumpy");


SetSurfaceObjectTexture
Information: Use this function to set the material texture for a specific object created for surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@slot - the slot where our object is located.
@m_index - the material index on the object to change.
@txd_model - the modelid on which the replacement texture is located.
@txd_name[] - the name of the txd file which contains the replacement texture.
@texture_name[] - the name of the texture to use as the replacement.
@m_color - the object color to set, as an integer or hex in ARGB color format, using 0 keeps the existing material color (it's 0 by default).

returns - the function returns true (1) if the material texture was successfully applied and false (0) if the surface doesn't exist or if the ID of the slot or object is invalid.

Example:
Code:
SetSurfaceObjectTexture(s_id, 5, 0, 17944, "lngblok_lae2", "white64bumpy");


SetSurfaceModel
Information: Use this function to change the object model of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@object_model - model ID of the object which will be used to create/change the surface.
@Float: x_off - object's X offset.
@Float: y_off - object's Y offset.

returns - the function returns true (1) if the object model of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceModel(s_id, 19552, 125.0, 125.0);


GetSurfaceModel
Information: Use this function to get the information about the object model of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the object model if the surface exists and false (0) if it doesn't exist.

Example:
Code:
printf("Object model of the surface is %i.", GetSurfaceModel(s_id));


SetSurfacePos
Information: Use this function to change the starting and ending positions of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@Float: x_start - starting X position of our surface.
@Float: y_start - starting Y position of our surface.
@Float: x_end - ending X position of our surface.
@Float: y_end - ending Y position of our surface.

returns - the function returns true (1) if the positions of the surface were successfully changed and false (0) if the surface doesn't exist or if one of the starting and ending positions (X, Y) is the same.

Example:
Code:
SetSurfacePos(s_id, -500.0, -500.0, 500.0, 500.0);


GetSurfacePos
Information: Use this function to get the information about the starting and ending positions of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@&Float: x_start - a float variable in which to store the starting X position in, passed by reference.
@&Float: y_start - a float variable in which to store the starting Y position in, passed by reference.
@&Float: x_end - a float variable in which to store the ending X position in, passed by reference.
@&Float: y_end - a float variable in which to store the ending Y position in, passed by reference.

returns - the function returns true (1) if the surface exists and false (0) if it doesn't exist.

Example:
Code:
new
		Float:pos[4];
GetSurfacePos(s_id, pos[0], pos[1], pos[2], pos[3]);
printf("Positions of the surface are: starting X (%0.2f), starting Y (%0.2f), ending X (%0.2f), ending Y (%0.2f)", pos[0], pos[1], pos[2], pos[3]);


SetSurfaceHeight
Information: Use this function to change the height of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@Float: height - height of our surface.

returns - the function returns true (1) if the height of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceHeight(s_id, 50.0);


GetSurfaceHeight
Information: Use this function to get the information about the height of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the height (float) if the surface exists and -100.0 if it doesn't exist.

Example:
Code:
printf("Height of the surface is %0.2f.", GetSurfaceHeight(s_id));


SetSurfaceRot
Information: Use this function to change the rotation of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@Float: x_rot - X rotation for objects.
@Float: y_rot - Y rotation for objects.
@Float: z_rot - Z rotation for objects.

returns - the function returns true (1) if the rotation was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceRot(s_id, 0.0, 0.0, 90.0);


GetSurfaceRot
Information: Use this function to get the information about the rotation of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@&Float: x_rot - a float variable in which to store the X rotation in, passed by reference.
@&Float: y_rot - a float variable in which to store the Y rotation in, passed by reference.
@&Float: z_rot - a float variable in which to store the Z rotation in, passed by reference.

returns - the function returns true (1) if the surface exists and false (0) if it doesn't exist.

Example:
Code:
new
		Float:pos[3];
GetSurfaceRot(s_id, pos[0], pos[1], pos[2]);
printf("Rotations of the surface are: X (%0.2f), Y (%0.2f), Z (%0.2f)", pos[0], pos[1], pos[2]);


SetSurfaceStreamDistance
Information: Use this function to change the streaming distance of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@Float: d_stream - streaming distance for objects.

returns - the function returns true (1) if the streaming distance of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceStreamDistance(s_id, 400.0);


GetSurfaceStreamDistance
Information: Use this function to get the information about the streaming distance of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the streaming distance (float) if the surface exists and 0.0 if it doesn't exist.

Example:
Code:
printf("Streaming distance of the surface is %0.2f.", GetSurfaceStreamDistance(s_id));


SetSurfaceDrawDistance
Information: Use this function to change the drawing distance of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.
@Float: d_draw - drawing distance for objects.

returns - the function returns true (1) if the drawing distance of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceDrawDistance(s_id, 400.0);


GetSurfaceDrawDistance
Information: Use this function to get the information about the drawing distance of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the drawing distance (float) if the surface exists and -1.0 if it doesn't exist.

Example:
Code:
printf("Drawing distance of the surface is %0.2f.", GetSurfaceDrawDistance(s_id));


SetSurfaceWorld
Information: Use this function to change the virtual world of the surface. Use the -1 value if you want the surface to be visible in all worlds.

Input parameters:
@s_id - the ID of the dynamic surface.
@world - the virtual world of our surface.

returns - the function returns true (1) if the virtual world of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceWorld(s_id, 5);


GetSurfaceWorld
Information: Use this function to get the information about the virtual world of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the virtual world if the surface exists and -2 if it doesn't exist.

Example:
Code:
printf("Virtual world of the surface is %i.", GetSurfaceWorld(s_id));


SetSurfaceInterior
Information: Use this function to change the interior of the surface. Use the -1 value if you want the surface to be visible in all interiors.

Input parameters:
@s_id - the ID of the dynamic surface.
@interior - the interior of our surface.

returns - the function returns true (1) if the interior of the surface was successfully changed and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfaceInterior(s_id, 10);


GetSurfaceInterior
Information: Use this function to get the information about the interior of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the interior if the surface exists and -2 if it doesn't exist.

Example:
Code:
printf("Interior of the surface is %i.", GetSurfaceInterior(s_id));


SetSurfacePlayer
Information: Use this function to change the player of the surface. Use the -1 value if you want the surface to be visible to all players.

Input parameters:
@s_id - the ID of the dynamic surface.
@player - use this if you want to show the surface only to a specific player.

returns - the function returns true (1) if the player of the surface was successfully setted and false (0) if the surface doesn't exist.

Example:
Code:
SetSurfacePlayer(s_id, 20);


GetSurfacePlayer
Information: Use this function to get the information about the player of the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the player ID if the surface exists and -2 if it doesn't exist.

Example:
Code:
printf("Player of the surface is %i (%s).", GetSurfacePlayer(s_id), GetPlayerNameEx(GetSurfacePlayer(s_id)));


GetSurfaceObjectCount
Information: Use this function to get the information about total objects created for the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the total object count if the surface exists and false (0) if it doesn't exist.

Example:
Code:
printf("Total object count for the surface is %i.", GetSurfaceObjectCount(s_id));


GetSurfaceHorizontalObjects
Information: Use this function to get the information about total objects created in horizontal direction (X) for the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the horizontal object count if the surface exists and false (0) if it doesn't exist.

Example:
Code:
printf("Horizontal object count for the surface is %i.", GetSurfaceHorizontalObjects(s_id));


GetSurfaceVerticalObjects
Information: Use this function to get the information about total objects created in vertical direction (Y) for the surface.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the vertical object count if the surface exists and false (0) if it doesn't exist.

Example:
Code:
printf("Vertical object count for the surface is %i.", GetSurfaceVerticalObjects(s_id));


GetSurfaceSurplusObjects
Information: Use this function to get the information about created surplus objects which aren't counted in neither horizontal (X) or vertical direction (Y) for the surface. There will be surplus objects if the calculation for creating objects was disturbed due to objects-per-surface limit.

Input parameters:
@s_id - the ID of the dynamic surface.

returns - the function returns the surplus object count if the surface exists and -1 if it doesn't exist.

Example:
Code:
printf("Surplus object count for the surface is %i.", GetSurfaceSurplusObjects(s_id));



Regarding horizontal, vertical and surplus objects:

Code:
// We change this in our "surface.inc" include file.
#define MAX_SURFACE_OBJECTS (10)

new
		s_id = CreateSurface(18752, 215.0, 215.0, 100.0, 500.0, 500.0, -500.0, -500.0);

printf("Total object count for the surface is %i.", GetSurfaceObjectCount(s_id));
printf("Horizontal object count for the surface is %i.", GetSurfaceHorizontalObjects(s_id));
printf("Vertical object count for the surface is %i.", GetSurfaceVerticalObjects(s_id));
printf("Surplus object count for the surface is %i.", GetSurfaceSurplusObjects(s_id));

This will create our surface from -500.0, -500.0 to 500.0, 500.0.

Total distance in X direction:
500.0 + 500.0 = 1000.0

Total distance in Y direction:
500.0 + 500.0 = 1000.0

X offset
1000.0 / 215.0 = 4.65 ~= 5

Y offset
1000.0 / 215.0 = 4.65 ~= 5

Total object count:
5 * 5 = 25

But our objects-per-surface limit is setted to 10 in this case, so that's the maximum the function will create.

Our "printf" functions will return this:
Code:
Error at "UpdateSurface" function for model 18752 (surface ID: 0) - limit for objects per surface is reached (10/25). Change the "MAX_SURFACE_OBJECTS" definition in your "surface.inc" include file if you want to have more objects per surface.

Created/updated 10 objects at "UpdateSurface" function for model 18752 (surface ID: 0).

Total object count for the surface is 10.
Horizontal object count for the surface is 3.
Vertical object count for the surface is 1.
Surplus object count for the surface is 7.
If we set our objects-per-surface limit to 25 or more in this case, this is what we'll get:
Code:
Created/updated 25 objects at "UpdateSurface" function for model 18752 (surface ID: 0).

Total object count for the surface is 25.
Horizontal object count for the surface is 5.
Vertical object count for the surface is 5.
Surplus object count for the surface is 0.
There were no surplus objects, because the calculation for creating objects wasn't disturbed - the limit was big enough.



Loops:

If you want to loop through all valid (created) objects for the surface, then use the code like this:
Code:
for(new a = 0; a < GetSurfaceObjectCount(s_id); a++)
{
	MySurfaceFunctionForObject(s_id, a);
}

If you want to loop through all valid (created) surfaces, then use the code like this:
Code:
foreach(Iter_Surface, a)
{
	MySurfaceFunction(a);
}



New settings and objects in surface:

If you have for an example 500 objects created for your surface and you change the model, X and Y offset of the object or starting and ending position, so the surface would create more objects, you'll need to re-apply the texture for these additional objects. The old ones will be fine.

In case you also change your settings, but this time so it would produce less objects than before, then you have no worries, the script will delete other unnecessary/surplus objects regarding the old settings of the surface.



Definitions:

These are the definitions in the include file (these values are default in the include file - change them as you like):
Code:
#define MAX_SURFACES (10)
#define MAX_SURFACE_OBJECTS (3000)
#define OBJ_DBG_MSG

Definition "MAX_SURFACES" obviously tells the script how many surfaces are allowed to be created. The "MAX_SURFACE_OBJECTS" definition tells the script how many objects per surface are allowed to be created.

Delete the "OBJ_DBG_MSG" definition if you don't want messages about surface creating/updating in the console/server log.



Download:

Version 2 (latest version - dynamic surfaces):


Version 1 (if you're interested in the main calculation code):

Last edited by Correlli; 15/03/2015 at 05:11 PM. Reason: Update / new version.
Correlli is offline   Reply With Quote
Old 10/03/2015, 04:09 AM   #2
JeaSon
Gangsta
 
JeaSon's Avatar
 
Join Date: Aug 2013
Location: Future
Posts: 564
Reputation: 79
Default Re: Create your own surface with just one line (CreateObjectSurface)

really nice work
__________________
Server:23.94.215.9:7777
Social Media:
Other:
My Works
JeaSon is offline   Reply With Quote
Old 10/03/2015, 08:04 AM   #3
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,371
Reputation: 78
Default Re: Create your own surface with just one line (CreateObjectSurface)

Awesome work.
AroseKhanNiazi is offline   Reply With Quote
Old 10/03/2015, 12:20 PM   #4
LazyB0y
Huge Clucker
 
LazyB0y's Avatar
 
Join Date: Feb 2014
Location: Pakistan
Posts: 281
Reputation: 15
Default Re: Create your own surface with just one line (CreateObjectSurface)

Nice work
__________________
LazyB0y is offline   Reply With Quote
Old 10/03/2015, 01:13 PM   #5
KayJ
Gangsta
 
Join Date: Apr 2014
Posts: 706
Reputation: 61
Default Re: Create your own surface with just one line (CreateObjectSurface)

Nice work
__________________
SA:MP Wikipedia Profile

[Filterscript] Position - Save, Load & Delete [Y_INI] [ZCMD]
[Include] InfoText TextDraw
KayJ is offline   Reply With Quote
Old 10/03/2015, 01:33 PM   #6
streetpeace
Gangsta
 
streetpeace's Avatar
 
Join Date: May 2013
Posts: 512
Reputation: 2
Default Re : Create your own surface with just one line (CreateObjectSurface)

omg, very nice work man!
streetpeace is offline   Reply With Quote
Old 10/03/2015, 01:58 PM   #7
Alex Magaņa
High-roller
 
Alex Magaņa's Avatar
 
Join Date: Oct 2012
Location: 𝕭𝖗𝖔𝖙𝖍𝖊𝖗𝖍𝖔𝖔𝖉
Posts: 2,446
Reputation: 211
Default Re: Create your own surface with just one line (CreateObjectSurface)

Interesting i would check it later!
__________________


Alex Magaņa is offline   Reply With Quote
Old 10/03/2015, 04:06 PM   #8
Pottus
Godfather
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 5,420
Reputation: 1227
Default Re: Create your own surface with just one line (CreateObjectSurface)

It's a good idea but I don't like the design here are my reasons.

1.) There is no saving of objectid's which means you lose all reference of objects!
2.) Too many parameters in the function.
3.) There should be pools of objects this will fix the first two issues.

You need to think dynamic design when it comes to SAMP it's almost always the same refer to this link and specifically the hearts concept.

http://forum.sa-mp.com/showpost.php?...4&postcount=14

So I will just give you an idea here none of this code has been tested.

Code:
#define OBJ_DBG_MSG
#define MAX_SURFACE_GROUPS 10
#define MAX_SURFACE_OBJECTS 200

enum OBJECTSURFACEGROUPINFO
{
		// Parameter settings
		Float:gSI_object_model,
		Float:gSI_x_off,
		Float:gSI_y_off,
		Float:gSI_height,
		Float:gSI_x_start,
		Float:gSI_y_start,
		Float:gSI_x_end,
		Float:gSI_y_end,
		gSI_world,
		gSI_interior,
		gSI_player,
		Float:gSI_d_stream,
		Float:gSI_d_draw,

		// Saved object data
		gSI_ObjectID[MAX_SURFACE_OBJECTS],
		Float:gSI_OX[MAX_SURFACE_OBJECTS],
		Float:gSI_OY[MAX_SURFACE_OBJECTS],

		// Internal data
		bool:gSI_Used,
		gSI_Count,
}

static g_ObjectSurfaceGroups[MAX_SURFACE_GROUPS][OBJECTSURFACEGROUPINFO];
stock CreateObjectSurface(object_model, Float:x_off, Float:y_off, Float:height, Float:x_start, Float:y_start, Float:x_end = 0.0, Float:y_end = 0.0, Float:x_rot = 0.0, Float:y_rot = 0.0, Float:z_rot = 0.0, world = -1, interior = -1, player = -1, Float:d_stream = 200.0, Float:d_draw = 0.0)
{
	for(new i = 0; i < MAX_SURFACE_GROUPS; i++)
	{
		    if(g_ObjectSurfaceGroups[i][gSI_Used] == false)
		    {
			        if(!x_end)
			        {
		         			if(x_start < 0.0)       x_end = floatabs(x_start);
			            	else                            x_end = -x_start;
			        }

			        if(!y_end)
			        {
			                if(y_start < 0.0)       y_end = floatabs(y_start);
			                else                            y_end = -y_start;
			        }

			        if(x_start == x_end || y_start == y_end)
			        {
		         		printf("Error at \"CreateObjectSurface\" function for model %i - one of the starting and ending positions (X: %0.2f, Y: %0.2f) is the same.",
		           				object_model,
			                	x_start,
		                 		y_start
							);
						return -1;
			        }
			        
					// Save all parameter data
                    g_ObjectSurfaceGroups[i][gSI_object_model] = object_model;
                    g_ObjectSurfaceGroups[i][gSI_x_off] = x_off;
                    g_ObjectSurfaceGroups[i][gSI_y_off] = y_off;
                    g_ObjectSurfaceGroups[i][gSI_height] = height;
                    g_ObjectSurfaceGroups[i][gSI_x_start] = x_start;
                    g_ObjectSurfaceGroups[i][gSI_y_start] = y_start;
                    g_ObjectSurfaceGroups[i][gSI_x_end] = x_end;
                    g_ObjectSurfaceGroups[i][gSI_y_end] = y_end;
                    g_ObjectSurfaceGroups[i][gSI_world] = world;
                    g_ObjectSurfaceGroups[i][gSI_interior] = interior;
                    g_ObjectSurfaceGroups[i][gSI_player] = player;
                    g_ObjectSurfaceGroups[i][gSI_d_stream] = d_stream;
                    g_ObjectSurfaceGroups[i][gSI_d_draw] = d_draw;
					g_ObjectSurfaceGroups[i][gSI_Used] = true;
					
			        new
			                        Float:coord[2], bool:calculate[2], loop[2], object;

			        if(x_start < 0.0)
			        {
			                // -3000.0, -4000.0 -> 1000.0
			                // -4000.0, -3000.0 -> 1000.0
			                if(x_end < 0.0)
			                {
			                        if(x_start > x_end)
			                                calculate[0] = true;
			                        coord[0] = floatabs(x_start + floatabs(x_end));
			                }
			                // -3000.0, 4000.0 -> 7000.0
			                else
			                        coord[0] = floatabs(x_start) + x_end;
			        }
			        else
			        {
			                // 3000.0, -4000.0 -> 7000.0
			                if(x_end < 0.0)
			                {
			                        calculate[0] = true;
			                        coord[0] = x_start + floatabs(x_end);
			                }
			                // 3000.0, 4000.0 -> 1000.0
			                // 4000.0, 3000.0 -> 1000.0
			                else
			                {
			                        if(x_start > x_end)
			                                calculate[0] = true;
			                        coord[0] = floatabs(x_start - x_end);
			                }
			        }

			        if(y_start < 0.0)
			        {
			                // -3000.0, -4000.0 -> 1000.0
			                // -4000.0, -3000.0 -> 1000.0
			                if(y_end < 0.0)
			                {
			                        if(y_start > y_end)
			                                calculate[1] = true;
			                        coord[1] = floatabs(y_start + floatabs(y_end));
			                }
			                // -3000.0, 4000.0 -> 7000.0
			                else
			                        coord[1] = floatabs(y_start) + y_end;
			        }
			        else
			        {
			                // 3000.0, -4000.0 -> 7000.0
			                if(y_end < 0.0)
			                {
			                        calculate[1] = true;
			                        coord[1] = y_start + floatabs(y_end);
			                }
			                // 3000.0, 4000.0 -> 1000.0
			                // 4000.0, 3000.0 -> 1000.0
			                else
			                {
			                        if(y_start > y_end)
			                                calculate[1] = true;
			                        coord[1] = floatabs(y_start - y_end);
			                }
			        }

			        loop[0] = floatround(coord[0] / x_off, floatround_ceil);
			        loop[1] = floatround(coord[1] / y_off, floatround_ceil);

			        g_Count = 0;

			        for(new a = 0; a < loop[0]; a++)
			        {
			                for(new b = 0; b < loop[1]; b++)
			                {
			                        if(calculate[0])        coord[0] = x_start - (x_off * a);
			                        else                            coord[0] = x_start + (x_off * a);

			                        if(calculate[1])        coord[1] = y_start - (y_off * b);
			                        else                            coord[1] = y_start + (y_off * b);

									// Save object id
			                        g_ObjectSurfaceGroups[i][gSI_ObjectID][g_Count] = CreateDynamicObject(
			                                object_model,
			                                coord[0],
			                                coord[1],
			                                height,
			                                x_rot,
			                                y_rot,
			                                z_rot,
			                                world,
			                                interior,
			                                player,
			                                d_stream,
			                                d_draw
			                        );

									// Save position data
                                    g_ObjectSurfaceGroups[i][gSI_OX][g_Count] = coord[0];
                                    g_ObjectSurfaceGroups[i][gSI_OY][g_Count] = coord[1];

                                    g_Count++;
			                }
			        }

			        #if defined OBJ_DBG_MSG
			                printf("Created %i objects at \"CreateObjectSurface\" function for model %i.",
			                        g_Count,
			                        object_model
			                );
			        #endif
			        
			        g_ObjectSurfaceGroups[i][gSI_Count] = g_Count;

					// Return surface group index
			        return i;

			    }
		}

		printf("ERROR::CreateObjectSurface()::Too many surfaces");
		return -1;
}

stock SetObjectSurfaceMaterial(index, m_index = 0, txd_model = 0, txd_name[] = "", texture_name[] = "", m_color = 0)
{
		if(index < 0 || index >= MAX_SURFACE_GROUPS)
		{
		        printf("ERROR::SetObjectSurfaceMaterial()::Index out of bounds");
		        return -1;
		}
		else
		{
		        if(g_ObjectSurfaceGroups[index][gSI_Used])
		        {
						for(new i = 0; i < g_ObjectSurfaceGroups[index][gSI_Count]; i++)
						{
                                SetDynamicObjectMaterial(object, m_index, txd_model, txd_name, texture_name, m_color);
						}
	                    g_ObjectSurfaceGroups[index][gSI_Used] = false;
						return 1;
		        }

		}
	    printf("ERROR::SetObjectSurfaceMaterial()::Index does not exist");
		return -1;
}


stock DestroyObjectSurface(index)
{
		if(index < 0 || index >= MAX_SURFACE_GROUPS)
		{
		        printf("ERROR::CreateObjectSurface()::Index out of bounds");
		        return -1;
		}
		else
		{
		        if(g_ObjectSurfaceGroups[index][gSI_Used])
		        {
						for(new i = 0; i < g_ObjectSurfaceGroups[index][gSI_Count]; i++)
						{
								DestroyDynamicObject(g_ObjectSurfaceGroups[index][i];
						}
	                    g_ObjectSurfaceGroups[index][gSI_Used] = false;
						return 1;
		        }
		
		}
	    printf("ERROR::CreateObjectSurface()::Index does not exist");
		return -1;
}
Pottus is offline   Reply With Quote
Old 10/03/2015, 04:57 PM   #9
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,524
Reputation: 437
Default Re: Create your own surface with just one line (CreateObjectSurface)

As Pottus stated there is no way to detect if an object was created with this function / no way to destroy the surface.
Abagail is offline   Reply With Quote
Old 10/03/2015, 05:04 PM   #10
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,168
Reputation: 361
Default Re: Create your own surface with just one line (CreateObjectSurface)

Quote:
Originally Posted by Pottus View Post
1.) There is no saving of objectid's which means you lose all reference of objects!
Usually I would create a dynamic system, but this time I've left it out for the first version, since I was in a hurry and some people were mainly interested in the main code. However, the plan is to update the current version and add additional stuff when I find more time.

Quote:
Originally Posted by Pottus View Post
2.) Too many parameters in the function.
More than half of them are additional.

Cheers.
Correlli is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] acMenu.inc || Create circulars menus with only one line. adri1 Includes 21 04/01/2014 12:42 PM
[Include] rl_areas - Create your own areas in one line! Swimor Includes 2 27/01/2013 06:37 PM
>> SQL Create Table - Line too Long! << nGen.SoNNy Scripting Help 15 19/12/2012 01:18 PM
How create a line lorigio Scripting Help 4 05/02/2012 09:39 AM
[Include] S32GPS - Create a GPS location with just one line! System64 Includes 31 12/09/2011 05:34 PM


All times are GMT. The time now is 05:35 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.