[TUT] Komanda /kaciga

Započeo LoOdaK, Avgust 27, 2016, 02:58:54 PRE PODNE

prethodna tema - sledeća tema

0 članova i 1 gost pregledaju ovu temu.


OVO JE MOJ PRVI TUTORIJAL I ZNAM DA NIJE NESTO ALI VALDA CE POMOCI NEKOM

- Za ovaj tutorijal vam je potreban YSI Pack a koristicemo YCMD kao procesor komandi

- Kao sto mozete vidjeti po naslovu teme radi se o tutorijalu " Kako napraviti komandu /kaciga"
- Komandu nije tesko napraviti, a ja cu se potruditi da sto bolje objasnim, Pa da krenemo:


1. Korak

Prvo moramo da definisemo varijablu koja ce zapisivati da li igrac ima kacigu ili nema tj. da li je stavio ili nije

Na vrh skripte gdje su vam ostali new, dodajte ovo
[pawn]new Kaciga[MAX_PLAYERS][/pawn]


2. Korak

Kada smo to odradili pritisnete CTRL + F na vasoj tastaturi i nadjete public OnPlayerConnect

Kada ste nasli dodajte ovo:
[pawn]Kaciga[playerid] = 0;[/pawn]

Ovo sto smo dodali iznad ce igracu uvijek kada se konektuje na server stavljati varijablu na 0 tj. da nema stavljenu kacigu


3. Korak

Prelazimo na komandu
[pawn]YCMD:kaciga(playerid,params[], help)
{
   new string[60];
   if(!IsABike(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,SIVA," Morate biti na motoru da biste stavili kacigu !!");
   if(Kaciga[playerid] == 1)
   {
      Kaciga[playerid] = 0;
       format(string,sizeof(string)," %s je skinuo kacigu sa svoje glave (/kaciga).",GetName(playerid));
       ProxDetector(30.0, playerid, string, PROX,PROX,PROX,PROX,PROX);
       RemovePlayerAttachedObject(playerid, 9);
   }
   else if(Kaciga[playerid] == 0)
   {
      Kaciga[playerid] = 1;
      format(string,sizeof(string)," %s stavlja kacigu na svoju glavu (/kaciga).",GetName(playerid));
      ProxDetector(30.0, playerid, string, PROX,PROX,PROX,PROX,PROX);
      SetPlayerAttachedObject(playerid, 9, 18976, 2, 0.07, 0.04, 0, 88, 75);
   }
   return 1;
}[/pawn]

Sada cu pokusati da objasnim sto bolje

[pawn]new string[60];[/pawn]

Definisali smo string koji cemo kasnije koristiti

[pawn]if(!IsABike(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,SIVA," Morate biti na motoru da biste stavili kacigu !!");[/pawn]

Ovdje provjeravamo ako igrac nije na motoru/biciklu da ne moze staviti kacigu

[pawn]if(Kaciga[playerid] == 1)
{[/pawn]

Ovdje smo izvrsili provjeru ako igrac ima kacigu pa ova otvorena zagrada obiljezava pocetak dogadjaja koji ce se desiti ako ima kacigu

[pawn]Kaciga[playerid] = 0;[/pawn]

Postavlja varijablu kacige na 0 tj. da je ne nosi

[pawn]format(string,sizeof(string)," %s je skinuo kacigu sa svoje glave (/kaciga).",GetName(playerid));[/pawn]

Ovo je onaj string koji smo definisali ovdje ispisujemo poruku da je neko skinuo kacigu sa glave ( taj neko je igrac )

[pawn]ProxDetector(30.0, playerid, string, PROX,PROX,PROX,PROX,PROX);[/pawn]

Ovo je funkcija ProxDetector koja u odredjenom range-u ce slati onaj gore string

[pawn]RemovePlayerAttachedObject(playerid, 9);[/pawn]

Ovo skida igracevu kacigu sa glave tj. uklanja objekat kacige

[pawn]else if(Kaciga[playerid] == 0)
{[/pawn]

Gore smo imali provjeru ako igrac ima kacigu..... ,a ovo provjerava a ako igrac nema kacigu sta ce da se desi

[pawn]Kaciga[playerid] = 1;[/pawn]

Postavlja varijablu kacige igracu na 1 tj. da nosi kacigu

[pawn]format(string,sizeof(string)," %s stavlja kacigu na svoju glavu (/kaciga).",GetName(playerid));[/pawn]

Formatira se onaj gore string i kaze da neko stavlja kacigu na glavu..

[pawn]ProxDetector(30.0, playerid, string, PROX,PROX,PROX,PROX,PROX);[/pawn]

Ponovo ProxDetector salje string u odredjenom range-u

[pawn]SetPlayerAttachedObject(playerid, 9, 18976, 2, 0.07, 0.04, 0, 88, 75);[/pawn]

Postavlja se objekat kacige na glavu


4. Korak

Ovo dodajte kod ostalih stockova

STOCK ISABIKE

[pawn]stock IsABike(vehid)
{
    new modelid = GetVehicleModel(vehid);
   if (modelid == 448 || modelid == 461 || modelid == 462 || modelid == 463 || modelid == 468 || modelid == 471 || modelid == 521 || modelid == 522 || modelid == 523 || modelid == 581 || modelid == 586)
   {
      return 1;
   }
   return 0;
}[/pawn]

STOCK GETNAME

[pawn]stock GetName(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}[/pawn]

Public PROXDETECTOR

[pawn]forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);
public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
   if(IsPlayerConnected(playerid))
   {
      new Float:posx, Float:posy, Float:posz;
      new Float:oldposx, Float:oldposy, Float:oldposz;
      new Float:tempposx, Float:tempposy, Float:tempposz;
      GetPlayerPos(playerid, oldposx, oldposy, oldposz);
      for(new i = 0; i < MAX_PLAYERS; i++)
      {
         if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
         {
               GetPlayerPos(i, posx, posy, posz);
               tempposx = (oldposx -posx);
               tempposy = (oldposy -posy);
               tempposz = (oldposz -posz);
               if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
               {
                  SendClientMessage(i, col1, string);
               }
               else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
               {
                  SendClientMessage(i, col2, string);
               }
               else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
               {
                  SendClientMessage(i, col3, string);
               }
               else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
               {
                  SendClientMessage(i, col4, string);
               }
               else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
               {
                  SendClientMessage(i, col5, string);
               }
         }   }
      }
   return 1;
}[/pawn]


TO JE BILO TO ZA OVAJ TUTORIJAL
[/b]

MOGUCE JE DA IMA GRESAKA RECITE DA ISPRAVIM
[/b]
BY LOODAK <3
[/b]
CitatElectric Power is everywhere present in unlimited quantities and can drive the world's machinery without the need of coal, oil, gas, or any other of the common fuels!



Dobar tut, sviÄ'a mi se, sve pohvale ;)

"They have computers, and they may have other weapons of mass destruction."



Tenks to al  :D  :D
CitatElectric Power is everywhere present in unlimited quantities and can drive the world's machinery without the need of coal, oil, gas, or any other of the common fuels!





Hvala svjema  :D  :D  :D
CitatElectric Power is everywhere present in unlimited quantities and can drive the world's machinery without the need of coal, oil, gas, or any other of the common fuels!



Pohvale :D

Nova Kuca Community - Founder , Owner

Pohvale  :D
• G A M E M O D E •
• F I L T E R S C R I P T •
• T U T O R I A L •


Citat
You are what you believe yoursefl to be.