05.06.2011, 10:47
Hey guys ....
I wanted to create a house system .....
This is what I got so far ...
forwards
OnGameModeInIt
COMMANDS
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
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
pawn Код:
forward LoadHouse(houseid);
forward SaveHouse(houseid);
forward UpdatePlayerHouseInfo();
forward LoadAllHouses();
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;
}
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