[Pomoc]Kuca

Započeo zikolukic, Maj 07, 2013, 01:29:41 PRE PODNE

prethodna tema - sledeća tema

0 članova i 2 gostiju pregledaju ovu temu.

Skripta koju koristim:NBE x14
Detaljan opis problema:kako da stavim kucu na prodaju?
Dio skripte:/
Neke slike/video za lakse dobivanje pomoci(neobavezno):/



CitatPosto vidim da mnogi pocetnici u skriptanju postavaljaju iskljucivo pitanja o ovoj temi,odlucio sam vam postati ovaj TUT,

Prvo morate definirati broj kuca koliko ste dodali u MTA IL DEBUGU
Kod: [Izaberi]
#define MAX_HOUSES 200//tu stavite broj kuca

Zatim dodajte;
Kod: [Izaberi]
enum houseinfo
{
    HouseNames[60], //imena kuca
    HouseCost, //cjena kuce
    HouseOwner[24], // vlasnik kuce
    Float:PickupX, // PickupX
    Float:PickupY, //PickupY
    Float:PickupZ, //PickupZ
    Float:TeleX, //lokacija kuce x
    Float:TeleY, //lokacija kuce y
    Float:TeleZ, //lokacija kuce z
    Interior, //interior kuce
    HouseSell, //kuca za sell
    Owned, //1 ako je kuca u vlasnistvu,0 ako nije
    Virtual//posjedovanje vise kuca
}

new HouseInfo[MAX_HOUSES][houseinfo];
new HouseCount = -1;
new PickupID[MAX_HOUSES];
new InHouse[MAX_PLAYERS] = -1;

Sada ubacite vase kuce ispod OnGameModeInit:
primjer
Kod: [Izaberi]
stock CreateHouse(Filename[], Cost, Float:Pickupx, Float:Pickupy, Float:Pickupz, Float:Telex, Float:Teley, Float:Telez, interior, sell)
{
    if(!dini_Exists("Owners.ini"))
    {
        dini_Create("Owners.ini");
    }
  HouseCount ++;
  new ID = HouseCount; //HouseID
  format(HouseInfo[ID][HouseNames], 60, "%s", Filename); //Saves the HouseName into a variable
  HouseInfo[ID][HouseCost] = Cost;
  HouseInfo[ID][PickupX] = Pickupx;
  HouseInfo[ID][Virtual] = 2000000 + ID;
  HouseInfo[ID][PickupY] = Pickupy;
  HouseInfo[ID][PickupZ] = Pickupz;
  HouseInfo[ID][TeleX] = Telex;
  HouseInfo[ID][TeleY] = Teley;
  HouseInfo[ID][TeleZ] = Telez;
  HouseInfo[ID][Interior] = interior;
  HouseInfo[ID][HouseSell] = sell;
  format(HouseInfo[ID][HouseOwner], 24, "gj9043jg-er((23");
    if(strlen(dini_Get("Owners.ini", Filename))) //This is to see if there is any owner.
    {
    format(HouseInfo[ID][HouseOwner], 24, "%s", dini_Get("Owners.ini", Filename));
    HouseInfo[ID][Owned] = 1;
    }
  PickupID[ID] = CreatePickup(1273, 23, Pickupx, Pickupy, Pickupz, -1); //Creates the pickup :).
  Create3DTextLabel("House", 0x00A0F6AA, Pickupx, Pickupy, Pickupz + 0.75, 15.0, 0, 1);
}
}

FileName - spremanje vase kuce (save as)
Cost - cjena kuce
Pickupx - x lokacija
Pickupy - y lokacija
Pickupz - z lokacija
Telex - x tele lokacija
Teley - y tele lokacija
Telez - z tele lokacija
interior - interior kuce
sell - sell kuce

Sada ubacite pod OnPlayerPickUpPickup ovaj kod koji provjerava  dali je vasa kuca
Kod: [Izaberi]
{
  for(new J; J<MAX_HOUSES; J++) //sve kuce
  {
    if(pickupid == PickupID[J]) //provjerava pickup
    {
      new str[75];
      if(HouseInfo[J][Owned] == 1)
      {
        format(str, sizeof(str), "~r~House Info~n~~g~Owner: ~w~%s", HouseInfo[J][HouseOwner]);
      }
      if(HouseInfo[J][Owned] == 0)
      {
        format(str, sizeof(str), "~r~House Info~n~~g~Owner: ~w~Nobody");
        SendClientMessage(playerid, 0x67F6F6AA, "Kuca je na prodaju! Type /buy to buy it");
      }
      new str2[100];
      format(str2, sizeof(str2), "~g~Cost price:~w~ %d ~n~~g~Sell Price:~w~ %d", HouseInfo[J][HouseCost], HouseInfo[J][HouseSell]);
      new str3[150];
      format(str3, sizeof(str3), "%s~n~%s", str, str2);
      GameTextForPlayer(playerid, str3, 3500, 3);
      return 1;
    }
  }
  return 1;
}

Nakon toga dodajte ispod OnPlayerCommandText komande koje ce vam trebat(/buy /sell /enter /exit) 
Kod: [Izaberi]
if (strcmp("/buy", cmdtext, true, 10) == 0)
  {
    for(new i; i<MAX_HOUSES; i++)
    {
      if(!IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PickupX], HouseInfo[PickupY], HouseInfo[PickupZ])) continue;
     
                new Pname[24]; GetPlayerName(playerid, Pname, 24);
                for(new S; S<MAX_HOUSES; S++)
                {
            if(!strcmp(dini_Get("Owned.ini", HouseInfo[HouseNames]), Pname)) return SendClientMessage(playerid, 0xF60000AA, "You already have a house!");
                }
                if(GetPlayerMoney(playerid) < HouseInfo[HouseCost]) return SendClientMessage(playerid, 0xF60000AA, "You don't have enough money to buy this house");
                if(HouseInfo[Owned] == 1) return SendClientMessage(playerid, 0xF60000AA, "Kuca ima vlasnika!");
                GivePlayerMoney(playerid, - HouseInfo[HouseCost]);
        GameTextForPlayer(playerid, "~r~House Purchased!", 2000, 3);
        HouseInfo[Owned] = 1;
        GetPlayerName(playerid, Pname, 24);
        format(HouseInfo[HouseOwner], 24, "%s", Pname);
        dini_Set("Owners.ini", HouseInfo[HouseNames], Pname);
        return 1;
        }
        SendClientMessage(playerid, 0xF60000AA, "Niste dovoljno blizu kuce");
    return 1;
  }
  if (strcmp("/sell", cmdtext, true, 10) == 0)
  {
    for(new i; i<MAX_HOUSES; i++)
        {
      if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PickupX], HouseInfo[PickupY], HouseInfo[PickupZ]))
        {
        new Pname[24]; GetPlayerName(playerid, Pname, 24);
        if(strcmp(Pname, HouseInfo[HouseOwner])) return SendClientMessage(playerid, 0xF60000AA, "Ti ne posjedujes kucu!");
        GivePlayerMoney(playerid, HouseInfo[HouseSell]);
        GameTextForPlayer(playerid, "~r~House Sold!", 2000, 3);
        HouseInfo[Owned] = 0;
        format(HouseInfo[HouseOwner], 24, "0943jt3u9*egjlfd");
        dini_Unset("Owners.ini", HouseInfo[HouseNames]);
        return 1;
            }
        }
    SendClientMessage(playerid, 0xF60000AA, "Niste dovljno blizu kuce");
        return 1;
  }
  return 0;
}

Kod: [Izaberi]
public OnPlayerCommandText(playerid, cmdtext)
{
  if (strcmp("/enter", cmdtext, true, 10) == 0)
  {
    for(new i; i<MAX_HOUSES; i++)
    {
      if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PickupX], HouseInfo[PickupY], HouseInfo[PickupZ]))
        {
        new Pname[24]; GetPlayerName(playerid, Pname, 24);
        if(strcmp(Pname, HouseInfo[HouseOwner])) return SendClientMessage(playerid, 0xF60000AA, "You don't own this house!");
        SetPlayerPos(playerid, HouseInfo[TeleX], HouseInfo[TeleY], HouseInfo[TeleZ]);
        SetPlayerInterior(playerid, HouseInfo[Interior]);
        InHouse[playerid] = i;
        SetPlayerVirtualWorld(playerid, HouseInfo[Virtual]);
        SendClientMessage(playerid, 0x00C4F6AA, "Usao si u kucu");
        return 1;
      }
    }
    SendClientMessage(playerid, 0xF60000AA, "Niste dovoljno blizu kuce");
    return 1;
  }
  if (strcmp("/exit", cmdtext, true, 10) == 0)
  {
    if(InHouse[playerid] == -1) return SendClientMessage(playerid, 0xF60000AA, "Usao si u kucu");
    SetPlayerPos(playerid, HouseInfo[InHouse[playerid]][PickupX], HouseInfo[InHouse[playerid]][PickupY], HouseInfo[InHouse[playerid]][PickupZ]);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid, 0);
    SendClientMessage(playerid, 0x00C4F6AA, "Izasao si iz kuce");
    InHouse[playerid] = -1;
    return 1;
}

napomena:TUT  preuzet sa forum.sa-mp.com..,
« Poslednja izmena: Septembar 29, 2010, 00:12:48 pre podne cristiane »