[Help] Gates -
xXRealLegitXx - 20.04.2013
Hello. I have really tried, and tried, and tried to make a gate script and I have tried using gate filterscripts but none of them did what I wanted.
What I want is a command (/gate open) that moves a certain gate. Same thing with /gate close.
But I want to be able to line gates up to the DECIMAL so like CreateGate or something like that as a function in the script.
I would love something to work of here if someone could help me.
-Jason
Re: [Help] Gates -
BigGroter - 20.04.2013
I do not quite understand your question, is this what you're looking for?
pawn Код:
//Top of the script, under defines.
new GateName;
// Under OnGameModeInit
GateName = CreateObject(ID, x, y, z, xrot, yrot, zrot);
CMD:open(playerid, params[])
{
MoveObject(GateName, x, y, z, speed, rotx, roty, rotz);
return 1;
}
Re: [Help] Gates -
Scenario - 20.04.2013
This is quite basic and hasn't been tested, but it should work absolutely fine for you!
pawn Код:
#include <a_samp>
#include <streamer>
#include <zcmd>
#define MAX_GATES 150 // change 150 to the number of gates you'll have
enum enumGateInformation
{
gateModel,
Float:gateClosePosX,
Float:gateClosePosY,
Float:gateClosePosZ,
Float:gateClosePosRX,
Float:gateClosePosRY,
Float:gateClosePosRZ,
Float:gateOpenPosX,
Float:gateOpenPosY,
Float:gateOpenPosZ,
Float:gateOpenPosRX,
Float:gateOpenPosRY,
Float:gateOpenPosRZ,
gateObjID
};
new
gateInfo[MAX_GATES][enumGateInformation];
stock CreateGate(modelid, Float:cx, Float:cy, Float:cz, Float:crx, Float:cry, Float:crz, Float:ox, Float:oy, Float:oz, Float:orx, Float:ory, Float:orz)
// SYNTAX: model, closex, closey, closez, closerx, closery, closerz, openx, openy, openz, openrx, openry, openrz
{
for(new i = 0; i < sizeof(gateInfo); i++)
{
if(gateInfo[i][gateObjID] == INVALID_OBJECT_ID)
{
gateInfo[i][gateModel] = modelid;
gateInfo[i][gateClosePosX] = cx;
gateInfo[i][gateClosePosY] = cy;
gateInfo[i][gateClosePosZ] = cz;
gateInfo[i][gateClosePosRX] = crx;
gateInfo[i][gateClosePosRY] = cry;
gateInfo[i][gateClosePosRZ] = crz;
gateInfo[i][gateOpenPosX] = ox;
gateInfo[i][gateOpenPosY] = oy;
gateInfo[i][gateOpenPosZ] = oz;
gateInfo[i][gateOpenPosRX] = orx;
gateInfo[i][gateOpenPosRY] = ory;
gateInfo[i][gateOpenPosRZ] = orz;
gateInfo[i][gateObjID] = CreateObject(modelid, cx, cy, cz, crx, cry, crz);
break;
}
}
return 1;
}
stock DestroyGate(gateid)
{
DestroyObject(gateInfo[gateid][gateObjID]);
for(new i; enumGateInformation:i < enumGateInformation; i++) gateInfo[gateid][enumGateInformation:i] = 0;
return 1;
}
CMD:opengate(playerid, params[])
{
new
i = getNearestGate(playerid);
MoveObject(gateInfo[i][gateObjID], gateInfo[i][gateOpenPosX], gateInfo[i][gateOpenPosY], gateInfo[i][gateOpenPosZ], 2.0, gateInfo[i][gateOpenPosRX], gateInfo[i][gateOpenPosRY], gateInfo[i][gateOpenPosRZ]);
return 1;
}
CMD:closegate(playerid, params[])
{
new
i = getNearestGate(playerid);
MoveObject(gateInfo[i][gateObjID], gateInfo[i][gateClosePosX], gateInfo[i][gateClosePosY], gateInfo[i][gateClosePosZ], 2.0, gateInfo[i][gateClosePosRX], gateInfo[i][gateClosePosRY], gateInfo[i][gateClosePosRZ]);
return 1;
}
stock getNearestGate(playerid) // partial credits to [uL]Pottus
{
new
currentGate,
Float:distance = 9999.9, // the whole map, basically
Float:odist;
for(new i = 0; i < sizeof(gateInfo); i++)
{
odist = GetPlayerDistanceFromPoint(playerid, gateInfo[i][gateClosePosX], gateInfo[i][gateClosePosY], gateInfo[i][gateClosePosZ]);
if (odist < distance)
{
currentGate = i;
distance = odist;
}
}
return currentGate;
}
Re: [Help] Gates -
Pottus - 20.04.2013
Try this for getNearestGate()
pawn Код:
stock getNearestGate(playerid)
{
new
currentGate,
Float:distance = 9999.9, // the whole map, basically
Float:odist;
for(new i = 0; i < sizeof(gateInfo); i++)
{
odist = GetPlayerDistanceFromPoint(playerid, gateInfo[i][gateClosePosX], gateInfo[i][gateClosePosY], gateInfo[i][gateClosePosZ]);
if (odist < distance)
{
currentGate = i;
distance = odist;
}
}
return currentGate;
}
Re: [Help] Gates -
Mattakil - 20.04.2013
Well, here is one I made for my server, using zcmd, you type /open [password] and it opens, same with /close...if you have any scripting experience, you should be able to change it to your needs if you want to, if you cant do that drop me a PM...either way, I think it is more simple than the others
pawn Код:
COMMAND:open(playerid, params[])
{
if(isnull(params))
{
SendClientMessage(playerid, -1, "Open/Close [PASSWORD]");
return true;
}
if(!strcmp(params, "gov123", false))
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2819.3171, 2651.5464, 103.3268))
{
MoveObject(pgate1, -2819.3171, 2648.8591, 103.3268, 3.0);
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2855.7876, 2659.5562, 107.6278))
{
MoveObject(pgate2, -2855.7678, 2656.9021, 107.6278, 3.0);
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2466.4287, 2250.1355, 1.3655))
{
MoveObject(pgate3, -2457.7766, 2250.1355, 1.3655, 3.0);
return 1;
}
}
return true;
}
COMMAND:close(playerid, params[])
{
if(isnull(params))
{
SendClientMessage(playerid, -1, "Open/Close [PASSWORD]");
return true;
}
if(!strcmp(params, "gov123", false))
{
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2819.3171, 2651.5464, 103.3268))
{
MoveObject(pgate1, -2819.3171, 2651.5464, 103.3268, 3.0);
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2855.7876, 2659.5562, 107.6278))
{
MoveObject(pgate2, -2855.7678, 2659.5361, 107.6278, 3.0);
return 1;
}
if(IsPlayerInRangeOfPoint(playerid, 5.0, -2457.7766, 2250.1355, 1.3655))
{
MoveObject(pgate3, -2466.4287, 2250.1355, 1.3655, 3.0);
return 1;
}
}
return true;
}
note that gov123 is the password
now you will have to define the objects OnFilterScriptInit so they are always there. I am using Pgate1 in here as the example.
pawn Код:
public OnFilterScriptInit()
{
pgate1 = CreateObject(971, -2819.3171, 2651.5464, 103.3268, 0.0, 0.0, 90.0, 100.0);
Re: [Help] Gates -
Scenario - 20.04.2013
Quote:
Originally Posted by [uL]Pottus
Try this for getNearestGate()
|
EDIT: floatsqroot gave error when used like that...

This is working code, AFAIK:
pawn Код:
stock getNearestGate(playerid) // partial credit goes to [uL]Pottus
{
new
currentGate,
Float:distance = 9999.9, // the whole map, basically
Float:fPos[3],
Float:odist;
GetPlayerPos(playerid, fPos[0], fPos[1], fPos[2]);
for(new i = 0; i < sizeof(gateInfo); i++)
{
odist = floatsqroot(
floatpower(floatsub(gateInfo[i][gateClosePosX], fPos[0]), 2.0) +
floatpower(floatsub(gateInfo[i][gateClosePosY], fPos[1]), 2.0) +
floatpower(floatsub(gateInfo[i][gateClosePosZ], fPos[2]), 2.0)
);
if (odist < distance)
{
currentGate = i;
distance = odist;
}
}
return currentGate;
}
@OP: If you grabbed my code already, you'll want to re-get it because I missed a few things the first time around.
Re: [Help] Gates -
Pottus - 20.04.2013
I derped that function check my update
Re: [Help] Gates -
Scenario - 20.04.2013
Ah, that's better.
I've updated my code, again. This is final now:
pawn Код:
#include <a_samp>
#include <streamer>
#include <zcmd>
#define MAX_GATES 150 // change 150 to the number of gates you'll have
enum enumGateInformation
{
gateModel,
Float:gateClosePosX,
Float:gateClosePosY,
Float:gateClosePosZ,
Float:gateClosePosRX,
Float:gateClosePosRY,
Float:gateClosePosRZ,
Float:gateOpenPosX,
Float:gateOpenPosY,
Float:gateOpenPosZ,
Float:gateOpenPosRX,
Float:gateOpenPosRY,
Float:gateOpenPosRZ,
gateObjID
};
new
gateInfo[MAX_GATES][enumGateInformation];
stock CreateGate(modelid, Float:cx, Float:cy, Float:cz, Float:crx, Float:cry, Float:crz, Float:ox, Float:oy, Float:oz, Float:orx, Float:ory, Float:orz)
// SYNTAX: model, closex, closey, closez, closerx, closery, closerz, openx, openy, openz, openrx, openry, openrz
{
for(new i = 0; i < sizeof(gateInfo); i++)
{
if(gateInfo[i][gateObjID] == INVALID_OBJECT_ID)
{
gateInfo[i][gateModel] = modelid;
gateInfo[i][gateClosePosX] = cx;
gateInfo[i][gateClosePosY] = cy;
gateInfo[i][gateClosePosZ] = cz;
gateInfo[i][gateClosePosRX] = crx;
gateInfo[i][gateClosePosRY] = cry;
gateInfo[i][gateClosePosRZ] = crz;
gateInfo[i][gateOpenPosX] = ox;
gateInfo[i][gateOpenPosY] = oy;
gateInfo[i][gateOpenPosZ] = oz;
gateInfo[i][gateOpenPosRX] = orx;
gateInfo[i][gateOpenPosRY] = ory;
gateInfo[i][gateOpenPosRZ] = orz;
gateInfo[i][gateObjID] = CreateObject(modelid, cx, cy, cz, crx, cry, crz);
break;
}
}
return 1;
}
stock DestroyGate(gateid)
{
DestroyObject(gateInfo[gateid][gateObjID]);
for(new i; enumGateInformation:i < enumGateInformation; i++) gateInfo[gateid][enumGateInformation:i] = 0;
return 1;
}
CMD:opengate(playerid, params[])
{
new
i = getNearestGate(playerid);
MoveObject(gateInfo[i][gateObjID], gateInfo[i][gateOpenPosX], gateInfo[i][gateOpenPosY], gateInfo[i][gateOpenPosZ], 2.0, gateInfo[i][gateOpenPosRX], gateInfo[i][gateOpenPosRY], gateInfo[i][gateOpenPosRZ]);
return 1;
}
CMD:closegate(playerid, params[])
{
new
i = getNearestGate(playerid);
MoveObject(gateInfo[i][gateObjID], gateInfo[i][gateClosePosX], gateInfo[i][gateClosePosY], gateInfo[i][gateClosePosZ], 2.0, gateInfo[i][gateClosePosRX], gateInfo[i][gateClosePosRY], gateInfo[i][gateClosePosRZ]);
return 1;
}
stock getNearestGate(playerid) // partial credits to [uL]Pottus
{
new
currentGate,
Float:distance = 9999.9, // the whole map, basically
Float:odist;
for(new i = 0; i < sizeof(gateInfo); i++)
{
odist = GetPlayerDistanceFromPoint(playerid, gateInfo[i][gateClosePosX], gateInfo[i][gateClosePosY], gateInfo[i][gateClosePosZ]);
if (odist < distance)
{
currentGate = i;
distance = odist;
}
}
return currentGate;
}
Re: [Help] Gates -
Pottus - 20.04.2013
Gotta love how someone asks a question and ends up with a solution that is good enough to be a releasable include.
Re: [Help] Gates -
Mattakil - 20.04.2013
Gotta agree with above, lol...he is looking for a simple command...you guys are posting stuff he probs wont understand to do xD Anyway...here is something else you can do, kinda goes with my first post.
pawn Код:
CMD:gate(playerid, params[])
{
if(!strcmp(params, "open", false))
//paste open codes here
}
and the same for close, it doesnt have to be a 200 line script, ad you see, my first one would be half the size if there wasnt passwords, but it was easier than tying the shit to factions, and I didnt want everyone to be able to open prison security gates...lol