[Tutorial] [TUT]Creating Simple Buyable Houses!
#41

Although this code is abit werid ... after i copied the last part .. its fucked like all over the place, so i fixed it abit..

Code:
#include <a_samp>
#include <dini>

#define MAX_HOUSES 500

enum houseinfo
{
    HouseNames[60], //To save into the file
    HouseCost, //The house cost
    HouseOwner[24], // The house owners Name
    Float:PickupX, // PickupX
    Float:PickupY, //PickupY
    Float:PickupZ, //PickupZ
    Float:TeleX, //The house location
    Float:TeleY, //The house location
    Float:TeleZ, //The house location
    Interior, //The house Interior
    HouseSell, //House sell price
    Owned,
    Virtual
}

new HouseInfo[MAX_HOUSES][houseinfo]; //It saves all the info in this variable.
new HouseCount = -1; //House count
new PickupID[MAX_HOUSES];
new InHouse[MAX_PLAYERS] = -1;

public OnGameModeInit()
{
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

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);
}

public OnPlayerPickUpPickup(playerid, pickupid) //Pickup callback
{
	for(new J; J<MAX_HOUSES; J++) //Loops through all houses
  	{
    	if(pickupid == PickupID[J]) //If the pickupid is one of our house ones
    	{
      		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, "This house is up for sale! 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[175];
			format(str3, sizeof(str3), "%s~n~%s", str, str2);
 			GameTextForPlayer(playerid, str3, 3500, 3);
		}
		return 1;
 	}
  	return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
	if(strcmp("/buy", cmdtext, true, 10) == 0)
  	{
		for(new i; i<MAX_HOUSES; i++)
		{
			if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[i][PickupX], HouseInfo[i][PickupY], HouseInfo[i][PickupZ]))
			{
				new Pname[24]; GetPlayerName(playerid, Pname, 24);
	   			for(new S; S<MAX_HOUSES; S++)
	      		{
					if(!strcmp(dini_Get("Owned.ini", HouseInfo[S][HouseNames]), Pname)) return SendClientMessage(playerid, 0xF60000AA, "You already have a house!");
	    		}
	      		if(GetPlayerMoney(playerid) < HouseInfo[i][HouseCost]) return SendClientMessage(playerid, 0xF60000AA, "You don't have enough money to buy this house");
	        	if(HouseInfo[i][Owned] == 1) return SendClientMessage(playerid, 0xF60000AA, "This house is already owned!");
	         	GivePlayerMoney(playerid, - HouseInfo[i][HouseCost]);
	        	GameTextForPlayer(playerid, "~r~House Purchased!", 2000, 3);
	        	HouseInfo[i][Owned] = 1;
	        	GetPlayerName(playerid, Pname, 24);
	        	format(HouseInfo[i][HouseOwner], 24, "%s", Pname);
	        	dini_Set("Owners.ini", HouseInfo[i][HouseNames], Pname);
			}
			else
			{
                SendClientMessage(playerid, 0xF60000AA, "You are not close enough to a house");
			}
		}
		return 1;
	}
	if (strcmp("/sell", cmdtext, true, 10) == 0)
  	{
    	for(new i; i<MAX_HOUSES; i++)
        {
      		if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[i][PickupX], HouseInfo[i][PickupY], HouseInfo[i][PickupZ]))
      		{
		        new Pname[24]; GetPlayerName(playerid, Pname, 24);
		        if(strcmp(Pname, HouseInfo[i][HouseOwner])) return SendClientMessage(playerid, 0xF60000AA, "You don't own this house!");
		        GivePlayerMoney(playerid, HouseInfo[i][HouseSell]);
		        GameTextForPlayer(playerid, "~r~House Sold!", 2000, 3);
		        HouseInfo[i][Owned] = 0;
		        format(HouseInfo[i][HouseOwner], 24, "0943jt3u9*egjlfd");
		        dini_Unset("Owners.ini", HouseInfo[i][HouseNames]);
			}
		}
		return 1;
	}
  	if (strcmp("/enter", cmdtext, true, 10) == 0)
  	{
    	for(new i; i<MAX_HOUSES; i++)
        {
      		if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[i][PickupX], HouseInfo[i][PickupY], HouseInfo[i][PickupZ]))
        	{
		        new Pname[24]; GetPlayerName(playerid, Pname, 24);
		        if(strcmp(Pname, HouseInfo[i][HouseOwner])) return SendClientMessage(playerid, 0xF60000AA, "You don't own this house!");
		        SetPlayerPos(playerid, HouseInfo[i][TeleX], HouseInfo[i][TeleY], HouseInfo[i][TeleZ]);
		        SetPlayerInterior(playerid, HouseInfo[i][Interior]);
		        InHouse[playerid] = i;
		        SetPlayerVirtualWorld(playerid, HouseInfo[i][Virtual]);
		        SendClientMessage(playerid, 0x00C4F6AA, "You have entered your house");
			}
			else
			{
				SendClientMessage(playerid, 0xF60000AA, "You are not close enough to a house");
			}
		}
		return 1;
	}
  	if (strcmp("/exit", cmdtext, true, 10) == 0)
  	{
	    if(InHouse[playerid] == -1) return SendClientMessage(playerid, 0xF60000AA, "You are not in a house");
	    SetPlayerPos(playerid, HouseInfo[InHouse[playerid]][PickupX], HouseInfo[InHouse[playerid]][PickupY], HouseInfo[InHouse[playerid]][PickupZ]);
	    SetPlayerInterior(playerid, 0);
	    SetPlayerVirtualWorld(playerid, 0);
	    SendClientMessage(playerid, 0x00C4F6AA, "You have exited your house");
	    InHouse[playerid] = -1;
	    return 1;
  	}
  	return 0;
}
Reply


Messages In This Thread
[TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 07:46
Re: [TUT]Creating Simple Buyable Houses! - by SAW-RL - 03.01.2010, 07:48
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 10:25
Re: [TUT]Creating Simple Buyable Houses! - by Niixie - 03.01.2010, 10:28
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 10:41
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 10:45
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 10:47
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 10:48
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 10:49
Re: [TUT]Creating Simple Buyable Houses! - by ClanDBZVegeta - 03.01.2010, 11:04
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 11:12
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 11:18
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 12:29
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 12:43
Re: [TUT]Creating Simple Buyable Houses! - by x-cutter - 03.01.2010, 13:51
Re: [TUT]Creating Simple Buyable Houses! - by Deat_Itself - 03.01.2010, 14:19
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 14:38
Re: [TUT]Creating Simple Buyable Houses! - by HydraX - 03.01.2010, 14:45
Re: [TUT]Creating Simple Buyable Houses! - by HydraX - 03.01.2010, 14:49
Re: [TUT]Creating Simple Buyable Houses! - by kmzr - 03.01.2010, 16:58
Re: [TUT]Creating Simple Buyable Houses! - by kmzr - 03.01.2010, 19:21
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 19:23
Re: [TUT]Creating Simple Buyable Houses! - by Ehab1911 - 03.01.2010, 19:28
Re: [TUT]Creating Simple Buyable Houses! - by kmzr - 03.01.2010, 19:51
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 03.01.2010, 19:53
Re: [TUT]Creating Simple Buyable Houses! - by HydraX - 03.01.2010, 20:44
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 03.01.2010, 22:34
Re: [TUT]Creating Simple Buyable Houses! - by HydraX - 04.01.2010, 01:34
Re: [TUT]Creating Simple Buyable Houses! - by ToPhrESH - 17.07.2010, 11:37
Re: [TUT]Creating Simple Buyable Houses! - by Stefan_Toretto - 17.07.2010, 13:35
Re: [TUT]Creating Simple Buyable Houses! - by Smokey619 - 17.07.2010, 23:05
Re: [TUT]Creating Simple Buyable Houses! - by Scenario - 17.07.2010, 23:37
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 18.07.2010, 00:03
Re: [TUT]Creating Simple Buyable Houses! - by Scenario - 18.07.2010, 00:06
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 18.07.2010, 19:37
Re: [TUT]Creating Simple Buyable Houses! - by Unte99 - 18.07.2010, 23:03
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 19.07.2010, 06:26
Re: [TUT]Creating Simple Buyable Houses! - by Scenario - 19.07.2010, 06:29
Re: [TUT]Creating Simple Buyable Houses! - by multinfs - 13.11.2010, 13:05
Re: [TUT]Creating Simple Buyable Houses! - by iTorran - 28.11.2010, 11:39
Re: [TUT]Creating Simple Buyable Houses! - by Shadow_ - 03.12.2010, 19:39
Re: [TUT]Creating Simple Buyable Houses! - by Mean - 03.12.2010, 21:03
Re: [TUT]Creating Simple Buyable Houses! - by scripter1 - 21.12.2010, 01:41
Re: [TUT]Creating Simple Buyable Houses! - by Tomejus - 02.01.2011, 00:47
Re: [TUT]Creating Simple Buyable Houses! - by -•♥♠♦♣-•Arshavin•-♥♠♦♣•- - 03.01.2011, 13:22
Re: [TUT]Creating Simple Buyable Houses! - by -•♥♠♦♣-•Arshavin•-♥♠♦♣•- - 06.01.2011, 21:21
Re: [TUT]Creating Simple Buyable Houses! - by bami - 27.01.2011, 11:57
Re: [TUT]Creating Simple Buyable Houses! - by MoDee - 12.02.2011, 12:16
Re: [TUT]Creating Simple Buyable Houses! - by Kyro - 15.02.2011, 20:47
Re: [TUT]Creating Simple Buyable Houses! - by [03]Garsino - 09.03.2011, 11:45
Re: [TUT]Creating Simple Buyable Houses! - by Karl[NDZ] - 25.04.2012, 14:39
Re: [TUT]Creating Simple Buyable Houses! - by SwiftKidZ - 02.05.2012, 05:47
Re: [TUT]Creating Simple Buyable Houses! - by Stm - 22.05.2012, 23:50
Re: [TUT]Creating Simple Buyable Houses! - by [HiC]TheKiller - 23.05.2012, 05:39
Re: [TUT]Creating Simple Buyable Houses! - by Wickeed - 15.06.2012, 18:07
Re: [TUT]Creating Simple Buyable Houses! - by tixzor - 16.06.2012, 19:13
Re: [TUT]Creating Simple Buyable Houses! - by Ukko - 18.06.2012, 12:23
Re: [TUT]Creating Simple Buyable Houses! - by Vendicatori - 18.07.2012, 01:19
Re: [TUT]Creating Simple Buyable Houses! - by Unirom Shaw - 18.07.2012, 02:22
Re: [TUT]Creating Simple Buyable Houses! - by Songason - 19.07.2012, 13:14
Re: [TUT]Creating Simple Buyable Houses! - by SwisherSweet - 02.10.2012, 03:25
Re: [TUT]Creating Simple Buyable Houses! - by Lordzy - 02.10.2012, 04:56
Re: [TUT]Creating Simple Buyable Houses! - by Ghost_Boii - 02.10.2012, 06:44
Re: [TUT]Creating Simple Buyable Houses! - by Hade. - 30.10.2012, 11:25
Re: [TUT]Creating Simple Buyable Houses! - by RieTzz - 18.02.2013, 09:05
Respuesta: [TUT]Creating Simple Buyable Houses! - by Cerealguy - 28.10.2013, 01:13
Respuesta: [TUT]Creating Simple Buyable Houses! - by DanDRT - 28.10.2013, 11:08
Re: [TUT]Creating Simple Buyable Houses! - by Jardell - 28.10.2013, 11:24
Re: [TUT]Creating Simple Buyable Houses! - by Nostalgia - 28.10.2013, 11:26
Re: [TUT]Creating Simple Buyable Houses! - by proSeryoga - 28.10.2013, 12:16
Re: [TUT]Creating Simple Buyable Houses! - by ZBits - 01.01.2014, 12:08
Re: [TUT]Creating Simple Buyable Houses! - by NikO1 - 01.01.2014, 12:14
Re: [TUT]Creating Simple Buyable Houses! - by Youssef214 - 12.02.2014, 12:38
Re: [TUT]Creating Simple Buyable Houses! - by Slavica - 11.02.2017, 13:13
Re: [TUT]Creating Simple Buyable Houses! - by DiamondGaming - 25.12.2017, 16:18

Forum Jump:


Users browsing this thread: 3 Guest(s)