+ Something In Enumators
#1

Hello guys. Today i started working on Item Sell system. I dont know how to Add Something In Shop.
Heres my codes.
PHP код:
/* ENUMATORS */
enum invgayidva
{
    
invisid,
    
iyideba 0,
    
vincyidisid[MAX_PLAYERS],
    
fasi
}
new 
InvSInfo[40][invgayidva];
new 
ItemebisID 0
Heres Sell Code
PHP код:
stock ItemSellBuy(playerid)
{
    for(new 
itemii;itemii<MAX_SELLITEMS;itemii++)
    {
        new 
formati[1024], suturu[1024], suturun2[1024], listiii[1024];
        new 
adminiiiii=0;
        if(
InvSInfo[itemii][iyideba] > && itemii != 0)
        {
            
PlayerAdminMassage[playerid][adminiiiii] = itemii;
            
adminiiiii++;
            
format(suturusizeof(suturu), "%s - %s - %d\n"GetName(InvSInfo[itemii][vincyidisid]),InvNames[InvSInfo[itemii][invisid]],InvSInfo[itemii][fasi]);
            
strins(listiiisuturustrlen(formati), strlen(suturu));
        }
        else { 
SendClientMessage(playeridCOLOR_RED""#servn"Motamasheebi Ar Yidian Arafers.");}
        
format(suturun2,sizeof(suturun2), "COIN SHOP - IYIDEBA %d ITEMI"InvSInfo[itemii][iyideba]);
        
ShowPlayerDialog(playerid,dialog_coinbuysell,DIALOG_STYLE_LIST,suturun2,listiii,"Yidva","Gatishva");
    }
    return 
1;
}
stock ShowInvForSell(playerid)
{
    new 
str[1024], slotstr[1024];
    new 
listitems[1024], adm=0;
    for(new 
slot;slot<INVNUMBERS;slot++)
    {
        if(
PlayerInv[playerid][slot] > && slot != 0)
        {
            
PlayerAdminMassage[playerid][adm] = slot;
            
adm ++;
            
format(strsizeof(str), "[%d] - %s\n"PlayerInv[playerid][slot],InvNames[slot]);
            
strins(listitemsstrstrlen(listitems), strlen(str));
        }
    }
    if(
Player[playerid][pPack] == 1format(slotstr,sizeof(slotstr),"Dzalian Patara Zurgchanta [%d/%d]",Player[playerid][pSlots],Player[playerid][pPack]*10);
    else if(
Player[playerid][pPack] == 2format(slotstr,sizeof(slotstr),"Patara Zurgchanta [%d/%d]",Player[playerid][pSlots],Player[playerid][pPack]*10);
    else if(
Player[playerid][pPack] == 3format(slotstr,sizeof(slotstr),"Sashualo Zurgcahnta [%d/%d]",Player[playerid][pSlots],Player[playerid][pPack]*10);
    else if(
Player[playerid][pPack] == 4format(slotstr,sizeof(slotstr),"Didi Zurgchanta [%d/%d]",Player[playerid][pSlots],Player[playerid][pPack]*10);
    else if(
Player[playerid][pPack] == 5format(slotstr,sizeof(slotstr),"Dzalian Didi Zurgchanta [%d/%d]",Player[playerid][pSlots],Player[playerid][pPack]*10);
    
ShowPlayerDialog(playerid,dialog_sellitemi,DIALOG_STYLE_LIST,slotstr,listitems,"Gayidva","Gatishva");
    return 
1;

And Heres Dialog
PHP код:
    if(dialogid == dialog_sellitemi)
    {
        if(
response)
        {
            
playermassagetoadmin[playerid] = PlayerAdminMassage[playerid][listitem];
            
PlayerInv[playerid][playermassagetoadmin[playerid]]--;
            
Player[playerid][pSlots] --;
            new 
buffer[128], buffer2[128];
            
format(buffersizeof(buffer), ""#servn" {ffffff}Tqven Dadet Gasayidad Nivti: {00FFFF}%s.", InvNames[playermassagetoadmin[playerid]]);
            
SendClientMessage(playeridCOLOR_GRADbuffer);
            
format(buffer2sizeof(buffer2), ""#servn" {ffffff}%s Yidis Nivts: {00FFFF}%s. {ffffff} Fasi: {00FFFF}%d", Name(playerid), InvNames[playermassagetoadmin[playerid]]);
            
SendClientMessageToAll(COLOR_GRADbuffer2);
            if(
playermassagetoadmin[playerid] == 10RemovePlayerWeapon(playerid,25);
            else if(
playermassagetoadmin[playerid] == 11RemovePlayerWeapon(playerid,24);
            else if(
playermassagetoadmin[playerid] == 12RemovePlayerWeapon(playerid,30);
            else if(
playermassagetoadmin[playerid] == 13RemovePlayerWeapon(playerid,31);
            else if(
playermassagetoadmin[playerid] == 14RemovePlayerWeapon(playerid,34);
            else if(
playermassagetoadmin[playerid] == 15RemovePlayerWeapon(playerid,28);
            else if(
playermassagetoadmin[playerid] == 16RemovePlayerWeapon(playerid,29);
            else if(
playermassagetoadmin[playerid] == 17RemovePlayerWeapon(playerid,32);
            else if(
playermassagetoadmin[playerid] == 26RemovePlayerWeapon(playerid,5);
            else if(
playermassagetoadmin[playerid] == 27RemovePlayerWeapon(playerid,8);
            else if(
playermassagetoadmin[playerid] == 28RemovePlayerWeapon(playerid,6);
            else if(
playermassagetoadmin[playerid] == 29RemovePlayerWeapon(playerid,4);
            else if(
playermassagetoadmin[playerid] == 30RemovePlayerWeapon(playerid,3);
            else if(
playermassagetoadmin[playerid] == 59RemovePlayerWeapon(playerid,22);
            else if(
playermassagetoadmin[playerid] == 60RemovePlayerWeapon(playerid,23);
            else if(
playermassagetoadmin[playerid] == 61RemovePlayerWeapon(playerid,26);
            else if(
playermassagetoadmin[playerid] == 62RemovePlayerWeapon(playerid,35);
            else if(
playermassagetoadmin[playerid] == 71RemovePlayerWeapon(playerid,33);
            else if(
playermassagetoadmin[playerid] == 72RemovePlayerWeapon(playerid,27);
            else if(
playermassagetoadmin[playerid] == 73RemovePlayerWeapon(playerid,16);
            else if(
playermassagetoadmin[playerid] == 74RemovePlayerWeapon(playerid,18);
            return 
1;
        }else{}
    } 
Thanks For Help.
Reply
#2

Ok, so first of all, change that "else if"`s to switch with cases. Switch is faster then if, and it will be better for reading too.

Also I will suggest you to read this topic, it`s very usefull: Click here.
Reply
#3

Rewriting your code is the key to the solution!

Your code has variables that are 'too complex' for reading and saving in the human memory, YES, even for a little time.
Use switch than if else code as suggested above.

PHP код:
playermassagetoadmin[playerid] = PlayerAdminMassage[playerid][listitem]; 
            
PlayerInv[playerid][playermassagetoadmin[playerid]]--; 
Is this code understandable by us? Care to eloborate what it does? and Why using the array called 'PlayerAdminMassage', even the name of the array is 'too complex'.
Reply
#4

Quote:
Originally Posted by Sanady
Посмотреть сообщение
Ok, so first of all, change that "else if"`s to switch with cases. Switch is faster then if, and it will be better for reading too.

Also I will suggest you to read this topic, it`s very usefull: Click here.
Go to the second page of this thread: https://sampforum.blast.hk/showthread.php?tid=109867&page=2 it's about "switch" vs "else if". But for off the record, I prefer to use switches anyways because it's fancier when you look at it and slightly easier to handle because of it being good "eye candy".


-----------------------------------------------------------------------------------------------


Код:
enum invgayidva 
{ 
    invisid, 
    iyideba = 0,
You didn't assign "iyideba" the value 0 but its position in the enum. So now:

Код:
InvSInfo[x][0] = InvSInfo[x][iyideba] = InvSInfo[x][invisid]
(For the record, values are set to 0 by default in most cases, I think at least in all cases but maybe some cases they are not ).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)