[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
#42

Hehe, thanks thekiller, I use this in my server, it's kinda unhandy but it's kewl!
Reply
#43

I ran into a slight error. When I try to buy the house, it says I already have a house when I dont.
Reply
#44

hello everyone,

I have a problem. I save player position when he disconnect from server, then he connects I load his positions everything is okey. But when I disconnect in house and later connect and type /exit Command set player pos near some house in beach. What should I do? Everything is okey when I enter house and exit house, but if I disconnect in house and when connect typing /exit I spawn near some other houses... Please help me.

EDIT: Fixed that with virtual world saving.
Reply
#45

I have prob it doesnt even load houses asif there's even no fs so help?

Please respond!
Reply
#46

someone help me guys nothin loads the pickups only commands work :S!
Reply
#47

i'm trying to make a spawn at house cmd, but it wont work.
Can somebody help me with this?

my code:
Code:
new Pname[24]; GetPlayerName(playerid, Pname, 24);
for(new i; i<MAX_HOUSES; i++)
{
if(!strcmp(HouseInfo[i][HouseOwner], Pname, false, sizeof(Pname)))
{
SetPlayerPos(playerid, HouseInfo[i][PickupX], HouseInfo[i][PickupY], HouseInfo[i][PickupZ]);
}
}
Reply
#48

Very thx
Reply
#49

some thing is wrong it says You Already Have A House and i dont ??

can someone help me plz?
Reply
#50

Quote:
Originally Posted by multinfs
Посмотреть сообщение
you know what? im using ur script and all i find is bugs! truckingmissions uses checkpoints and if you go too close to house then load point becomes the house enterance.
Your reply to my post is irrelevant. + If all you find is bugs then I suggest you to fix your scripts. It's not my fault that you use the SetPlayerCheckpoint function when my script clearly uses a checkpoint streamer.
Reply
#51

I get this error
pawn Code:
(851) : warning 219: local variable "PlayerName" shadows a variable at a preceding level
Line 851:
pawn Code:
new PlayerName[24];
Reply
#52

Nice work
Reply
#53

Did i only have this error D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 017: undefined symbol "Invited"
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : warning 215: expression has no effect
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 001: expected token: ";", but found "]"
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 029: invalid expression, assumed zero
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : fatal error 107: too many error messages on one line

HELP PLS
Reply
#54

Quote:
Originally Posted by Stm
View Post
Did i only have this error D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 017: undefined symbol "Invited"
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : warning 215: expression has no effect
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 001: expected token: ";", but found "]"
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : error 029: invalid expression, assumed zero
D:\samp03dsvr_R2_win32\samp03dsvr_R2_win32\gamemod es\User.pwn(157) : fatal error 107: too many error messages on one line

HELP PLS
I cant see any "Invited" variable in the code anywhere. Make sure that you're looking at the right script .
Reply
#55

This is awesome tutorial :O !
Thanks TheKiller!
Reply
#56

Give me picture please
Reply
#57

I tried this tutorial several times, even used the one you uploaded, houses aren't visable at all.
What's wrong? I have no errors when compiling as FS or so.
Reply
#58

you have a tutorial for dcmd?
Reply
#59

Thanks for tutorial, good for begiener like me :P
Reply
#60

I did everything you said but still I get these errors:
Code:
C:\Users\Sonny\Documents\SAMP server\filterscripts\SonnyHouses.pwn(35) : error 010: invalid function or declaration
C:\Users\Sonny\Documents\SAMP server\filterscripts\SonnyHouses.pwn(35 -- 48) : error 010: invalid function or declaration
C:\Users\Sonny\Documents\SAMP server\filterscripts\SonnyHouses.pwn(35 -- 54) : error 025: function heading differs from prototype
C:\Users\Sonny\Documents\SAMP server\filterscripts\SonnyHouses.pwn(35 -- 54) : fatal error 107: too many error messages on one line
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)