SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 20/11/2019, 06:23 PM   #1
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default How to make a Building System

Hi!
I want to show you how you can create a Building System with an enum and an Automated enter/exit system with ZCMD and Pickups.


First you have to create the enum:

Code:
enum BuildingInfo {
	Float:benterx,
	Float:bentery,
	Float:benterz,
	Float:bexitx,
	Float:bexity,
	Float:bexitz,
	bInterior,
	bName[128]
}
You can customize it of course i have the coordinates for the Pickups and the Enter/Exit Coordinates,Interior and Name of the Building

now you can create the Array for the enum, so you can enter your own Informations and coordinates

Code:
new bInfo[][BuildingInfo] = {
{2337.1052,2458.4021,14.9688,238.6867,140.1222,1003.0234,3,"LVPD HQ"}
};
That's the LVPD for example, you have to put the Information exactly as the enum is, so the Enter Coordinates are first, than the exit coordinates, the interior,and the name.

The Name is for the Pickup, where a Text is placed at GameMode Start

You can do this like shown here:

Code:
DisableInteriorEnterExits();
for(new i=0; i<sizeof(bInfo); i++)
{
	new string[128];
	format(string,sizeof(string),"/enter or Key F to leave the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], -1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], 30, 0);
	format(string,sizeof(string),"/exit or Key F to enter the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][bexitx],bInfo[i][bexity], bInfo[i][bexitz],-1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][bexitx], bInfo[i][bexity], bInfo[i][bexitz], 30, 0);
}
if you have this under OnGameModeInit, it will create the pickups and Text for all Buildings, that you have in the enum, so it does it easy for you.

Now we create the Command for the enter Exit System:

Code:
CMD:exit(playerid)
{
	for(new i=0; i<sizeof(bInfo); i++)
	{
		if(!IsPlayerInRangeOfPoint(playerid, 5, bInfo[i][bexitx], bInfo[i][bexity], bInfo[i][bexitz]))continue;
		if(IsPlayerInAnyVehicle(playerid))continue;
		SetPlayerInterior(playerid, 0);
		SetPlayerPos(playerid, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz]);
		return 1;
	}
	return 1;
}

CMD:enter(playerid)
{
	for(new i=0; i<sizeof(bInfo); i++)
	{
		if(!IsPlayerInRangeOfPoint(playerid, 5, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz]))continue;
		if(IsPlayerInAnyVehicle(playerid))continue;
		SetPlayerInterior(playerid, bInfo[i][bInterior]);
		SetPlayerPos(playerid, bInfo[i][bexitx], bInfo[i][bexity], bInfo[i][bexitz]);
		return 1;
	}
	return 1;
}
so now, you can enter and exit any building with this commands. It will automatically check every Building and see if you are in range of the enter or exit point,and it will put you in the right building and interior.

To enter a building with the Key "F" or "ENTER" you put the following under OnPlayerKeyStateChange

Code:
if(newkeys == KEY_SECONDARY_ATTACK)
{
	cmd_enter(playerid);
	cmd_exit(playerid);
	return 1;
}
This was my first tutorial, so don't be so bad to me xD i know my english isn't that great,but i hope you will understand the tutorial, it is more for experienced scripters than for beginners.
ImTobi is offline   Reply With Quote
Old 21/11/2019, 05:29 AM   #2
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,883
Reputation: 1321
Default Re: How to make a Building System

This is a much older method that works fine when done correctly which you have only half done (we will get to that after) however you can do this without any looping you can just use the streamer with dynamic areas.

Simply save the dynamic area id the player when the enter.
When a player types /enter or a key press first check if they are in that area
If they are in that area still use the extraid feature to store the interior reference from the area they are in
Finally confirm that the areaid that was given matches the reference stored in the interior array (You need to update enums here)

Now another thing why not save the id's of what is created? There should always be some kind of clean up routine created what you have here is bad practice.

Code:
DisableInteriorEnterExits();
for(new i=0; i<sizeof(bInfo); i++)
{
	new string[128];
	format(string,sizeof(string),"/enter or Key F to leave the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], -1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], 30, 0);
	format(string,sizeof(string),"/exit or Key F to enter the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][bexitx],bInfo[i][bexity], bInfo[i][bexitz],-1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][bexitx], bInfo[i][bexity], bInfo[i][bexitz], 30, 0);
}
What about setting the facing angle?
What about setting the camera behind the player?
Why are you using a static hard-coded system? These kind of systems should be designed DYNAMIC as a standalone include. There should be functions for creating / destroying / modifying.

Just one more thing if you are using data that will not be modified declare your variable correct. Any decent scripter knows that creating modules (includes) is the way to go. Typically variables that just hold data within a system are declared using the "static const" keywords.

Code:
static const bInfo[][BuildingInfo] = {
{2337.1052,2458.4021,14.9688,238.6867,140.1222,1003.0234,3,"LVPD HQ"}
};
The "static" keyword makes the variable invisible to other includes thus making it impossible to modify outside of the include in which that variable (also functions) is declared (encapsulation).

The "const" keyword I am sure you know makes the variable impossible to modify whether that variable is declared globally or in an include.

I'll just tell you the truth this isn't a tutorial for people to learn from it's more of a case of what not to do. This tutorial lacks depth and good practice. 1-Star from me because this isn't really helping anyone as there is so much more that has not been documented that should have been. Another thing is that yes this isn't the best method for teleports but that isn't the problem it is the execution of the method that completely botched this tutorial for so many reasons it isn't funny.

Last edited by Pottus; 21/11/2019 at 06:05 AM.
Pottus is offline   Reply With Quote
Old 21/11/2019, 03:11 PM   #3
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: How to make a Building System

Quote:
Originally Posted by Pottus View Post
This is a much older method that works fine when done correctly which you have only half done (we will get to that after) however you can do this without any looping you can just use the streamer with dynamic areas.

Simply save the dynamic area id the player when the enter.
When a player types /enter or a key press first check if they are in that area
If they are in that area still use the extraid feature to store the interior reference from the area they are in
Finally confirm that the areaid that was given matches the reference stored in the interior array (You need to update enums here)

Now another thing why not save the id's of what is created? There should always be some kind of clean up routine created what you have here is bad practice.

Code:
DisableInteriorEnterExits();
for(new i=0; i<sizeof(bInfo); i++)
{
	new string[128];
	format(string,sizeof(string),"/enter or Key F to leave the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], -1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][benterx], bInfo[i][bentery], bInfo[i][benterz], 30, 0);
	format(string,sizeof(string),"/exit or Key F to enter the Building:\n%s",bInfo[i][bName]);
	CreatePickup(1318, 1, bInfo[i][bexitx],bInfo[i][bexity], bInfo[i][bexitz],-1);
	Create3DTextLabel(string, COLOR_WHITE, bInfo[i][bexitx], bInfo[i][bexity], bInfo[i][bexitz], 30, 0);
}
What about setting the facing angle?
What about setting the camera behind the player?
Why are you using a static hard-coded system? These kind of systems should be designed DYNAMIC as a standalone include. There should be functions for creating / destroying / modifying.

Just one more thing if you are using data that will not be modified declare your variable correct. Any decent scripter knows that creating modules (includes) is the way to go. Typically variables that just hold data within a system are declared using the "static const" keywords.

Code:
static const bInfo[][BuildingInfo] = {
{2337.1052,2458.4021,14.9688,238.6867,140.1222,1003.0234,3,"LVPD HQ"}
};
The "static" keyword makes the variable invisible to other includes thus making it impossible to modify outside of the include in which that variable (also functions) is declared (encapsulation).

The "const" keyword I am sure you know makes the variable impossible to modify whether that variable is declared globally or in an include.

I'll just tell you the truth this isn't a tutorial for people to learn from it's more of a case of what not to do. This tutorial lacks depth and good practice. 1-Star from me because this isn't really helping anyone as there is so much more that has not been documented that should have been. Another thing is that yes this isn't the best method for teleports but that isn't the problem it is the execution of the method that completely botched this tutorial for so many reasons it isn't funny.

Thanks for your feedback.
I learned it this way from tutorials
and i do it everytime like this, i add buildings in the enum, instead of ingame, which could be easier. But i don't know the exact way to do it

And it was my first Try xD of an "tutorial"
ImTobi 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
How i can make building enterable CarRamper Scripting Help 2 14/06/2016 09:50 AM
How To Make enterable building? NayanIndia Scripting Help 2 04/02/2015 03:42 PM
how can i make a command to make building's in game wes231 Scripting Help 1 17/11/2011 07:52 AM
How to make a building with a icon Despare Help Archive 2 06/09/2009 04:31 AM
How Do I make an entrance to any building ? *BueNoOo* Help Archive 4 22/03/2009 03:29 PM


All times are GMT. The time now is 07:50 PM.


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