Dialog + Loop problem
#1

Hello, yes, it's me again
I got another problem in my ServerShop script, and I can't figure out how to fix it...
anyways here's code:
pawn Код:
if ( !strcmp( "/servershop", cmdtext, true, 11 ) )
    {
        for(new i; i<sizeof ServerShop ; i++)
        {
            if(ServerShop[i][shop_unlocked][playerid] == 1)
                format(string, sizeof(string), "{00FF00}%s \n\t{00FF00}Already Bought\n",ServerShop[i][shop_name], ServerShop[i][shop_costmoney], ServerShop[i][shop_costscore]);
            else
                format(string, sizeof(string), "{FFFFFF}%s \n\t{FFFFFF}%i Money\n\t{FFFFFF}%i Score\n",ServerShop[i][shop_name], ServerShop[i][shop_costmoney], ServerShop[i][shop_costscore]);
        }
        ShowPlayerDialog(playerid,72,DIALOG_STYLE_LIST,"{E4FF47}Server Shop", string ,"Select", "Cancel");
       
        return 1;
    }
ok so what this should do is it should show all the shop items that are unlocked green and the not unlocked white.
When I do this with SendClientMessage(...,...,string)
it works
but when I do it with a dialog, it only shows one shop item...
I have a total of 10 shop items
rep plus for helper
Reply
#2

pawn Код:
format(string, sizeof(string), "{00FF00}%s \n\t{00FF00}Already Bought\n",ServerShop[i][shop_name], ServerShop[i][shop_costmoney], ServerShop[i][shop_costscore]);
You do not have all these values ​​to be deployed to the format.
You need of the value to the %s and nothing more.
pawn Код:
format(string, sizeof(string), "{00FF00}%s \n\t{00FF00}Already Bought\n",ServerShop[i][shop_name]);
Reply
#3

I see, thanks
but I still only get the very last shop item...
Reply
#4

you need to readd the existing string

pawn Код:
format(string, sizeof(string), "%s{00FF00}%s\n\t{00FF00}Already Bought\n", string, ServerShop[i][shop_name]);
Reply
#5

ah, thanks it works!
rep++

btw, I got another small question, what has to do with my servershop system...
how can I check if the listitem is possible to / by 2?
Reply
#6

So you just wanna find out the ServerShop index ?

Than that should be enough
pawn Код:
listitem = listitem / 2;
printf("ServerShop[%d][shop_name] \"%s\"", listitem, ServerShop[listitem][shop_name]);
and to answer your question exactly, how to find out if a number is divisible by 2 use

pawn Код:
if((listitem % 2) == 0) {} // or
if((listitem & 0b1) == 0) {} // the faster methode - if this case a warning use ! instead of == 0
Reply
#7

hmm ok I kinda understand, but I cannot figure out how to put this in my script with the adjustments...

ok so i'll explain.
pawn Код:
if(dialogid == 72)
    {
        new string[500];
        if(!response) return 1;
       
        if(ServerShop[listitem][shop_unlocked][playerid] == 0)
            return SendClientMessage(playerid,COLOR_RED,"*You cannot buy shop items twice!");
        if(ServerShop[listitem][shop_costmoney] > GetPlayerMoney(playerid) && ServerShop[listitem][shop_unlocked[playerid][playerid]==1)
            return SendClientMessage(playerid,COLOR_RED,"*You either do not have enough score or money for this item!");
        /*else
        {
            GivePlayerMoney(playerid,-ServerShop[listitem][shop_costmoney]);
            SetPlayerScore(playerid,GetPlayerScore(playerid)-ServerShop[listitem][shop_costscore]);
            format(string, sizeof string, "*%s", ServerShop[listitem][shop_reward]);
            SendClientMessage(playerid,COLOR_SEXYGREEN,string);
        }*/

    }
ok, so I am making that u must select the item u want to buy
but I made my dialog so that the already bought items are 2lines
1: Name of the item
2: "Already Bought"
and that the available items have 3 lines:
1: name of the item
2: money needed
3: score needed

now, when making the thing to let the player choose this caused troubles
because for example listitem 1 and 2 are from the Already bouhgt item: condom for example
and then listitem 3 4 and 5 are from the availble item, vibrator...
so how can I correctly check what type the player has selected?
Reply
#8

That should work

pawn Код:
new
    index = 0;
do {
    if(ServerShop[index][shop_unlocked][playerid]) {
        listitem -= 2;
    } else {
        listitem -= 3;
    }
} while(!(listitem & (1 << (cellbits - 1))) && (++index != sizeof ServerShop));
Reply
#9

Ahh, I see
If I'm right it does this?:

new int, called index wich is 0 (represents the listitem)

as long as... do
if statment
If the listitem minus 1 is equal to 2
else if the listitem minus one is equal to Three

as long ass the listiem is not... from here I pass


Anyways, where Exactly to put this?
Reply
#10

index just represents the index of the SystemShop

I just subtract the line count and if listitem gets negative we found our index

pawn Код:
if(!(listitem & (1 << (cellbits - 1)))) {} // this can also be written like
if(0 <= listitem) {}
the do, just because the first while check would be unnecessary

pawn Код:
// indention
    if(dialogid == 72)
    {
        if(!response) return 1;

        new string[500], index;
        do
        { // not sure if you can remove the brackets here, so i let them
            listitem -= (ServerShop[index][shop_unlocked][playerid]) ? (2) : (3);
        } while(!(listitem & (1 << (cellbits - 1))) && (++index != sizeof ServerShop));
       
        if(ServerShop[index][shop_unlocked][playerid] == 0)
            return SendClientMessage(playerid,COLOR_RED,"*You cannot buy shop items twice!");
        if(ServerShop[index][shop_costmoney] > GetPlayerMoney(playerid) && ServerShop[index][shop_unlocked[playerid][playerid]==1)
            return SendClientMessage(playerid,COLOR_RED,"*You either do not have enough score or money for this item!");
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)