COMMAND:biz(playerid, params[])
{
if (PlayerInfo[playerid][LoggedIn] == false) return true;
new string[128], param[64], amount, amount2;
if(sscanf(params, "s[64]I(-1)I(-1)", param, amount, amount2))
{
scm(playerid, COLOR_GREEN, "/biz [usage]");
scm(playerid, COLOR_GREY, " plant | edit | select |");
}
if(strcmp(param, "plant", true) == 0)
{
new allow = FurnRight(playerid, 1);
if(allow > 0) {
if(amount == (-1)) {
ShowModelSelectionMenuEx(playerid, FurnObjs, sizeof(FurnObjs), "Furniture List", 8, 16.0, 0.0, -55.0);
} else {
if(amount < 320 || amount > 35000) return scm(playerid, -1, "Invalid Object ID!");
if(GetPlayerInterior(playerid) == 0 && GetPlayerVirtualWorld(playerid) == 0 && IsInvalidObjectID(amount)) return scm(playerid, -1, "This is not a valid outdoor furniture object!");
new foundid = -1;
for(new i = 0; i < MAX_OBJECT_ARRAY; i++) {
if(ObjectList[i][oID] == amount) {
foundid=i;
break;
}
}
if(foundid == -1) return scm(playerid, -1, "Invalid Object ID!");
new Float:X, Float:Y, Float:Z, obj = 0;
GetPlayerPos(playerid, X, Y, Z);
obj = CreatePlayerObject(playerid, amount, X+1.0, Y+1.0, Z, 0.0, 0.0, 0.0, 100.0);
SetPVarInt(playerid, "FurnObject", obj);
SetPVarInt(playerid, "EditorMode", 3);
SetPVarInt(playerid, "Mute", 1);
PlayerInfo[playerid][pFurnID]=amount;
EditPlayerObject(playerid, obj);
format(string, sizeof(string),"%s selected, use the SPRINT key to navigate.", ObjectList[foundid][oName]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
}
}
else if(strcmp(param, "edit", true) == 0)
{
if(FurnRight(playerid, 1)){ GetCloseBizzObject(playerid, FurnRight(playerid, 1)); }
}
else if(strcmp(param, "removeall", true) == 0)
{
if(FurnRight(playerid, 1)) {
ShowPlayerDialog(playerid, DIALOG_BUSINESS_REMOVEALL, DIALOG_STYLE_MSGBOX, "Remove all furniture objects", "Are you sure you want to remove all of your current business furniture objects?", "Yes", "No");
} else SendClientMessage(playerid, COLOR_GREY, "You don't have permission to furnish this business.");
}
return 1;
}
stock FurnRight(playerid, type)
{
new key = -1;
if(type == 1)
{
for(new i = 0; i < sizeof(BusinessInfo); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 150.0,BusinessInfo[i][EnterX],BusinessInfo[i][EnterY],BusinessInfo[i][EnterZ]))
{
if(BusinessInfo[i][Type] == 1)
{
if(strlen(BusinessInfo[i][Owner]) > 0)
{
if(strcmp(BusinessInfo[i][Owner], PlayerInfo[playerid][Name], true) == 0)
{
key = i;
return key;
}
}
}
}
else if(IsPlayerInRangeOfPoint(playerid, 150.0,BusinessInfo[i][ExitX],BusinessInfo[i][ExitY],BusinessInfo[i][ExitZ]))
{
if(BusinessInfo[i][Type] == 0)
{
if(strlen(BusinessInfo[i][Owner]) > 0)
{
if(strcmp(BusinessInfo[i][Owner], PlayerInfo[playerid][Name], true) == 0)
{
key = i;
return key;
}
}
}
}
else if(IsPlayerInRangeOfPoint(playerid, 30.0,BusinessInfo[i][EnterX],BusinessInfo[i][EnterY],BusinessInfo[i][EnterZ]))
{
if(BusinessInfo[i][Type] == 0)
{
if(strlen(BusinessInfo[i][Owner]) > 0)
{
if(strcmp(BusinessInfo[i][Owner], PlayerInfo[playerid][Name], true) == 0)
{
key = i;
return key;
}
}
}
}
}
}
return -1;
}
|
this code is a mess, loggedin check in every command no need for that, slowest possible owner detection, unreadable code, what is even furnobjs doing?
|
nearestOwnedBusiness(pid)
{
for(new i, i2=sizeof(BusinessInfo); i < i2; i++){
if( (IsPlayerInRangeOfPoint(pid, 150.0,BusinessInfo[i][EnterX],BusinessInfo[i][EnterY],BusinessInfo[i][EnterZ]) && (BusinessInfo[i][Type] == 0 || BusinessInfo[i][Type] == 1) ||
IsPlayerInRangeOfPoint(pid, 150.0,BusinessInfo[i][ExitX],BusinessInfo[i][ExitY],BusinessInfo[i][ExitZ]) && BusinessInfo[i][Type] == 0) &&
strlen(BusinessInfo[i][Owner]) > 0 && strcmp(BusinessInfo[i][Owner], PlayerInfo[pid][Name], true) == 0))
{
return i;
}
}
return -1;
}
CMD:biz(playerid, params[])
{
new string[128], param[64], amount, amount2;
if(sscanf(params, "s[64]I(-1)I(-1)", param, amount, amount2))
{
scm(playerid, COLOR_GREEN, "/biz [usage]");
scm(playerid, COLOR_GREY, " plant | edit | select |");
}
new nearestBid=nearestOwnedBusiness(playerid);
if(nearestBid==-1)return scm(playerid, COLOR_WHITE, "you arent near to any of your businesses!");
if(strcmp(param, "plant", true) == 0)
{
if(amount == (-1)) {
ShowModelSelectionMenuEx(playerid, FurnObjs, sizeof(FurnObjs), "Furniture List", 8, 16.0, 0.0, -55.0);
} else {
if(amount < 320 || amount > 35000) return scm(playerid, -1, "Invalid Object ID!");
if( GetPlayerInterior(playerid) == 0 &&
GetPlayerVirtualWorld(playerid) == 0 &&
IsInvalidObjectID(amount)) return scm(playerid, -1, "This is not a valid outdoor furniture object!");
new foundid = -1;
for(new i = 0; i < MAX_OBJECT_ARRAY; i++) {
if(ObjectList[i][oID] == amount) {
foundid=i;
break;
}
}
if(foundid == -1) return scm(playerid, -1, "Invalid Object ID!");
new Float:X, Float:Y, Float:Z, obj = 0;
GetPlayerPos(playerid, X, Y, Z);
obj = CreatePlayerObject(playerid, amount, X+1.0, Y+1.0, Z, 0.0, 0.0, 0.0, 100.0);
SetPVarInt(playerid, "FurnObject", obj);
SetPVarInt(playerid, "EditorMode", 3);
SetPVarInt(playerid, "Mute", 1);
PlayerInfo[playerid][pFurnID]=amount;
EditPlayerObject(playerid, obj);
format(string, sizeof(string),"%s selected, use the SPRINT key to navigate.", ObjectList[foundid][oName]);
scm(playerid, COLOR_WHITE, string);
}
}
else if(strcmp(param, "edit", true) == 0)
{
GetCloseBizzObject(playerid, nearestBid);
}
else if(strcmp(param, "removeall", true) == 0)
{
ShowPlayerDialog(playerid, DIALOG_BUSINESS_REMOVEALL, DIALOG_STYLE_MSGBOX,
"Remove all furniture objects",
"Are you sure you want to remove all of your current business furniture objects?", "Yes", "No");
}
return 1;
}
|
PHP Code:
|
but now I still get two messages showing?
|
this code is a mess, loggedin check in every command no need for that, slowest possible owner detection, unreadable code, what is even furnobjs doing?
|