Business upgrade
#1

Hello everyone, the problem I'm facing right now is the following -

On my server you can own 1 business as a REGULAR player and 2 businesses as a VIP player (same with houses).

When I try to upgrade my house(s) it works perfectly, but when I buy 2 businesses and try to upgrade them, it only allows me to upgrade the first one (regular) and when I go inside the second one (VIP) it says "You are not inside your business".

Normal bizzes are "PlayerInfo[playerid][pBiz]" , VIP bizzes are "PlayerInfo[playerid][pVBiz]".

Here's the house command if you need it to compare between the biz and house upgrade commands to see whats wrong and so on.

(The difference is that Houses are being upgraded from the outside, where the pickup is, but the Bizzes are being upgraded from the inside.)

House upgrade command:

Код:
CMD:houseupgrade(playerid, params[])
{
	new string[128], idx = PlayerInfo[playerid][pHouse], price;
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pHouse]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a house.");
	if(!PlayerInfo[playerid][pVHouse])
	{
	    if(!IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ])) return SendClientMessage(playerid, COLOR_GREY, "You are not near your house.");
	}
	else
	{
	    new done;
   	    if(!IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))
 		{
	 		done ++;
	   	    idx = PlayerInfo[playerid][pVHouse];
	   	    if(!IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ])) done ++;
		}
		if(done == 2) return SendClientMessage(playerid, COLOR_GREY, "You are not near your house.");

	}
	if(sscanf(params, "s[8]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /houseupgrade [confirm]");
	if(HouseInfo[idx][hLevel] >= 10) return SendClientMessage(playerid, COLOR_GREY, "Your house already has the maximum level possible.");
	if(!strcmp(params, "confirm", true))
	{
	    if(!PlayerInfo[playerid][pVIP])price = 50000;
	    if(PlayerInfo[playerid][pVIP] == 1) price = 37500;
	    else if(PlayerInfo[playerid][pVIP] == 2) price = 25000;
	    else if(PlayerInfo[playerid][pVIP] == 3) price = 12500;
	    else if(PlayerInfo[playerid][pVIP] == 4) price = 0;
		if(PlayerInfo[playerid][pMoney] < price)
		{
		    format(string, sizeof(string), "You need $%d to upgrade your house.", price);
			SendClientMessage(playerid, COLOR_GREY, string);
			return 1;
		}
		HouseInfo[idx][hLevel] ++;
		GiveZaiatMoney(playerid, -price);
		format(string, sizeof(string), " You have upgraded your house to level %d.", HouseInfo[idx][hLevel]);
		SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
		format(string, sizeof(string), "ID: %d\nHouse (Lvl: %d)\nOwner: %s\nStatus: %s", idx, HouseInfo[idx][hLevel], HouseInfo[idx][hOwner], RHS(idx));
		UpdateDynamic3DTextLabelText(HouseInfo[idx][hText], COLOR_WHITE, string);
	}
	return 1;
}
Biz upgrade command:
Код:
CMD:bizupgrade(playerid, params[])
{
	new string[128], idx = PlayerInfo[playerid][pBiz];
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pBiz]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a business.");
    if(GetPlayerVirtualWorld(playerid)-100 != idx) return SendClientMessage(playerid, COLOR_GREY, "You are not inside your business.");
	if(sscanf(params, "s[8]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /bizupgrade [confirm]");
	if(BizInfo[idx][bLevel] >= 5) return SendClientMessage(playerid, COLOR_GREY, "Your business already has the maximum level possible.");
	if(!strcmp(params, "confirm", true))
	{
	    if(strval(RPBL(playerid)) == 1 && RPBS(playerid) >= 100) {BizInfo[idx][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 2.");}
	    else if(strval(RPBL(playerid)) == 2 && RPBS(playerid) >= 300) {BizInfo[idx][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 3.");}
	    else if(strval(RPBL(playerid)) == 3 && RPBS(playerid) >= 700) {BizInfo[idx][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 4.");}
	    else if(strval(RPBL(playerid)) == 4 && RPBS(playerid) >= 1200) {BizInfo[idx][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 5.");}
	    else
		{
		    if(strval(RPBL(playerid)) == 1) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 100 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 2) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 300 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 3) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 700 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 4) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 1200 -RPBS(playerid));
			SendClientMessage(playerid, COLOR_GREY, string);
		}
	}
	return 1;
}
I guess it's something easy to fix, not sure (haven't opened pawno since more than year lol), I tried several times, but unlucky...

P.S.: Thanks in advance to everyone who ATLEAST tries to help, you will be +Repped for sure, have a nice day!
Reply
#2

I could be blind as a bat, but in your example i dont even see a pVBiz?

Nevertheless, try the below, i added a bunch of linebreaks to improve readability, and added comments to describe my changes to your code, feel free to re-structure again on your end.
Код:
CMD:bizupgrade(playerid, params[])
{
	new string[128], 
		idx = PlayerInfo[playerid][pBiz],
		idx2 = PlayerInfo[playerid][pVBiz], // added a pointer too the pVBiz
		currInteriour = GetPlayerVirtualWorld(playerid)-100; // added a variable that should hold the current interior id (or whatever that GetPlayerVirtualWorld returns)
		
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    
	if(!PlayerInfo[playerid][pBiz]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a business.");
    
	// changed, now it will check against both interiours
	// As an added bonus, we can now just use "currInteriour" in the remainder of this function, if that does not match idx or idx2 then it wont get past the below line anyway.
	if((currInteriour != idx) && (currInteriour != idx2)) return SendClientMessage(playerid, COLOR_GREY, "You are not inside your business.");
		
	if(sscanf(params, "s[8]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /bizupgrade [confirm]");
	
	// changed, now it will check currInteriour instead of idx
	if(BizInfo[currInteriour][bLevel] >= 5) return SendClientMessage(playerid, COLOR_GREY, "Your business already has the maximum level possible.");
	
	if(!strcmp(params, "confirm", true))
	{
		// in the four if statements below, idx was replaced with currInteriour
	    if(strval(RPBL(playerid)) == 1 && RPBS(playerid) >= 100) {BizInfo[currInteriour][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 2.");}
	    else if(strval(RPBL(playerid)) == 2 && RPBS(playerid) >= 300) {BizInfo[currInteriour][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 3.");}
	    else if(strval(RPBL(playerid)) == 3 && RPBS(playerid) >= 700) {BizInfo[currInteriour][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 4.");}
	    else if(strval(RPBL(playerid)) == 4 && RPBS(playerid) >= 1200) {BizInfo[currInteriour][bLevel]++; SendClientMessage(playerid, COLOR_LIGHTBLUE, " You have upgraded your business to level 5.");}
	    else
		{
		    if(strval(RPBL(playerid)) == 1) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 100 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 2) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 300 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 3) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 700 -RPBS(playerid));
		    else if(strval(RPBL(playerid)) == 4) format(string, sizeof(string), "Your business needs to sell %d more products to level up.", 1200 -RPBS(playerid));
			SendClientMessage(playerid, COLOR_GREY, string);
		}
	}
	return 1;
}
Edit: "currInteriour" should actually be "currInterior", sorry, not a native english speaker
Reply
#3

I've tried by adding pVBiz, but then I removed it because it didnt worked for me, I tried like that

Код:
new string[128], idx = PlayerInfo[playerid][pBiz],  idx2 = PlayerInfo[playerid][pVBiz];
and
Код:
if(GetPlayerVirtualWorld(playerid)-100 != idx || !=idx2)
and it didn't worked, anyway I've forgotten much things since the last time I used to script lol

I must say one BIG THANKS, it worked! +Repped
Reply
#4

Cool, glad to be of help, and thanks for the rep, tho wasnt really needed hehe.

Btw, not to 'one up' you, but i didnt open Pawno for 7 years up untill 2 days ago, and so far ive just been posting in this help forum to help me remember how to code with it again haha, so it could always be worse
(That said, its actually working out great, jogging my memory and giving me reasons to dig trough the wiki and forum)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)