Szerző Téma: Metinkő  (Megtekintve 1209 alkalommal)

Metinkő
« Dátum: 2017. Augusztus 15. - 15:53:49 »
0
Sziasztok valaki, már nem emlékszem, hogy ki, posztolta a fórumra a következő scriptet:
 
#include <a_samp>
#include <zcmd>
#include <streamer>
 
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
 
#define MAX_METIN 100 // Max metin szám.
#define MAX_METIN_HP 10000 // Metin max hp.
#define METIN_OBJECT 888 // A metin objectje.
#define METIN_DRAW_DISTANCE 20.0 // A metin HP label látótávolsága.
#define DAMAGE_CRIT 2 // A kritikus sebzés, az alapsebzés hányszorosa legyen, alapesetben 2.
 
new Metin_ID[MAX_METIN];
new Metin_Object[MAX_METIN];
new Metin_HP[MAX_METIN];
new Float:Metin_Pos[MAX_METIN][3];
new Text3D:Metin_Label[MAX_METIN];
new Count_Metin = 0;
 
public OnFilterScriptInit()
{
 print(\"Metinkő rendszer betöltve ! Készítő: 1Mark6\");
 return 1;
}
 
public OnFilterScriptExit()
{
 for(new i = 0; i < MAX_METIN; i++)
 {
  Metin_ID = -1;
  Metin_HP
= 0;
  Metin_Pos
  • = 0.0;

  Metin_Pos
[1] = 0.0;
  Metin_Pos
[2] = 0.0;
  Count_Metin = 0;

  DestroyDynamicObject(Metin_Object
);
  DestroyDynamic3DTextLabel(Metin_Label
);
 }

 return 1;

}




CMD:metin(playerid)

{

 new id;

 if(GetFreeMetinSlot() != -1) id = GetFreeMetinSlot();

 else id = Count_Metin;



 if(id > MAX_METIN) return SendClientMessage(playerid,-1,\"Nem hozható létre több metin :(\");




 GetPlayerPos(playerid,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2]);

 Metin_Pos[id][0] += 3.0;

 Metin_Object[id] = CreateDynamicObject(METIN_OBJECT,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2],0,0,0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid));

 Metin_HP[id] = MAX_METIN_HP;

 new string[128]; format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",id,MAX_METIN_HP,Metin_HP[id]);

 Metin_Label[id] = CreateDynamic3DTextLabel(string,-1,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2]+1,METIN_DRAW_DISTANCE);

 Metin_ID[id] = id;




 if(id == Count_Metin) Count_Metin++;

 SendClientMessage(playerid,-1,\"Metin létrehozva !\");

 return 1;

}




public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)

{

 if(PRESSED(KEY_FIRE))

 {

  for(new i = 0; i < Count_Metin; i++)

  {

   if(IsPlayerInRangeOfPoint(playerid,2.0,Metin_Pos
  • ,Metin_Pos[1],Metin_Pos[2]) && IsValidDynamicObject(Metin_Object))

   {

    new critvalue;

    new bool:critelt = false;

    new value = RandomEx(1,50); // Alap sebzés ( 1 - 50 )

    new crit = RandomEx(1,10); // Krit esély ( 1:10 )




    // Crit = 10, 1:10-hez a krit esély azaz 10%

    if(crit == 10) {critvalue = DAMAGE_CRIT*value; critelt = true;}

    else {critvalue = value; critelt = false;}




    Metin_HP
-= critvalue;




    new string[128];

    /*

    if(!critelt) format(string,sizeof(string),\"Sebzés(Normál): %d\",critvalue);

    else if(critelt) format(string,sizeof(string),\"Sebzés(Kritikus): %d\",critvalue);

    SendClientMessage(playerid,-1,string);

    */

    format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",Metin_ID
,MAX_METIN_HP,Metin_HP);
    UpdateDynamic3DTextLabelText(Metin_Label
,-1,string);




    if(Metin_HP
<= 0)
    {

     DestroyDynamicObject(Metin_Object
);
     DestroyDynamic3DTextLabel(Metin_Label
);
     SendClientMessage(playerid,-1,\"Metin elpusztítva!\");

     GivePlayerMoney(playerid,RandomEx(1000,2500));

     Metin_ID
= -1;
    }

   }

  }

 }

 return 1;

}




stock RandomEx(min,max) // A min value, és a max value és benne van, tehát ( min <= generáltszám >= max )

{

 return random((max-min)+1)+min;

}




stock GetFreeMetinSlot()

{

 for(new i = 0; i < Count_Metin; i++)

  if(Metin_ID
== -1) return i;
 return -1;

}



 



Ez nagyon is jó, és hasznos is volt, szóval köszönöm neki. Csak azt szeretném, hogy a szerver bekapcsolásakor random helyeken létrehozna mondjuk 20-at, és ha a 20-ból az utolsót is szétütné valaki, újra létrehozódnának random helyeken. Ebben az átalakításban tudna segíteni valaki? Előre is köszönöm 

Metinkő
« Válasz #1 Dátum: 2017. Augusztus 17. - 10:31:37 »
+1


#define RANDOM_METINS      ( 5 )
new Float:RandomCoords[RANDOM_METINS][3] =
{      
{0.0,0.0,0.0},
{0.0,0.0,0.0},
{0.0,0.0,0.0},
{0.0,0.0,0.0},
{0.0,0.0,0.0}
};
CreateRandomMetins()
{
new rand;
for(new i = 0; i < RANDOM_METINS; i++)
{
   rand = random(RANDOM_METINS);
   CreateMetin(RandomCoords[rand][0],RandomCoords[rand][1],RandomCoords[rand][2],0,0);
}
return 1;
}
CreateMetin(Float:X,Float:Y,Float:Z,vw,interior)
{
    new id;
    if(GetFreeMetinSlot() != -1) id = GetFreeMetinSlot();
    else id = Count_Metin;
   
    if(id > MAX_METIN) return SendClientMessage(playerid,-1,\"Nem hozható létre több metin :(\");
   
Metin_Pos[id][0] = X, Metin_Pos[id][1] = Y, Metin_Pos[id][2] = Z;
   
    Metin_Pos[id][0] += 3.0;
    Metin_Object[id] = CreateDynamicObject(METIN_OBJECT,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2],0,0,0,vw,interior);
    Metin_HP[id] = MAX_METIN_HP;
    new string[128]; format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",id,MAX_METIN_HP,Metin_HP[id]);
    Metin_Label[id] = CreateDynamic3DTextLabel(string,-1,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2]+1,METIN_DRAW_DISTANCE);
    Metin_ID[id] = id;
   
    if(id == Count_Metin) Count_Metin++;
    SendClientMessage(playerid,-1,\"Metin létrehozva !\");
    return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_FIRE))
    {    
        for(new i = 0; i < Count_Metin; i++)
        {
            if(IsPlayerInRangeOfPoint(playerid,2.0,Metin_Pos[i][0],Metin_Pos[i][1],Metin_Pos[i][2]) && IsValidDynamicObject(Metin_Object[i]))
            {
                new critvalue;
                new bool:critelt = false;
                new value = RandomEx(1,50); // Alap sebzés ( 1 - 50 )
                new crit = RandomEx(1,10); // Krit esély ( 1:10 )
               
                // Crit = 10, 1:10-hez a krit esély azaz 10%
                if(crit == 10) {critvalue = DAMAGE_CRIT*value; critelt = true;}
                else {critvalue = value; critelt = false;}
           
                Metin_HP[i] -= critvalue;
               
                new string[128];
                if(!critelt) format(string,sizeof(string),\"Sebzés(Normál): %d\",critvalue);
                else if(critelt) format(string,sizeof(string),\"Sebzés(Kritikus): %d\",critvalue);
                SendClientMessage(playerid,-1,string);
               
                format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",Metin_ID[i],MAX_METIN_HP,Metin_HP[i]);
                UpdateDynamic3DTextLabelText(Metin_Label[i],-1,string);
               
                if(Metin_HP[i] <= 0)
                {
            if(Metin_ID[i] == Count_Metin - 1) // Ha az utolsó metin az.
            {
               CreateRandomMetins();
            }
         
                    DestroyDynamicObject(Metin_Object[i]);
                    DestroyDynamic3DTextLabel(Metin_Label[i]);
                    SendClientMessage(playerid,-1,\"Metin elpusztítva!\");
                    GivePlayerMoney(playerid,RandomEx(1000,2500));
                    Metin_ID[i] = -1;
                }
            }
        }
    }
    return 1;
}

 
Nem nagyon értek ehhez a rendszerhez, de valami hasonló elven kellene müküdnie mint ez.

Metinkő
« Válasz #2 Dátum: 2017. Augusztus 18. - 16:58:22 »
0
Köszönöm, működik (Bele írtam pár kordinátát) A gond csak az, hogy egy helyen többet is létrehoz véletlenszerűen, Erre lenne valami ötletetek? 
 
 
 
 

Metinkő
« Válasz #3 Dátum: 2017. Augusztus 18. - 18:02:41 »
+1
Amikor létrehozza a random számot, akkor azt az értéket lemented egy tömbbe. Tehát az a random szám szerepelt, ergó létrevan hozva.
 
És csak szimplán beleépíted a ciklusba még 1 ciklussal, vagy esetleg egy do-while ciklussal, hogyha az újonnan generált szám már szerepel abban az tömbben, ergó létre van hozva, akkor \"continue;\" vagy do-while-ba ezen az elven.
 
És ha elpusztulnak akkor meg reseteled ezt a segéd tömböt is.

Metinkő
« Válasz #4 Dátum: 2017. Augusztus 18. - 20:25:52 »
0
Köszönöm

Metinkő
« Válasz #5 Dátum: 2017. Augusztus 21. - 18:32:20 »
0
Epsilion egyik régi megoldását próbáltam alkalmazni hozzá, de nem sikerült megoldanom. Egy kis segítséget még kaphatok? 

Metinkő
« Válasz #6 Dátum: 2017. Augusztus 21. - 20:52:12 »
0
Mi a probléma?

Metinkő
« Válasz #7 Dátum: 2017. Augusztus 22. - 00:11:25 »
0
A már felhasznált szám átugrása, nem akar összejönni

Metinkő
« Válasz #8 Dátum: 2017. Augusztus 22. - 11:12:46 »
0
Létrehozol, egy Metin_Status[MAX_METIN]; változót, amikor létrehozod akkor ezt az értéket 1-re állítod, ha szétesik akkor 0- ra.
 
És a random metineket meg így hozod létre.
 

CreateRandomMetins()
{
new rand;
for(new i = 0; i < RANDOM_METINS; i++)
{
   do
   {
      rand = random(RANDOM_METINS);
   }
   while(Metin_Status[rand] == 0);
   CreateMetin(RandomCoords[rand][0],RandomCoords[rand][1],RandomCoords[rand][2],0,0);
}
return 1;
}

 
 

Metinkő
« Válasz #9 Dátum: 2017. Augusztus 23. - 01:57:14 »
0
Beraktam, de valamiért nem akar beindulni tőle a szerver. Valami nem oké, de nem jelez warningot 
 
 
 
#include <a_samp>
#include <zcmd>
#include <streamer>
 
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
 
#define MAX_METIN 100 // Max metin szám.
#define MAX_METIN_HP 10000 // Metin max hp.
#define METIN_OBJECT 888 // A metin objectje.
#define METIN_DRAW_DISTANCE 20.0 // A metin HP label látótávolsága.
#define DAMAGE_CRIT 2 // A kritikus sebzés, az alapsebzés hányszorosa legyen, alapesetben 2.
 
new Metin_ID[MAX_METIN];
new Metin_Object[MAX_METIN];
new Metin_HP[MAX_METIN];
new Float:Metin_Pos[MAX_METIN][3];
new Text3D:Metin_Label[MAX_METIN];
new Metin_Status[MAX_METIN];
new Count_Metin = 0;
 
public OnFilterScriptInit()
{
 print(\"Metinkő rendszer betöltve !\");
 CreateRandomMetins();
 return 1;
}
 
public OnFilterScriptExit()
{
 for(new i = 0; i < MAX_METIN; i++)
 {
  Metin_ID = -1;
  Metin_HP
= 0;
  Metin_Pos
  • = 0.0;

  Metin_Pos
[1] = 0.0;
  Metin_Pos
[2] = 0.0;
  Count_Metin = 0;

  DestroyDynamicObject(Metin_Object
);
  DestroyDynamic3DTextLabel(Metin_Label
);
 }

 return 1;

}



#define RANDOM_METINS  ( 7 )




new Float:RandomCoords[RANDOM_METINS][3] =

{

 {-92.4117,66.6368,3.1172},

 {-82.0231,70.6992,3.1172},

 {-72.6411,68.3785,3.6405},

 {-62.0239,72.1258,3.6504},

 {-51.2558,69.1751,3.7222},

 {-43.7977,74.3264,3.9111},

 {-38.4744,68.7825,3.1172}

};




CreateRandomMetins()

{

 new rand;

 for(new i = 0; i < RANDOM_METINS; i++)

 {

  do

  {

   rand = random(RANDOM_METINS);

  }

  while(Metin_Status[rand] == 0);

  CreateMetin(RandomCoords[rand][0],RandomCoords[rand][1],RandomCoords[rand][2],0,0);

 }

 return 1;

}




CreateMetin(Float:X,Float:Y,Float:Z,vw,interior)

{

    new id;

    if(GetFreeMetinSlot() != -1) id = GetFreeMetinSlot();

    else id = Count_Metin;



    if(id > MAX_METIN) return 0;



 Metin_Pos[id][0] = X, Metin_Pos[id][1] = Y, Metin_Pos[id][2] = Z;




    Metin_Pos[id][0] += 3.0;

    Metin_Object[id] = CreateDynamicObject(METIN_OBJECT,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2],0,0,0,vw,interior);

    Metin_HP[id] = MAX_METIN_HP;

    new string[128]; format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",id,MAX_METIN_HP,Metin_HP[id]);

    Metin_Label[id] = CreateDynamic3DTextLabel(string,-1,Metin_Pos[id][0],Metin_Pos[id][1],Metin_Pos[id][2]+1,METIN_DRAW_DISTANCE);

    Metin_ID[id] = id;

    Metin_Status[id] = 1;




    if(id == Count_Metin) Count_Metin++;

    //SendClientMessage(playerid,-1,\"Metin létrehozva !\");

    return 1;

}





public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)

{

 if(PRESSED(KEY_FIRE))

 {

  for(new i = 0; i < Count_Metin; i++)

  {

   if(IsPlayerInRangeOfPoint(playerid,2.0,Metin_Pos
  • ,Metin_Pos[1],Metin_Pos[2]) && IsValidDynamicObject(Metin_Object))

   {

    new critvalue;

    new bool:critelt = false;

    new value = RandomEx(1,50); // Alap sebzés ( 1 - 50 )

    new crit = RandomEx(1,10); // Krit esély ( 1:10 )




    // Crit = 10, 1:10-hez a krit esély azaz 10%

    if(crit == 10) {critvalue = DAMAGE_CRIT*value; critelt = true;}

    else {critvalue = value; critelt = false;}




    Metin_HP
-= critvalue;




    new string[128];

    /*

    if(!critelt) format(string,sizeof(string),\"Sebzés(Normál): %d\",critvalue);

    else if(critelt) format(string,sizeof(string),\"Sebzés(Kritikus): %d\",critvalue);

    SendClientMessage(playerid,-1,string);

    */

    format(string,sizeof(string),\"Metinkő [ID:%d]\\nHP: %d/%d\",Metin_ID
,MAX_METIN_HP,Metin_HP);
    UpdateDynamic3DTextLabelText(Metin_Label
,-1,string);




    if(Metin_HP
<= 0)
    {

        if(Metin_ID
== Count_Metin - 1) // Ha az utolsó metin az.
     {

      CreateRandomMetins();

     }

     DestroyDynamicObject(Metin_Object
);
     DestroyDynamic3DTextLabel(Metin_Label
);
     SendClientMessage(playerid,-1,\"Metin elpusztítva!\");

     GivePlayerMoney(playerid,RandomEx(1000,2500));

     Metin_ID
= -1;
     Metin_Status
= 0;
    }

   }

  }

 }

 return 1;

}




stock RandomEx(min,max) // A min value, és a max value és benne van, tehát ( min <= generáltszám >= max )

{

 return random((max-min)+1)+min;

}




stock GetFreeMetinSlot()

{

 for(new i = 0; i < Count_Metin; i++)

  if(Metin_ID
== -1) return i;
 return -1;

}

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal