08.11.2013, 04:59
Can you give me some script for gate system. i need this in HQ Gang thanks for those people who give me a gate system
/*
Dynamic Entrance System
By Infinity90 - Enjoy!
Note: You need to be a rcon amdin to use the commands (/doors & /doorname)
*/
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#define MAX_DOORS 350
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xFF0000C8
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_BLUE 0x4468BBC8
enum DoorInfo
{
Pickup,
Float:Ex,
Float:Ey,
Float:Ez,
Float:Ix,
Float:Iy,
Float:Iz,
Interior,
Text3D:Text,
dText[128],
dActive,
Eworld,
Iworld,
Eint,
Iint
}
new dInfo[MAX_DOORS][DoorInfo];
BootDoors()
{
new dPosition[14][64];
new filestring[256];
new str[128];
new File: file = fopen("doors.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(dInfo))
{
fread(file, filestring);
splits(filestring, dPosition, '|');
strmid(dInfo[idx][dText], dPosition[0], 0, strlen(dPosition[0]), 128);
dInfo[idx][Pickup] = strval(dPosition[1]);
dInfo[idx][Ex] = floatstr(dPosition[2]);
dInfo[idx][Ey] = floatstr(dPosition[3]);
dInfo[idx][Ez] = floatstr(dPosition[4]);
dInfo[idx][Ix] = floatstr(dPosition[5]);
dInfo[idx][Iy] = floatstr(dPosition[6]);
dInfo[idx][Iz] = floatstr(dPosition[7]);
dInfo[idx][Interior] = strval(dPosition[8]);
dInfo[idx][dActive] = strval(dPosition[9]);
dInfo[idx][Eworld] = strval(dPosition[10]);
dInfo[idx][Iworld] = strval(dPosition[11]);
dInfo[idx][Eint] = strval(dPosition[12]);
dInfo[idx][Iint] = strval(dPosition[13]);
if(dInfo[idx][dActive] == 0) {
format(str,sizeof(str),"Door ID %d\nPress C to enter.",idx);
dInfo[idx][Text] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, dInfo[idx][Ex], dInfo[idx][Ey], dInfo[idx][Ez],10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, dInfo[idx][Eworld], dInfo[idx][Eint], -1);
dInfo[idx][Pickup] = CreateDynamicPickup(1239, 23, dInfo[idx][Ex], dInfo[idx][Ey], dInfo[idx][Ez], 0, 0, -1);
} else {
format(str,sizeof(str),"Door ID %d\nPress C to enter.\n%s",idx,dInfo[idx][dText]);
dInfo[idx][Text] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, dInfo[idx][Ex], dInfo[idx][Ey], dInfo[idx][Ez],15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, dInfo[idx][Eworld], dInfo[idx][Eint], -1);
CreateDynamicPickup(dInfo[idx][Pickup], 23, dInfo[idx][Ex], dInfo[idx][Ey], dInfo[idx][Ez], 0, 0, -1);
}
idx++;
printf("%d doors loaded!",idx);
}
fclose(file);
}
return 1;
}
SaveDoors() {
new FileStr[512], File: fHandle = fopen("doors.cfg", io_write);
for(new id; id < MAX_DOORS; id++) {
format(FileStr, sizeof(FileStr), "%s|%d|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d\r\n\n",dInfo[id][dText],dInfo[id][Pickup],dInfo[id][Ex],dInfo[id][Ey],dInfo[id][Ez],dInfo[id][Ix],dInfo[id][Iy],dInfo[id][Iz],dInfo[id][Interior],dInfo[id][dActive],dInfo[id][Eworld],dInfo[id][Iworld],dInfo[id][Eint],dInfo[id][Iint]);
fwrite(fHandle, FileStr); }
return fclose(fHandle);
}
stock IsKeyJustDown(key, newkeys, oldkeys) {
if((newkeys & key) && !(oldkeys & key))
return 1;
return 0;
}
public OnFilterScriptInit()
{
BootDoors();
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
CMD:doorpickup(playerid,params[]) {
if(IsPlayerAdmin(playerid)) {
new doorid,pickup;
if(sscanf(params,"dd",doorid,pickup)) return SendClientMessage(playerid,-2,"USAGE: /doorpickup [doorid] [pickup]");
{
DestroyDynamicPickup(dInfo[doorid][Pickup]);
dInfo[doorid][Pickup] = pickup;
CreateDynamicPickup(pickup, 23, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez], 0, 0, -1);
SendClientMessage(playerid,COLOR_RED,"Door pickup changed!");
SaveDoors();
}
}
else
{
SendClientMessage(playerid,-2,"You're not a rcon admin!");
}
return 1;
}
CMD:doorname(playerid,params[]) {
if(IsPlayerAdmin(playerid)) {
new doorid,str[128];
if(sscanf(params,"ds[128]",doorid,params)) return SendClientMessage(playerid,-2,"USAGE: /doorname [doorid] [text]");
{
DestroyDynamic3DTextLabel(dInfo[doorid][Text]);
dInfo[doorid][dText] = format(str,sizeof(str),"Door ID %d\nPress C to enter.\n%s",doorid,params);
dInfo[doorid][Text] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez],15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, dInfo[doorid][Eworld], dInfo[doorid][Eint], -1);
SaveDoors();
}
}
else
{
SendClientMessage(playerid,-2,"You're not a rcon admin!");
}
return 1;
}
CMD:doors(playerid,params[])
{
if(IsPlayerAdmin(playerid)) {
new option[32],doorid,Float:Pos[3],str[128];
if(sscanf(params,"ds[32]",doorid,option)) {
SendClientMessage(playerid, -2, " USAGE: /doors [doorid] [option] [amount]");
SendClientMessage(playerid, -2, " Options: exterior interior delete");
return 1;
}
if(doorid >= MAX_DOORS) { SendClientMessage(playerid, -2, "Invalid Door!"); return 1; }
GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
if(strcmp(option, "exterior", true) == 0) {
if(dInfo[doorid][dActive] == 0) {
SendClientMessage(playerid,-2,"You have successfully created a new door [Exterior]");
dInfo[doorid][Ex] = Pos[0];
dInfo[doorid][Ey] = Pos[1];
dInfo[doorid][Ez] = Pos[2];
dInfo[doorid][Eworld] = GetPlayerVirtualWorld(playerid);
dInfo[doorid][Eint] = GetPlayerInterior(playerid);
dInfo[doorid][dActive] = 1;
format(str,sizeof(str),"Door ID %d\nPress C to enter.",doorid);
dInfo[doorid][Text] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez],10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, dInfo[doorid][Eworld], dInfo[doorid][Eint], -1);
dInfo[doorid][Pickup] = CreateDynamicPickup(1239, 23, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez], 0, 0, -1);
dInfo[doorid][Pickup] = 1239;
} else {
DestroyDynamic3DTextLabel(dInfo[doorid][Text]);
DestroyDynamicPickup(dInfo[doorid][Pickup]);
dInfo[doorid][Ex] = Pos[0];
dInfo[doorid][Ey] = Pos[1];
dInfo[doorid][Ez] = Pos[2];
dInfo[doorid][Eworld] = GetPlayerVirtualWorld(playerid);
dInfo[doorid][Eint] = GetPlayerInterior(playerid);
format(str,sizeof(str),"Door ID %d\nPress C to enter.",doorid);
dInfo[doorid][Text] = CreateDynamic3DTextLabel(str, COLOR_YELLOW, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez],10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, dInfo[doorid][Eworld], dInfo[doorid][Eint], -1);
dInfo[doorid][Pickup] = CreateDynamicPickup(1239, 23, dInfo[doorid][Ex], dInfo[doorid][Ey], dInfo[doorid][Ez], 0, 0, -1);
dInfo[doorid][Pickup] = 1239;
SendClientMessage(playerid,-2,"Door edited [Exterior]"); }
}
else if(strcmp(option, "interior", true) == 0) {
if(dInfo[doorid][dActive] == 0) {
SendClientMessage(playerid,-2,"You have successfully created a new door [Interior]");
dInfo[doorid][Ix] = Pos[0];
dInfo[doorid][Iy] = Pos[1];
dInfo[doorid][Iz] = Pos[2];
dInfo[doorid][Iworld] = GetPlayerVirtualWorld(playerid);
dInfo[doorid][Iint] = GetPlayerInterior(playerid);
} else {
dInfo[doorid][Ix] = Pos[0];
dInfo[doorid][Iy] = Pos[1];
dInfo[doorid][Iz] = Pos[2];
dInfo[doorid][Iworld] = GetPlayerVirtualWorld(playerid);
dInfo[doorid][Iint] = GetPlayerInterior(playerid);
SendClientMessage(playerid,-2,"Door edited [Interior]"); }
}
else if(strcmp(option, "delete", true) == 0) {
dInfo[doorid][Ex] = 0;
dInfo[doorid][Ey] = 0;
dInfo[doorid][Ez] = -10;
dInfo[doorid][Ix] = 0;
dInfo[doorid][Iy] = 0;
dInfo[doorid][Iz] = 0;
DestroyDynamic3DTextLabel(dInfo[doorid][Text]);
DestroyDynamicPickup(dInfo[doorid][Pickup]);
SendClientMessage(playerid,COLOR_RED,"Door deleted!");
}
SaveDoors();
} else { SendClientMessage(playerid,-2,"You're not a rcon admin!"); }
return 1;
}
/*CMD:enter(playerid,params[])
{
for(new i = 0; i < sizeof(dInfo); i++) {
if(IsPlayerInRangeOfPoint(playerid,3.0,dInfo[i][Ex],dInfo[i][Ey],dInfo[i][Ez])) {
SetPlayerPos(playerid, dInfo[i][Ix],dInfo[i][Iy],dInfo[i][Iz]); SetPlayerInterior(playerid, dInfo[i][Iint]); SetPlayerVirtualWorld(playerid, dInfo[i][Iworld]); }
}
return 1;
}
CMD:exit(playerid,params[])
{
for(new i = 0; i < sizeof(dInfo); i++) {
if(IsPlayerInRangeOfPoint(playerid,3.0,dInfo[i][Ix],dInfo[i][Iy],dInfo[i][Iz])) {
SetPlayerPos(playerid, dInfo[i][Ex],dInfo[i][Ey],dInfo[i][Ez]); SetPlayerInterior(playerid, dInfo[i][Eint]); SetPlayerVirtualWorld(playerid, dInfo[i][Eworld]); }
}
return 1;
}*/
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
if(IsKeyJustDown(KEY_CROUCH, newkeys, oldkeys)) {
for(new i = 0; i < sizeof(dInfo); i++) {
if(IsPlayerInRangeOfPoint(playerid,3.0,dInfo[i][Ex],dInfo[i][Ey],dInfo[i][Ez])) {
SetPlayerPos(playerid, dInfo[i][Ix],dInfo[i][Iy],dInfo[i][Iz]); SetPlayerInterior(playerid, dInfo[i][Iint]); SetPlayerVirtualWorld(playerid, dInfo[i][Iworld]);
}
else if(IsPlayerInRangeOfPoint(playerid,3.0,dInfo[i][Ix],dInfo[i][Iy],dInfo[i][Iz])) {
SetPlayerPos(playerid, dInfo[i][Ex],dInfo[i][Ey],dInfo[i][Ez]); SetPlayerInterior(playerid, dInfo[i][Eint]); SetPlayerVirtualWorld(playerid, dInfo[i][Eworld]);
}
}
}
return 1;
}
forward splits(const strsrc[], strdest[][], delimiter);
public splits(const strsrc[], strdest[][], delimiter) {
new i, li;
new aNum;
new len;
while(i <= strlen(strsrc)){
if(strsrc[i]==delimiter || i==strlen(strsrc)){
len = strmid(strdest[aNum], strsrc, li, i, 128);
strdest[aNum][len] = 0;
li = i+1;
aNum++;
}
i++;
}
return 1;
}
#include a_samp
#include zcmd
#include Dini
#define MAX_GATES 20
#define GATE_OBJECT 980
#define GATE_STATE_CLOSED 0
#define GATE_STATE_OPEN 1
enum fs_gates
{
gCreated,
Float:gX,
Float:gY,
Float:gZ,
Float:gA,
gObject,
gPlacedBy[24],
gStatus,
gPassword
}
new GateInfo[MAX_GATES][fs_gates];
CMD:placegate( playerid, params[] )
{
if( isnull( params) )
return SendClientMessage( playerid, -1, "Syntax: /placegate [password]" );
if( !strval( params ) )
return SendClientMessage( playerid, -1, "You need to input numbers." );
if( IsPlayerInAnyVehicle( playerid ) )
return SendClientMessage( playerid, -1, "You need to exit your vehicle." );
new Float:pPos[4];
GetPlayerPos( playerid, pPos[0], pPos[1], pPos[2] );
GetPlayerFacingAngle( playerid, pPos[3] );
CreateGate( playerid, strval( params ), pPos[0], pPos[1], pPos[2], pPos[3] );
SendClientMessage( playerid, -1, "You succesfully created a movable gate. Use /gopen or /gclose." );
return 1;
}
CMD:gopen( playerid, params[] )
{
if( isnull( params ) )
return SendClientMessage( playerid, -1, "Syntax: /gopen [password]" );
new szName[24], gate = -1;
GetPlayerName( playerid, szName, 24 );
for( new i = 0; i != MAX_GATES; i++ )
if( GateInfo[i][gCreated] == 1 )
if( strval( params ) == GateInfo[i][gPassword] )
{ gate = i; break; }
if( gate != -1 )
{
if( !IsObjectMoving( GateInfo[gate][gObject] ) )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
{
if( GateInfo[gate][gStatus] == GATE_STATE_CLOSED )
{
MoveObject( GateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]-5.3, 7.0 );
SendClientMessage( playerid, -1, "You opened the gate." );
}
else
return SendClientMessage( playerid, -1, "The gate is already open." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
else
return SendClientMessage( playerid, -1, "You must wait untill the gate has moved." );
}
else
return SendClientMessage( playerid, -1, "Invalid password." );
return 1;
}
CMD:gclose( playerid, params[] )
{
if( isnull( params ) )
return SendClientMessage( playerid, -1, "Syntax: /gclose [password]" );
new szName[24], gate = -1;
GetPlayerName( playerid, szName, 24 );
for( new i = 0; i != MAX_GATES; i++ )
if( GateInfo[i][gCreated] == 1 )
if( strval( params ) == GateInfo[i][gPassword] )
{ gate = i; break; }
if( gate != -1 )
{
if( !IsObjectMoving( GateInfo[gate][gObject] ) )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
{
if( GateInfo[gate][gStatus] == GATE_STATE_OPEN )
{
MoveObject( GateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]+5.3, 7.0 );
SendClientMessage( playerid, -1, "You closed the gate." );
}
else
return SendClientMessage( playerid, -1, "The gate is already closed." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
else
return SendClientMessage( playerid, -1, "You must wait untill the gate has moved." );
}
else
return SendClientMessage( playerid, -1, "Invalid password." );
return 1;
}
CMD:removegate( playerid, params[] )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
{
new szName[24];
GetPlayerName( playerid, szName, 24 );
if( !strcmp( szName, GateInfo[i][gPlacedBy], true ) || IsPlayerAdmin( playerid ) )
{
DestroyObject( GateInfo[i][gObject] );
format( GateInfo[i][gPlacedBy], 24, "None" );
GateInfo[i][gCreated] = 0;
GateInfo[i][gX] = 0.0;
GateInfo[i][gY] = 0.0;
GateInfo[i][gZ] = 0.0;
GateInfo[i][gA] = 0.0;
GateInfo[i][gPassword] = 0;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
SendClientMessage( playerid, -1, "You removed the gate." );
new file[32];
format( file, 32, "Gates/gate_%d.ini", i );
if( dini_Exists( file ) )
dini_Remove( file );
break;
}
else
return SendClientMessage( playerid, -1, "You don't own this gate." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
}
return 1;
}
CMD:gateinfo( playerid, params[] )
{
if( IsPlayerAdmin( playerid ) )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( IsPlayerInRangeOfPoint( playerid, 5.0, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
{
new szString[128];
format( szString, 128, "Gate Info( Placed by: %s | Password: %d)", GateInfo[i][gPlacedBy], GateInfo[i][gPassword] );
SendClientMessage( playerid, -1, szString );
return 1;
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
}
}
else
return SendClientMessage( playerid, -1, "You're not an admin." );
return 1;
}
public OnFilterScriptInit( )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 0 )
{
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( fexist( file ) )
{
GateInfo[i][gCreated] = 1;
GateInfo[i][gX] = dini_Float( file, "X" );
GateInfo[i][gY] = dini_Float( file, "Y" );
GateInfo[i][gZ] = dini_Float( file, "Z" );
GateInfo[i][gA] = dini_Float( file, "A" );
GateInfo[i][gStatus] = dini_Int( file, "Status" );
GateInfo[i][gPassword] = dini_Int( file, "Password" );
format( GateInfo[i][gPlacedBy], 24, dini_Get( file, "PlacedBy" ) );
GateInfo[i][gObject] = CreateObject( GATE_OBJECT, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ], 0, 0, GateInfo[i][gA] );
}
}
}
return 1;
}
public OnFilterScriptExit( )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( fexist( file ) )
{
dini_IntSet( file, "Object", GateInfo[i][gObject] );
dini_FloatSet( file, "X", GateInfo[i][gX] );
dini_FloatSet( file, "Y", GateInfo[i][gY] );
dini_FloatSet( file, "Z", GateInfo[i][gZ] );
dini_FloatSet( file, "A", GateInfo[i][gA] );
dini_IntSet( file, "Status", GateInfo[i][gStatus] );
dini_IntSet( file, "Password", GateInfo[i][gPassword] );
dini_Set( file, "PlacedBy", GateInfo[i][gPlacedBy] );
DestroyObject( GateInfo[i][gObject] );
format( GateInfo[i][gPlacedBy], 24, "None" );
GateInfo[i][gCreated] = 0;
GateInfo[i][gX] = 0.0;
GateInfo[i][gY] = 0.0;
GateInfo[i][gZ] = 0.0;
GateInfo[i][gA] = 0.0;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
}
}
}
return 1;
}
public OnObjectMoved( objectid )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( GateInfo[i][gObject] == objectid )
{
if( GateInfo[i][gStatus] == GATE_STATE_CLOSED )
GateInfo[i][gStatus] = GATE_STATE_OPEN;
else if( GateInfo[i][gStatus] == GATE_STATE_OPEN )
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
// Update the variables.
new Float:oPos[3];
GetObjectPos( objectid, oPos[0], oPos[1], oPos[2] );
GateInfo[i][gX] = oPos[0];
GateInfo[i][gY] = oPos[1];
GateInfo[i][gZ] = oPos[2];
break;
}
}
}
return 1;
}
stock CreateGate( playerid, password, Float:x, Float:y, Float:z, Float:a )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 0 )
{
new szName[24];
GetPlayerName( playerid, szName, 24 );
GateInfo[i][gObject] = CreateObject( GATE_OBJECT, x, y, z+1.5, 0, 0, a );
format( GateInfo[i][gPlacedBy], 24, "%s", szName );
GateInfo[i][gCreated] = 1;
GateInfo[i][gX] = x;
GateInfo[i][gY] = y;
GateInfo[i][gZ] = z+1.5; // comment the +1.5 if you're not using object 980.
GateInfo[i][gA] = a;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
GateInfo[i][gPassword] = password;
SetPlayerPos( playerid, x+1, y+1, z );
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( !fexist( file ) )
{
dini_Create( file );
dini_IntSet( file, "Object", GateInfo[i][gObject] );
dini_FloatSet( file, "X", GateInfo[i][gX] );
dini_FloatSet( file, "Y", GateInfo[i][gY] );
dini_FloatSet( file, "Z", GateInfo[i][gZ] );
dini_FloatSet( file, "A", GateInfo[i][gA] );
dini_IntSet( file, "Status", GateInfo[i][gStatus] );
dini_Set( file, "PlacedBy", GateInfo[i][gPlacedBy] );
}
break;
}
}
}