25.11.2014, 02:11
Someone help me ? if how to make a automatic gate ? when you near the gate its open, when you go away or far from gate its close. so please help me if how to script it ..
new gate;
gate = CreateObject(/* add it here*/);
MoveObject(gate, /*code for when it's open*/, 2);
/*
Automatic Gate System By Wingman */ #include <a_samp> #include <streamer> #define GATE_UPDATE_INTERVAL (3) // This is the interval in seconds between the script checking if anybody's inrange of a gate, lower the value, more CPU Usage #define Open(%0,%1) \ MoveDynamicObject(gData[%0][GateID], gData[%0][x2], gData[%0][y2], gData[%0][z2], gData[%0][Speed]); SetDynamicObjectRot(gData[%0][GateID], gData[%0][rx2], gData[%0][ry2], gData[%0][rz2]); gData[%0][State] = true; Tracker[%1] = %0; #define Close(%0,%1) \ MoveDynamicObject(gData[%0][GateID], gData[%0][x], gData[%0][y], gData[%0][z], gData[%0][Speed]); SetDynamicObjectRot(gData[%0][GateID], gData[%0][rx], gData[%0][ry], gData[%0][rz]); gData[%0][State] = false; Tracker[%1] = -1; enum E_GATE_DATA { Modelid, Float, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float2, Float:y2, Float:z2, Float:rx2, Float:ry2, Float:rz2, interior, world, Floatistance, Float:Range, Float:Speed, bool:State, ignorevehicle, GateID } new gData[][E_GATE_DATA] = { /* Format as follows: {Model, ClosedX, ClosedY, ClosedZ, ClosedRotX, ClosedRotY, ClosedRotZ, OpenX, OpenY, OpenZ, OpenRotX, OpenRotY, OpenRotZ, Interior, World, Drawdistance, Radius, Speed, State (KEEP FALSE), ignorevehicle (0 = driver+onfoot, 1 = onfoot, 2 = driver), GateID (KEEP -1)} */ {989, 450.61224365,1162.69311523,9.06943035,0.00000000,0 .00000000,216.49621582,452.35848999,1157.85070801, 9.06943035, 0.00000000,0.00000000,216.49621582, 0, 0, 500.0, 10.0, 1.0, false, 0, -1}, // Octane 1 {989, 668.50390625,1277.46594238,13.77154160,0.00000000, 0.00000000,32.24487305,669.89965820,1272.42529297, 13.77154160, 0.00000000,0.00000000,216.49621582, 0, 0, 500.0, 10.0, 1.0, false, 1, -1} // Octane 2 }; new Tracker[MAX_PLAYERS] = {-1,...}, Timer; public OnFilterScriptInit() { for(new a = 0; a < sizeof(gData); a++) { gData[a][GateID] = CreateDynamicObject(gData[a][Modelid], gData[a][x], gData[a][y], gData[a][z], gData[a][rx], gData[a][ry], gData[a][rz], gData[a][world], gData[a][interior], -1, gData[a][Distance]); } Timer = SetTimer("Update", GATE_UPDATE_INTERVAL*1000, true); return 1; } public OnFilterScriptExit() { for(new a = 0; a < sizeof(gData); a++) { if(gData[a][GateID] != -1) DestroyDynamicObject(gData[a][GateID]); } KillTimer(Timer); return 1; } public OnPlayerConnect(playerid) { Tracker[playerid] = -1; } public OnPlayerDeath(playerid) { Tracker[playerid] = -1; } forward Update(); public Update() { new s, w, i; for(new a = 0, b = GetMaxPlayers(); a < b; a++) { s = GetPlayerState(a); w = GetPlayerVirtualWorld(a); i = GetPlayerInterior(a); for(new g = 0; g < sizeof(gData); g++) { if(Tracker[a] == g) { if(!IsPlayerInRangeOfPoint(a, gData[g][Range], gData[g][x2], gData[g][y2], gData[g][z2]) && gData[g][State] == true) { Close(g, a) } break; } if(IsPlayerInRangeOfPoint(a, gData[g][Range], gData[g][x], gData[g][y], gData[g][z]) && Tracker[a] == -1 && w == gData[g][world] && i == gData[g][interior] && gData[g][State] == false) { switch(gData[g][ignorevehicle]) { case 0: { if(s == PLAYER_STATE_DRIVER || s == PLAYER_STATE_ONFOOT) { Open(g, a) } } case 1: { if(s == PLAYER_STATE_ONFOOT) { Open(g, a) } } case 2: { if(s == PLAYER_STATE_DRIVER) { Open(g, a) } } } break; } } } } |