I need help with my house system
#1

Hey guys ....

I wanted to create a house system .....

This is what I got so far ...

pawn Код:
enum hInfo
{
    Float:hEnterX,
    Float:hEnterY,
    Float:hEnterZ,
    Float:hExitX,
    Float:hExitY,
    Float:hExitZ,
    hInsideInt,
    hInsideVir,
    hOutsideInt,
    hOutsideVir,
    bool:hOwned,
    hOwner[MAX_PLAYER_NAME],
    hPrice,
    hPickup,
    hIcon,
    hVecModel,
    Float:hVecX,
    Float:hVecY,
    Float:hVecZ,
    Float:hVecA
}
new HouseInfo[MAX_HOUSE][hInfo];
new hCar[MAX_HOUSE];//The house car
forwards

pawn Код:
forward LoadHouse(houseid);
forward SaveHouse(houseid);
forward UpdatePlayerHouseInfo();
forward LoadAllHouses();
OnGameModeInIt
pawn Код:
SetTimer("UpdatePlayerHouseInfo",1500,true);
LoadAllHouses();
pawn Код:
public LoadHouse(houseid)
{
    new hString[11];
    format(hString,sizeof(hString),"houses/%d",houseid);
    if(!dini_Exists(hString)) return 0;
    HouseInfo[houseid][hEnterX] = dini_Float(hString, "EnterX");
    HouseInfo[houseid][hEnterY] = dini_Float(hString, "EnterY");
    HouseInfo[houseid][hEnterZ] = dini_Float(hString, "EnterZ");
    HouseInfo[houseid][hExitX] = dini_Float(hString, "ExitX");
    HouseInfo[houseid][hExitY] = dini_Float(hString, "ExitY");
    HouseInfo[houseid][hExitZ] = dini_Float(hString, "ExitZ");
    HouseInfo[houseid][hInsideInt] = dini_Int(hString, "InsideInt");
    HouseInfo[houseid][hInsideVir] = dini_Int(hString, "InsideVir");
    HouseInfo[houseid][hOutsideInt] = dini_Int(hString, "OutsideInt");
    HouseInfo[houseid][hOutsideVir] = dini_Int(hString, "OutsideVir");
    HouseInfo[houseid][hOwned] = dini_Bool(hString, "Owned") ? true : false;
    strmid(HouseInfo[houseid][hOwner], dini_Get(hString, "Owner"), 0, false, strlen(dini_Get(hString,"Owner")));
    HouseInfo[houseid][hPrice] = dini_Int(hString, "Price");
    HouseInfo[houseid][hVecModel] = dini_Int(hString, "HV_Model");
    HouseInfo[houseid][hVecX] = dini_Float(hString, "HV_PosX");
    HouseInfo[houseid][hVecY] = dini_Float(hString, "HV_PosZ");
    HouseInfo[houseid][hVecZ] = dini_Float(hString, "HV_PosZ");
    HouseInfo[houseid][hVecA] = dini_Float(hString, "HV_PosA");
    return 1;
}

public SaveHouse(houseid)
{
    new hString[11];
    format(hString,sizeof(hString),"houses/%d",houseid);
    dini_FloatSet(hString, "EnterX", HouseInfo[houseid][hEnterX]);
    dini_FloatSet(hString, "EnterY", HouseInfo[houseid][hEnterY]);
    dini_FloatSet(hString, "EnterZ", HouseInfo[houseid][hEnterZ]);
    dini_FloatSet(hString, "ExitX", HouseInfo[houseid][hExitX]);
    dini_FloatSet(hString, "ExitY", HouseInfo[houseid][hExitY]);
    dini_FloatSet(hString, "ExitZ", HouseInfo[houseid][hExitZ]);
    dini_IntSet(hString, "InsideInt", HouseInfo[houseid][hInsideInt]);
    dini_IntSet(hString, "InsideVir", HouseInfo[houseid][hInsideVir]);
    dini_IntSet(hString, "OutsideInt", HouseInfo[houseid][hOutsideInt]);
    dini_IntSet(hString, "OutsideVir", HouseInfo[houseid][hOutsideVir]);
    dini_BoolSet(hString, "Owned", HouseInfo[houseid][hOwned]);
    dini_Set(hString, "Owner", HouseInfo[houseid][hOwner]);
    dini_IntSet(hString, "Price", HouseInfo[houseid][hPrice]);
    dini_IntSet(hString, "HV_Model", HouseInfo[houseid][hVecModel]);
    dini_FloatSet(hString, "HV_PosX", HouseInfo[houseid][hVecX]);
    dini_FloatSet(hString, "HV_PosZ", HouseInfo[houseid][hVecY]);
    dini_FloatSet(hString, "HV_PosZ", HouseInfo[houseid][hVecZ]);
    dini_FloatSet(hString, "HV_PosA", HouseInfo[houseid][hVecA]);
}

public UpdatePlayerHouseInfo()
{
    new str[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        for(new h = 0; h < MAX_HOUSE; h++)
        {
            if(IsPlayerInRangeOfPoint(i,1.5, HouseInfo[h][hEnterX], HouseInfo[h][hEnterY], HouseInfo[h][hEnterZ]) && GetPlayerInterior(i) == HouseInfo[h][hOutsideInt] && GetPlayerVirtualWorld(i) == HouseInfo[h][hOutsideVir])
            {
                if(HouseInfo[h][hOwned])
                {
                    format(str,sizeof(str),"~w~ House owned by ~g~ %s",HouseInfo[h][hOwner]);
                }else{
                    format(str,sizeof(str),"~w~ House price %s",HouseInfo[h][hPrice]);
                }
                GameTextForPlayer(i, str, 1000, 3);
            }
           
        }
    }
    return 1;
}

public LoadAllHouses()
{
    new index = 0,hFile[11];
    format(hFile,sizeof(hFile),"houses/%d",index);
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(dini_Exists(hFile))
        {
            LoadHouse(index);
            index++;
            format(hFile,sizeof(hFile),"houses/%d",index);
        }
    }
}

COMMANDS
pawn Код:
if(strcmp(cmd, "/buyhouse", true) == 0)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
        {
            if(HouseInfo[i][hOwned]) return SendClientMessage(playerid, COLOR_RED, "This house is already owned!");
            if(GetPlayerMoney(playerid) < HouseInfo[i][hPrice]) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money for this!");

            HouseInfo[i][hOwned] = true;
            strmid(HouseInfo[i][hOwner], pName, 0, false, strlen(pName));
            GivePlayerMoney(playerid, -HouseInfo[i][hPrice]);
            SendClientMessage(playerid, COLOR_MEDIUMGREEN, "House bought!");
            SaveHouse(i);
            LoadHouseVisual(i, true);
            return 1;
        }else return SendClientMessage(playerid,COLOR_GRAY,"You are not near a house !");
    }
    return 1;
}

if(strcmp(cmd, "/sellhouse", true) == 0)
{
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    for(new i = 0; i < MAX_HOUSE; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1.5, HouseInfo[i][hEnterX], HouseInfo[i][hEnterY], HouseInfo[i][hEnterZ]) && GetPlayerInterior(playerid) == HouseInfo[i][hOutsideInt] && GetPlayerVirtualWorld(playerid) == HouseInfo[i][hOutsideVir])
        {
            if(!strcmp(HouseInfo[i][hOwner], pName, false))
            {
                strmid(HouseInfo[i][hOwner], "For Sale", 0, false, 8);
                HouseInfo[i][hOwned] = false;
                GivePlayerMoney(playerid, HouseInfo[i][hPrice]/2);
                SendClientMessage(playerid, COLOR_MEDIUMGREEN, "House sold!");
                SaveHouse(i);
                LoadHouseVisual(i, true);
                return 1;
            }
         }
    }
    return 1;
}
Few questions / problems

1. How do I set house positions ?

2. Every time that I use /buyhouse it says you are not near a house .... no matter where I am
Reply
#2

1. Make a /tphouse command. /tphouse [houseid]. Then, set the hEnterX, hEnterY and hEnterZ to the position of the player (outside vir+int too)
2. Check 1. and teleport a house. Do /buyhouse at exact the same place.
Reply
#3

First of all thanks .

But what do you mean /tphouse command ?
what should it do ?



You should create a cmd that will create the ini file by the house id ...



Reply
#4

How do I create it
And what will it do?
Reply
#5

pawn Код:
if(!strcmp(cmd, "/tphouse", true))
{
    new Float:pPos[3], house_id;
    GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
    //I don't work with strcmp, don't know how it works anymore. 'house_id' = integer parameter.
    HouseInfo[house_id][hEnterX] = pPos[0];
    HouseInfo[house_id][hEnterY] = pPos[1];
    HouseInfo[house_id][hEnterZ] = pPos[2];
    HouseInfo[house_id][hOutsideInt] = GetPlayerInterior(playerid);
    HouseInfo[house_id][hOutsideVir] = GetPlayerVirtualWorld(playerid);
    SaveHouse(house_id);
    LoadHouseVisual(house_id, true);
    return 1;
}
This will teleport an house

p.s.
Anyone who's English? Is it 'a' or 'an' at the lettre 'h'?
Reply
#6

Can you give me that with DCMD please ? ((I also use sscanf))
That would be cool.
Reply
#7

Thank you. I like DCMD more then STRCMP. ZCMD is even better. I recommend you using ZCMD. Converting from DCMD to ZCMD is easy:

1) Press in your pawno CTRL+H
2) Replace all the 'dcmd_' with 'CMD:'
3) Remove all the dcmd(*) in the OnPlayerCommandText
4) Remove the whole OnPlayerCommandText callback
5) Remove the DCMD #define

Tada. As easy as can be. However, here's the dcmd command:

pawn Код:
dcmd_tphouse(playerid, params[])
{
    new house_id, Float:pPos[3];
    GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
    if(!sscanf(params, "d", house_id)) return SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /tphouse [houseid]");
    HouseInfo[house_id][hEnterX] = pPos[0];
    HouseInfo[house_id][hEnterY] = pPos[1];
    HouseInfo[house_id][hEnterZ] = pPos[2];
    HouseInfo[house_id][hOutsideInt] = GetPlayerInterior(playerid);
    HouseInfo[house_id][hOutsideVir] = GetPlayerVirtualWorld(playerid);
    SaveHouse(house_id);
    LoadHouseVisual(house_id, true);
    return 1;
}
Reply
#8

Cool will do that.
Thanks
But how do I set the house exit ?

same thing ? just another CMD ?


This is a preview for my CMD's
Just for testing
pawn Код:
dcmd_henter(playerid, params[])
{
    new id,inte,price;
    if(!sscanff(params,"iii",id,inte,price))
    {
        new Float:pPos[3];
        GetPlayerPos(playerid,pPos[0],pPos[1],pPos[2]);
        HouseInfo[id][hInsideInt] = inte;
        HouseInfo[id][hEnterX] = pPos[0];
        HouseInfo[id][hEnterY] = pPos[1];
        HouseInfo[id][hEnterZ] = pPos[2];
        HouseInfp[id][hPickup] = 1273;
        HouseInfo[id][hPrice] = price;
        HouseInfo[id][hOutsideVir] = id;
    }
    return 1;
}

dcmd_hexit(playerid, params[])
{
            if(!sscanf(params,"i",id))
            {
            new id;
        new Float:pPos[3];
        GetPlayerPos(playerid,pPos[0],pPos[1],pPos[2]);
        HouseInfo[id][hEexitX] = pPos[0];
        HouseInfo[id][hExitY] = pPos[1];
        HouseInfo[id][hExitrZ] = pPos[2];
        HouseInfo[id][hOutsideInt] = 0;
        HouseInfo[id][hOutsideVir] = 0;
    SaveHouse(d);
    LoadHouseVisual(id, true);
           }
        return 1;
}
pawn Код:
 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)