Szerző Téma: Bejárat rendszer [100%] [MySQL]  (Megtekintve 2028 alkalommal)

Bejárat rendszer [100%] [MySQL]
« Dátum: 2013. November 15. - 20:50:08 »
+6 Show voters
Üdvözlök mindenkit!
Lejjebb a saját készítésû Bejárat Rendszeremet mutatom be. Néhány függvény-t a régi See-modból vettem. A rendszer Bug-mentes. Ha mégis gond lenne vele, írjatok. Mivel hosszú szkript, elõfordulhat, hogy valamit kihagytam. Ha ez elõfordul, kérlek jelezd nekem.
Tulajdonságai:
  -Egyszerû paranccsal készíthetõ IG.
  -Mindegyik bejáratnak hosszú neve lehet.
  -MySQL rendszerbe menti õket.
  -Szép 3Dtextlabel, PickUp, GameText.
  -Egy gombnyomásra bedob.
  -Streamer kell hozzá, azaz a VW-k, és az INT-ek teljesen elkülöníthetõk egymástól.
  -BetoltBejaratok(); függvényt használhatod akárhányszor, szépen újratölti a MySQl-bõl az adatokat.
Kép:
http://kepfeltoltes.hu/131115/sa-mp-904_www.kepfeltoltes.hu_.png
.sql fájl letöltése:
https://mega.co.nz/#!9s1EVZLK!VTcMZil6fmezCH8NGVmDTVmhpKNrj6fn5XW3AyhWTkQ
Maga a szkript:
Változók, enumok:
 

#define DIALOG_BEJARAT 9876
#define MAX_BEJARATOK 100
enum bejaratok_adatai
{
       Float:kint_x,
       Float:kint_y,
       Float:kint_z,
       kint_i,
       kint_w,
       Float:bent_x,
       Float:bent_y,
       Float:bent_z,
       bent_i,
       bent_w,
       b_van,
       b_id
};
new Bejaratok[MAX_BEJARATOK][bejaratok_adatai];
new BejaratokPickup[sizeof(Bejaratok)][2];
new Text3D:Bejaratok3D[sizeof(Bejaratok)][2];
new BejaratokNeve[sizeof(Bejaratok)][1];
new bool:BejaratKeszito[MAX_PLAYERS] = false;
enum BejaratKeszitoAdatok
{
    Float:b_poz_x,
    Float:b_poz_y,
    Float:b_poz_z,
    b_poz_i,
    b_poz_w
};
new BejaratKeszitoPoz[MAX_PLAYERS][bejaratKeszitoAdatok];

 
OnPlayerConnect és OnGameModeInit
 
public OnPlayerConnect(playerid)
{   
ResetPlayerBejaratKeszito(playerid);
return 1;
}
public OnGameModeInit()
{
 BetoltBejaratok();
return 1;
}

 
Fõ Parancs: /bejarat
 
CMD:bejarat(playerid, params[])
{
  if(BejaratKeszito[playerid] == false)
  {
   ShowPlayerDialog(playerid, DIALOG_BEJARAT, DIALOG_STYLE_MSGBOX, \"Bejárat készítõ\", \"Helló! Ha szeretnél ide egy bejáratot, akkor kattints a \'Mehet\' gombra.\", \"Mehet\", \"Mégse\");
  return 1;
  }
     if(BejaratKeszito[playerid] == true)
  {
   new b_neve[30], BejaratID = UresBejaratHely();
   if(BejaratID == -1)
           {
               MSG(playerid, \"Nem rakható le több bejárat!\");
               return 1;
        }
           if(sscanf(params, \"s[30]\", b_neve)) return MSG(playerid, \"Használat: /bejarat [ Bejárat neve ]\");
           else if(3 >= strlen(b_neve)) return MSG(playerid, \"A névnek 3 - 30 karakterig terjedõnek kell lennie!\");
        else
        {
               strmid(BejaratokNeve[bejaratID], b_neve, 0, strlen(b_neve), strlen(b_neve)+1);
        }
    Bejaratok[bejaratID][b_van] = 1;
        new adatok[500], adatok_eleje[150], str_be[128], str_ki[128];
           new Float:x, Float:y, Float:z, i = GetPlayerInterior(playerid), w = GetPlayerVirtualWorld(playerid);
   GetPlayerPos(playerid, x, y, z);
    Bejaratok[bejaratID][kint_x] = BejaratKeszitoPoz[playerid][b_poz_x];
    Bejaratok[bejaratID][kint_y] = BejaratKeszitoPoz[playerid][b_poz_y];
    Bejaratok[bejaratID][kint_z] = BejaratKeszitoPoz[playerid][b_poz_z];
    Bejaratok[bejaratID][kint_i] = BejaratKeszitoPoz[playerid][b_poz_i];
    Bejaratok[bejaratID][kint_w] = BejaratKeszitoPoz[playerid][b_poz_w];
    Bejaratok[bejaratID][bent_x] = x;
    Bejaratok[bejaratID][bent_y] = y;
    Bejaratok[bejaratID][bent_z] = z;
    Bejaratok[bejaratID][bent_i] = i;
    Bejaratok[bejaratID][bent_w] = w;
    Bejaratok[bejaratID][b_id] = BejaratID;
               BejaratokPickup[bejaratID][0] = CreateDynamicPickup(
           1318,
           23,
           Bejaratok[bejaratID][kint_x],
           Bejaratok[bejaratID][kint_y],
           Bejaratok[bejaratID][kint_z],
           Bejaratok[bejaratID][kint_w],
           Bejaratok[bejaratID][kint_i],
           -1,
           100
      );
      BejaratokPickup[bejaratID][1] = CreateDynamicPickup(
           1318,
           23,
           Bejaratok[bejaratID][bent_x],
           Bejaratok[bejaratID][bent_y],
           Bejaratok[bejaratID][bent_z],
           Bejaratok[bejaratID][bent_w],
           Bejaratok[bejaratID][bent_i],
           -1,
           100
      );
               format(str_be, sizeof(str_be), \"{339933}[bejárat]\\n{33cc66}%s\", BejaratokNeve[bejaratID]);
               format(str_ki, sizeof(str_ki), \"{339933}[Kijárat]\\n{33cc66}%s\", BejaratokNeve[bejaratID]);
               Bejaratok3D[bejaratID][0] = CreateDynamic3DTextLabel(
         str_be,
         -1,
         Bejaratok[bejaratID][kint_x],
                   Bejaratok[bejaratID][kint_y],
                   Bejaratok[bejaratID][kint_z]+0.7,
         30,
         INVALID_PLAYER_ID,
         INVALID_VEHICLE_ID,
         1,
         Bejaratok[bejaratID][kint_w],
         Bejaratok[bejaratID][kint_i],
         -1,
         100
      );
      Bejaratok3D[bejaratID][1] = CreateDynamic3DTextLabel(
         str_ki,
         -1,
         Bejaratok[bejaratID][bent_x],
                   Bejaratok[bejaratID][bent_y],
                   Bejaratok[bejaratID][bent_z]+0.7,
         30,
         INVALID_PLAYER_ID,
         INVALID_VEHICLE_ID,
         1,
         Bejaratok[bejaratID][bent_w],
         Bejaratok[bejaratID][bent_i],
         -1,
         100
      );
 
   adatok_eleje = \"INSERT INTO `bejaratok` (`id`,`kint_x`,`kint_y`,`kint_z`,`kint_i`,`kint_w`,`bent_x`,`bent_y`,`bent_z`,`bent_i`,`bent_w`,`nev`) VALUES \";
           format(adatok,sizeof(adatok),\"%s(\'%i\',\'%f\',\'%f\',\'%f\',\'%i\',\'%i\',\'%f\',\'%f\',\'%f\',\'%i\',\'%i\',\'%s\')\",\\
           adatok_eleje,
         Bejaratok[bejaratID][b_id],
   Bejaratok[bejaratID][kint_x],
   Bejaratok[bejaratID][kint_y],
   Bejaratok[bejaratID][kint_z],
   Bejaratok[bejaratID][kint_i],
   Bejaratok[bejaratID][kint_w],
   Bejaratok[bejaratID][bent_x],
   Bejaratok[bejaratID][bent_y],
   Bejaratok[bejaratID][bent_z],
   Bejaratok[bejaratID][bent_i],
   Bejaratok[bejaratID][bent_w],
   BejaratokNeve[bejaratID]);
         mysql_query(adatok);
           FMSG(playerid, \"Új bejárat lerakva! (#%d)\", BejaratID);
           BejaratKeszito[playerid] = false;
      return 1;
      }
   return 1;
}

 
Egyéb parancsok:  /bejaratdel (Bejárat törlése) /bejaratgo (Teleport bejárathoz) /bejaratclosest (Legközelebbi bejárat ID-je.)
 
CMD:bejaratdel(playerid, params[])
{
   new delid;
   if(sscanf(params, \"i\", delid)) return MSG(playerid, \"Használat: /bejaratdel [ Bejárat ID ]\");
   else
   {
                    if(BejaratokPickup[delid][0]) DestroyDynamicPickup(BejaratokPickup[delid][0]);
                       if(BejaratokPickup[delid][1]) DestroyDynamicPickup(BejaratokPickup[delid][1]);
                       if(Bejaratok3D[delid][0]) DestroyDynamic3DTextLabel(Bejaratok3D[delid][0]);
                       if(Bejaratok3D[delid][1]) DestroyDynamic3DTextLabel(Bejaratok3D[delid][1]);
                       BejaratokNeve[delid] = \"\";
                       Bejaratok[delid][kint_x] = 0;
                       Bejaratok[delid][kint_y] = 0;
                       Bejaratok[delid][kint_z] = 0;
                       Bejaratok[delid][kint_i] = 0;
                       Bejaratok[delid][kint_w] = 0;
                       Bejaratok[delid][bent_x] = 0;
                       Bejaratok[delid][bent_y] = 0;
                       Bejaratok[delid][bent_z] = 0;
                       Bejaratok[delid][bent_i] = 0;
                       Bejaratok[delid][bent_w] = 0;
                       Bejaratok[delid][b_id] = 0;
                       Bejaratok[delid][b_van] = 0;
                       new string[64];
                       format(string, sizeof(string), \"DELETE FROM `samp`.`bejaratok` WHERE `bejaratok`.`id` = %d\", delid);
                       mysql_query(string);
           }
return 1;
}
CMD:bejaratclosest(playerid, params[])
{
 new bejaratid = GetClosestBejarat(playerid);
 new Float:distance = GetDistanceToBejarat(playerid, bejaratid);
 FMSG(playerid, \"Legközelebbi bejárat: ID(#%d)  Távolság: %.2f\", bejaratid, distance);
return 1;
}
CMD:bejaratgo(playerid, params[])
{
 new iden;
 if(sscanf(params, \"i\", iden)) return MSG(playerid, \"/gobejarat [id]\");
 else
 {
   if(Bejaratok[iden][b_van] == 0) return MSG(playerid, \"Nincs ilyen bejárat.\");
   SetPlayerVirtualWorld(playerid, Bejaratok[iden][kint_w]);
   SetPlayerInterior(playerid, Bejaratok[iden][kint_i]);
       SetPlayerPos(playerid, Bejaratok[iden][kint_x], Bejaratok[iden][kint_y], Bejaratok[iden][kint_z]);
 }
return 1;
}

 

public OnPlayerPickUpPickup(playerid, pickupid)
{
   for(new i = 0;i < sizeof(BejaratokPickup);i++)
{
if(
   IsPlayerInRangeOfPoint(playerid,2,Bejaratok[kint_x],Bejaratok[kint_y],Bejaratok[kint_z])
   &&
   GetPlayerVirtualWorld(playerid) == Bejaratok[kint_w]
)
{
         GameTextForPlayer(playerid, \"~u~ ~w~Belépéshez: ~g~~h~ALT ~u~\", 5000, 5);
   return 1;
}
}
for(new i = 0;i < sizeof(BejaratokPickup);i++)
{
if(
   IsPlayerInRangeOfPoint(playerid,2,Bejaratok[bent_x],Bejaratok[bent_y],Bejaratok[bent_z])
   &&
   GetPlayerVirtualWorld(playerid) == Bejaratok[bent_w]
)
{
           GameTextForPlayer(playerid, \"~d~ ~w~Kilépéshez: ~g~~h~ALT ~d~\", 5000, 5);
   return 1;
}
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{     
  if(PRESSED(KEY_WALK))
  {
        for(new i = 0;i < sizeof(BejaratokPickup);i++)
   {
   if(
      IsPlayerInRangeOfPoint(playerid,2,Bejaratok[kint_x],Bejaratok[kint_y],Bejaratok[kint_z])
      &&
      GetPlayerVirtualWorld(playerid) == Bejaratok[kint_w]
      &&
      GetPlayerInterior(playerid) == Bejaratok[kint_i]
      )
         {
            SetPlayerPos(playerid,Bejaratok[bent_x],Bejaratok[bent_y],Bejaratok[bent_z]);
            SetPlayerInterior(playerid,Bejaratok[bent_i]);
            SetPlayerVirtualWorld(playerid,Bejaratok[bent_w]);
            SetCameraBehindPlayer(playerid);
            return 1;
         }
      }
               for(new i = 0;i < sizeof(BejaratokPickup);i++)
      {
         if(
               IsPlayerInRangeOfPoint(playerid,2,Bejaratok[bent_x],Bejaratok[bent_y],Bejaratok[bent_z])
               &&
               GetPlayerVirtualWorld(playerid) == Bejaratok[bent_w]
               &&
               GetPlayerInterior(playerid) == Bejaratok[bent_i]
           )
         {
            SetPlayerPos(playerid,Bejaratok[kint_x],Bejaratok[kint_y],Bejaratok[kint_z]);
            SetPlayerInterior(playerid,Bejaratok[kint_i]);
            SetPlayerVirtualWorld(playerid,Bejaratok[kint_w]);
            return 1;
         }
      }
  return 1;
  }
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
   if(dialogid == DIALOG_BEJARAT)
   {
 if(response)
 {
       new Float:pozi_x, Float:pozi_y, Float:pozi_z, pozi_i, pozi_w;
   GetPlayerPos(playerid, pozi_x, pozi_y, pozi_z);
   pozi_i = GetPlayerInterior(playerid);
   pozi_w = GetPlayerVirtualWorld(playerid);
   BejaratKeszitoPoz[playerid][b_poz_x] = pozi_x;
   BejaratKeszitoPoz[playerid][b_poz_y] = pozi_y;
   BejaratKeszitoPoz[playerid][b_poz_z] = pozi_z;
   BejaratKeszitoPoz[playerid][b_poz_i] = pozi_i;
   BejaratKeszitoPoz[playerid][b_poz_w] = pozi_w;
   BejaratKeszito[playerid] = true;
   MSG(playerid, \"Ez kész van. Most menj el oda, ahova a kijáratot szeretnéd, majd írd be ezt: /bejarat [bejárat neve]\");
 }
      return 1;
   }
return 1;
}

 
Függvény: BetoltBejaratok(); Szépen újratölti az adatokat.
 
stock BetoltBejaratok()
{
           TorolIGObjectek();
           new count = 0;
        while (count < sizeof(Bejaratok))
        {
        new where[32];
        format(where, sizeof(where), \"id=\'%d\'\", count);
               if(Mysql_Num(\"bejaratok\", where) == 1)
               {
           Bejaratok[count][b_van] = 1;
       }
        else
      {
           Bejaratok[count][b_van] = 0;
       }
        if(Bejaratok[count][b_van] == 1)
        {
                   new query[128];
                   format(query, sizeof(query), \"SELECT * FROM `bejaratok` WHERE %s\", where);
           mysql_query(query);
           new datas[256], data[12][6];
           mysql_store_result();
           mysql_fetch_row(datas);
           mysql_free_result();
           split(datas, data, \'|\');
               Bejaratok[count][b_id] = strval(data[0]);
               Bejaratok[count][kint_x] = floatstr(data[1]);
               Bejaratok[count][kint_y] = floatstr(data[2]);
               Bejaratok[count][kint_z] = floatstr(data[3]);
               Bejaratok[count][kint_i] = strval(data[4]);
               Bejaratok[count][kint_w] = strval(data[5]);
               Bejaratok[count][bent_x] = floatstr(data[6]);
               Bejaratok[count][bent_y] = floatstr(data[7]);
               Bejaratok[count][bent_z] = floatstr(data[8]);
               Bejaratok[count][bent_i] = strval(data[9]);
               Bejaratok[count][bent_w] = strval(data[10]);
               strmid(BejaratokNeve[count], data[11], 0, strlen(data[11])+1, strlen(data[11])+1);
               Bejaratok[count][b_van] = 1;
               BejaratokPickup[count][0] = CreateDynamicPickup(
           1318,
           23,
           Bejaratok[count][kint_x],
           Bejaratok[count][kint_y],
           Bejaratok[count][kint_z],
           Bejaratok[count][kint_w],
           Bejaratok[count][kint_i],
           -1,
           100
      );
      BejaratokPickup[count][1] = CreateDynamicPickup(
           1318,
           23,
           Bejaratok[count][bent_x],
           Bejaratok[count][bent_y],
           Bejaratok[count][bent_z],
           Bejaratok[count][bent_w],
           Bejaratok[count][bent_i],
           -1,
           100
      );
               new str_be[128], str_ki[128];
               format(str_be, sizeof(str_be), \"{339933}[bejárat]\\n{33cc66}%s\", BejaratokNeve[count]);
               format(str_ki, sizeof(str_ki), \"{339933}[Kijárat]\\n{33cc66}%s\", BejaratokNeve[count]);
               Bejaratok3D[count][0] = CreateDynamic3DTextLabel(
         str_be,
         -1,
         Bejaratok[count][kint_x],
                   Bejaratok[count][kint_y],
                   Bejaratok[count][kint_z]+0.7,
         30,
         INVALID_PLAYER_ID,
         INVALID_VEHICLE_ID,
         1,
         Bejaratok[count][kint_w],
         Bejaratok[count][kint_i],
         -1,
         100
      );
      Bejaratok3D[count][1] = CreateDynamic3DTextLabel(
         str_ki,
         -1,
         Bejaratok[count][bent_x],
                   Bejaratok[count][bent_y],
                   Bejaratok[count][bent_z]+0.7,
         30,
         INVALID_PLAYER_ID,
         INVALID_VEHICLE_ID,
         1,
         Bejaratok[count][bent_w],
         Bejaratok[count][bent_i],
         -1,
         100
      );
           }
   count++;
   }
return 1;
}

 
Egyéb függvények, melyekre szükségünk lesz. Van ami SeeRPG mod átalakítás. Credit: Rolee
 
stock split(const strsrc[], strdest[][], delimiter)
{
   new i, li;
   new aNum;
   new len;
   while(i <= strlen(strsrc)){
       if(strsrc==delimiter || i==strlen(strsrc)){
           len = strmid(strdest[aNum], strsrc, li, i, 128);
           strdest[aNum][len] = 0;
           li = i+1;
           aNum++;
       }
       i++;
   }
   return 1;
}
stock Mysql_Num(tabla[], ahol[])
{
new query[256], num;
format(query, sizeof(query), \"SELECT * FROM `%s` WHERE %s\", tabla, ahol);
mysql_query(query);
mysql_store_result();
num = mysql_num_rows();
mysql_free_result();
return num;
}
stock TorolIGObjectek()
{
       for(new i = 0;i < sizeof(Bejaratok);i++)
       {
           if(BejaratokPickup[0]) DestroyDynamicPickup(BejaratokPickup[0]);
           if(BejaratokPickup[1]) DestroyDynamicPickup(BejaratokPickup[1]);
           if(Bejaratok3D[0]) DestroyDynamic3DTextLabel(Bejaratok3D[0]);
           if(Bejaratok3D[1]) DestroyDynamic3DTextLabel(Bejaratok3D[1]);
           BejaratokNeve = \"\";
           Bejaratok[kint_x] = 0;
           Bejaratok[kint_y] = 0;
           Bejaratok[kint_z] = 0;
           Bejaratok[kint_i] = 0;
           Bejaratok[kint_w] = 0;
           Bejaratok[bent_x] = 0;
           Bejaratok[bent_y] = 0;
           Bejaratok[bent_z] = 0;
           Bejaratok[bent_i] = 0;
           Bejaratok[bent_w] = 0;
           Bejaratok[b_id] = 0;
           Bejaratok[b_van] = 0;
       }
}
stock UresBejaratHely()
{
new hely = -1;
for(new x = 0; x < sizeof(Bejaratok); x++)
{
    if(x==0) continue;
if(Bejaratok
  • [b_van] != 1)

{
   hely = x;
   break;
}
}
return hely;
}
 
const Float:INF_FLOAT=Float:0x7F800000;
stock Float:GetDistanceToBejarat(playerid, bejarat)
{
if (IsPlayerConnected(playerid) && Bejaratok[bejarat][b_van])
{
return GetDistanceToPoint(playerid, Bejaratok[bejarat][kint_x], Bejaratok[bejarat][kint_y], Bejaratok[bejarat][kint_z]);
}
return INF_FLOAT;
}
stock GetClosestBejarat(playerid)
{
if(IsPlayerConnected(playerid))
{
new kozelibejarat = -1;
new Float:closestdist = 9999.0, Float:dist;
for(new bejarat=0; bejarat< sizeof(Bejaratok); bejarat++)
{
   dist = GetDistanceToBejarat(playerid, bejarat);
   if(dist < closestdist)
   {
      closestdist = dist;
      kozelibejarat = bejarat;
   }
}
return kozelibejarat;
}
return -1;
}
forward Float:GetDistanceToPoint(playerid,Float:x1,Float:y1,Float:z1);
stock Float:GetDistanceToPoint(playerid,Float:x1,Float:y1,Float:z1)
{
if (IsPlayerConnected(playerid))
{
new Float:x2,Float:y2,Float:z2;
GetPlayerPos(playerid,x2,y2,z2);
return GetDistanceBetweenPoints(x1,y1,z1,x2,y2,z2);
}
return INF_FLOAT;
}
forward Float:GetDistanceBetweenPoints(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2);
stock Float:GetDistanceBetweenPoints(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
return floatadd(floatadd(floatsqroot(floatpower(floatsub(x1,x2),2)),floatsqroot(floatpower(floatsub(y1,y2),2))),floatsqroot(floatpower(floatsub(z1,z2),2)));
}
forward ResetPlayerBejaratKeszito(playerid);
public ResetPlayerBejaratKeszito(playerid)
{
   BejaratKeszito[playerid] = false;
BejaratKeszitoPoz[playerid][b_poz_x] = 0;
   BejaratKeszitoPoz[playerid][b_poz_y] = 0;
   BejaratKeszitoPoz[playerid][b_poz_z] = 0;
   BejaratKeszitoPoz[playerid][b_poz_i] = 0;
   BejaratKeszitoPoz[playerid][b_poz_w] = 0;
}
« Utoljára szerkesztve: 2013. November 15. - 20:55:44 írta EpicSlash »

Bejárat rendszer [100%] [MySQL]
« Válasz #1 Dátum: 2013. November 15. - 21:17:33 »
0 Show voters
Pont kellett köszi!+

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal