Trouble with a simple command! -
Chrillzen - 27.11.2013
pawn Код:
CMD:lockhouse(playerid, params[])
{
new id = IsPlayerNearHouseEnt(playerid);
new id2 = IsPlayerInsideHouse(playerid);
if(id != PlayerInfo[playerid][HouseID] || id2 != PlayerInfo[playerid][HouseID]) return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
if(HouseInfo[id][hLocked] == 1)
{
HouseInfo[id][hLocked] = 0;
GameTextForPlayer(playerid, "~w~house ~g~ UNLOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
else
{
HouseInfo[id][hLocked] = 1;
GameTextForPlayer(playerid, "~w~house ~r~ LOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
return 1;
}
Alright, so the only problem is this line. If I use this line it says that I'm not the owner of the house even if I am.
pawn Код:
if(id != PlayerInfo[playerid][HouseID] || id2 != PlayerInfo[playerid][HouseID]) return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
If I use for example this line it works perfectly. But I want to check if the player is in the house aswell as if he's outside near the entrance of the house.
pawn Код:
if(id != PlayerInfo[playerid][HouseID]) return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
Re: Trouble with a simple command! -
xVIP3Rx - 27.11.2013
I guess IsPlayerInsideHouse(playerid) returns the house id, but what if you aren't in any house, can you show IsPlayerInsideHouse(playerid) or try to check what is it returning ?
pawn Код:
CMD:lockhouse(playerid, params[])
{
new id = IsPlayerNearHouseEnt(playerid);
new id2 = IsPlayerInsideHouse(playerid);
if(id != PlayerInfo[playerid][HouseID] || id2 != PlayerInfo[playerid][HouseID])
{
printf("id = %i", id);
printf("id2 = %i", id2);
printf("HouseID = %i", PlayerInfo[playerid][HouseID]);
return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
}
if(HouseInfo[id][hLocked] == 1)
{
HouseInfo[id][hLocked] = 0;
GameTextForPlayer(playerid, "~w~house ~g~ UNLOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
else
{
HouseInfo[id][hLocked] = 1;
GameTextForPlayer(playerid, "~w~house ~r~ LOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
return 1;
}
Just to debug it, Check if any of them are different and that's where the problem is..
Re: Trouble with a simple command! -
Loot - 27.11.2013
Please show me IsPlayerInsideHouse function.
On a side note, as a tip, checking if the player owns a house via a stored house id, it's a bad choice in my opinion. (what will happen if he owns lots of houses?)
A better way would be to store the owner in a house string, and compare the string to his name:
pawn Код:
// save owner name
new
Owner[MAX_PLAYER_NAME],
name[MAX_PLAYER_NAME]
;
GetPlayerName(playerid, name, sizeof(name));
format(Owner, sizeof(Owner), "%s", name);
HouseInfo[id][hOwner] = Owner;
// ...
// compare 2 strings
stock strmatch(const String1[], const String2[]) // Not sure who made this however.
{
if((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
{
return 1;
}
return 0;
}
// to check:
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strmatch(HouseInfo[id][hOwner], name))
{
// ...
}
else return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
Re: Trouble with a simple command! -
Chrillzen - 27.11.2013
@Loot Players can only own one house atm due to the way it's scripted. However I will change it to string comparing.
I debuged the code..
(when outside)
id1 = 5
id2 = 51
HouseID = 5
(when inside)
id1 = -1
id2 = 5
HouseID = 5
Here's my IsPlayerInsideHouse code:
pawn Код:
IsPlayerInsideHouse(playerid)
{
new hworld = GetPlayerVirtualWorld(playerid);
for(new h = 1; h < sizeof(HouseInfo); h++)
{
if(hworld == HouseInfo[h][hInsideWorld]) return h;
}
return -1;
}
Everytime a house is created the ID of that house sets the InsideWorld.
Re: Trouble with a simple command! -
xVIP3Rx - 27.11.2013
I think that will work..
pawn Код:
CMD:lockhouse(playerid, params[])
{
new id = IsPlayerNearHouseEnt(playerid);
new id2 = IsPlayerInsideHouse(playerid);
if(!GetPlayerInterior(playerid)) // He is outside any house ( interior = 0)
{
if(id != PlayerInfo[playerid][HouseID]) return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
}
else // He isn't outside
{
if(id2 != PlayerInfo[playerid][HouseID])) return SCM(playerid, COLOR_LIGHTRED, "[Error]: You do not own this house.");
}
if(HouseInfo[id][hLocked] == 1)
{
HouseInfo[id][hLocked] = 0;
GameTextForPlayer(playerid, "~w~house ~g~ UNLOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
else
{
HouseInfo[id][hLocked] = 1;
GameTextForPlayer(playerid, "~w~house ~r~ LOCKED", 3000, 6);
PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
new file4[40];
format(file4, sizeof(file4), HPATH, id);
new INI:File = INI_Open(file4);
INI_SetTag(File,"data");
INI_WriteInt(File,"hLocked", HouseInfo[id][hLocked]);
INI_Close(File);
}
return 1;
}
I just check where the player is before checking if he's the owner, If he is outside, Then I don't have to check if he's inside his house(Because he isn't inside any house).. Outside interior is always 0, So I just depend on that and check is he outside or inside any interior before checking if he's the owner
Note: I think you should add that check to your function as well.