25.02.2014, 19:13
There are many scripts around that let you simply do /creategate in game and set up dynamic gates that way. However, if you run a big roleplay server that does custom mapping, it might be a pain to do it that way. I've created an advanced mapping script for my server, but I have decided to release a simplified version to all of you.
When you are near a gate that you have mapped in, you can type /gate and it will prompt you for a code, if the code is correct it will open. This is extremely easy to edit to link gates to open according to a house or faction, as opposed to a code.
How does it work?
You simply paste all of your gates (or even all your mapping) in the desired place in the filterscript. I personally use a more advanced version using streamer and a lot more functions, and use the script for all of my mapping.
To create a gate, map 2 gates in your editor, one open and one closed. Now go into your code and export the parameters of the gates and format them as follows:
Modelid - The IDE of the object that you want to move
Closed, open Floats - The X, Y, Z and rotations for the object in it's closed and open spots.
Code - The password required to open the gate.
Now, if you want to use a streamer for this, you can make the gates create in only a certain virtual world, which I recommend if you are using this for RP purposes in interiors.
The script is short, so I will post it below.
Note: This script uses ZCMD. Make sure you have it before trying to compile the script!
When you are near a gate that you have mapped in, you can type /gate and it will prompt you for a code, if the code is correct it will open. This is extremely easy to edit to link gates to open according to a house or faction, as opposed to a code.
How does it work?
You simply paste all of your gates (or even all your mapping) in the desired place in the filterscript. I personally use a more advanced version using streamer and a lot more functions, and use the script for all of my mapping.
To create a gate, map 2 gates in your editor, one open and one closed. Now go into your code and export the parameters of the gates and format them as follows:
Код:
CreateDynamicGate(modelid, Float:closedx, Float:closedy, Float:closedz, Float:closedrx, Float:closedry, Float:closedrz, Float:openx, Float:openy, Float:openz, Float:openrx, Float:openry, Float:openrz, code[]);
Closed, open Floats - The X, Y, Z and rotations for the object in it's closed and open spots.
Code - The password required to open the gate.
Now, if you want to use a streamer for this, you can make the gates create in only a certain virtual world, which I recommend if you are using this for RP purposes in interiors.
The script is short, so I will post it below.
pawn Код:
#include <a_samp>
#include <zcmd>
#undef MAX_OBJECTS
#define MAX_OBJECTS 1000000 //Change this if you want to have a maximum amount of objects in the server
#define MAX_GATES 999 //The maximum amount of gates that will create
enum GateInfo
{
gmodel,
gobject,
Float:gclosedx,
Float:gclosedy,
Float:gclosedz,
Float:gclosedrx,
Float:gclosedry,
Float:gclosedrz,
Float:gopenx,
Float:gopeny,
Float:gopenz,
Float:gopenrx,
Float:gopenry,
Float:gopenrz,
gcode[6],
gclosed,
gopening,
};
#define DIALOG_CODE 392 //Change 392 if the dialog does not show up
new GInfo[MAX_GATES][GateInfo];
new gatescreated;
public OnFilterScriptInit()
{
gatescreated = 0;
//Insert the gate/mapping codes here
//=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%
// END OF EDIT
//=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%=%
for(new i=0; i<MAX_GATES; i++)
{
GInfo[i][gobject] = CreateObject(GInfo[i][gmodel], GInfo[i][gclosedx], GInfo[i][gclosedy], GInfo[i][gclosedz], GInfo[i][gclosedrx], GInfo[i][gclosedry], GInfo[i][gclosedrz]);
GInfo[i][gclosed] = 1;
}
return 1;
}
public OnFilterScriptExit()
{
for(new i = 0; i < MAX_OBJECTS; i++)
{
if(IsValidObject(i))
{
DestroyObject(i);
}
}
}
CMD:gate(playerid)
{
for(new i=0; i<MAX_GATES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, GInfo[i][gclosedx], GInfo[i][gclosedy], GInfo[i][gclosedz]))
{
if(GInfo[i][gclosed] == 1)
{
ShowPlayerDialog(playerid, DIALOG_CODE, DIALOG_STYLE_INPUT, "Code", "This door is password protected.\nEnter the code.", "Enter", "");
GInfo[i][gclosed] = 0;
GInfo[i][gopening] = 0;
}
else
{
MoveObject(GInfo[i][gobject], GInfo[i][gclosedx], GInfo[i][gclosedy], GInfo[i][gclosedz], 3.0, GInfo[i][gclosedrx], GInfo[i][gclosedry], GInfo[i][gclosedrz]);
GInfo[i][gclosed] = 1;
}
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_CODE)
{
if(response)
{
for(new i=0; i<MAX_GATES; i++)
{
if(strmatch(inputtext, GInfo[i][gcode]))
{
MoveObject(GInfo[i][gobject], GInfo[i][gopenx], GInfo[i][gopeny], GInfo[i][gopenz], 3.0, GInfo[i][gopenrx], GInfo[i][gopenry], GInfo[i][gopenrz]);
GInfo[i][gclosed] = 0;
GInfo[i][gopening] = 0;
}
}
}
}
return 0;
}
CreateDynamicGate(modelid, Float:closedx, Float:closedy, Float:closedz, Float:closedrx, Float:closedry, Float:closedrz, Float:openx, Float:openy, Float:openz, Float:openrx, Float:openry, Float:openrz, code[6])
{
gatescreated ++;
new id = gatescreated;
GInfo[id][gmodel] = modelid;
GInfo[id][gclosedx] = closedx;
GInfo[id][gclosedy] = closedy;
GInfo[id][gclosedz] = closedz;
GInfo[id][gclosedrx] = closedrx;
GInfo[id][gclosedry] = closedry;
GInfo[id][gclosedrz] = closedrz;
GInfo[id][gopenx] = openx;
GInfo[id][gopeny] = openy;
GInfo[id][gopenz] = openz;
GInfo[id][gopenrx] = openrx;
GInfo[id][gopenry] = openry;
GInfo[id][gopenrz] = openrz;
GInfo[id][gcode] = code;
return 1;
}
stock strmatch(const String1[], const String2[])//credits to cameltoe
{
if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
{
return true;
}
else
{
return false;
}
}