#define DIALOG_INVENTORY 5 //this makes DIALOG_INVENTORY id 5 (fifth dialog! I have 4 others from my register system and you may have some too!) #define DIALOG_DRUGS 6 //same goes here... but id 6, instead of 5
enum pInfo { pPass, pCash, pAdmin, pKills, pDeaths, pDrugs, //here are the 3 added variables! pNewspaper, pInventory }
PlayerInfo[playerid][pDrugs]+PlayerInfo[playerid][pNewspaper]
public OnPlayerDisconnect(playerid,reason) { new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteInt(File,"Cash",GetPlayerMoney(playerid)); INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]); INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]); INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]); INI_WriteInt(File,"Drugs",PlayerInfo[playerid][pDrugs]); //here are the three variables added to the save function under onplayerdisconnect! saving the three variables when the player disconnects INI_WriteInt(File,"Newspaper",PlayerInfo[playerid][pNewspaper]); INI_WriteInt(File,"Inventory",PlayerInfo[playerid][pInventory]); INI_Close(File); return 1; }
PlayerInfo[playerid][pDrugs] = 0; PlayerInfo[playerid][pNewspaper] = 0;
CMD:drugs(playerid,params[]) { new string[69]; //this creates the string, which is used to display specific values, from the ini save file! if(PlayerInfo[playerid][pInventory] > 6) //this is checking if the value of the inventory space is above 6... the reason for this, is that the max inv space is 11 (tutorial sake), and the drugs take up 5 slots... therefore, if the inv value is over 6, it won't work! { format(string, sizeof(string), "You need at least 6 spaces in your inventory! You only have %d",11-PlayerInfo[playerid][pInventory]); //this is where this comes in, this will be sent, if the inventory space is above 6 when trying to get drugs! I have the %d being replaced with 11-vairable... as this will find out whats left within the inventory... 11 - 6, 5 spaces left! SendClientMessage(playerid, COLOR_RED, string); //this sends the string to the player, otherwise the string is insufficient and won't work! It will send the message in red. } else //this is switching the if statement around. For example: if it's above 6, it won't work... but if it is below 6, it will! It's basically switching the > to < instead of having to create a new if statement! { PlayerInfo[playerid][pInventory] += 5; //this will check the ini file for the playerinfo for the inventory, and then will add 5 to whats already there... PlayerInfo[playerid][pDrugs] += 5; //this will add to the specific part of the ini which is for the drugs... we want to add to this variable too, so that we can check how many drugs is on the player, which is used later! format(string, sizeof(string), "You bought some drugs! You now have %d drugs!", PlayerInfo[playerid][pDrugs]); //this is formatting the string which is formatting exactly what is going to be sent to the player, once he gathers the drugs! The %d is linked with the PlayerInfo at the end, the %d will be replaced with what's in the PlayerInfo variable... for example, if the variable is equal to 10, it will replace the %d to 10! SendClientMessage(playerid, -1, string); //this again will send the string to the player but in the colour white (-1 is white!) } return 1; }
CMD:newspaper(playerid,params[]) { new string[69]; //as explained before, this is creating the string variable, which allows us to create the string! and the string size is 69... i dont even know why i put 69;) if(PlayerInfo[playerid][pInventory] < 11) //this checks if the inventory space value is less than 11 (so not full) { if(PlayerInfo[playerid][pNewspaper] == 1) return SendClientMessage(playerid, COLOR_RED, "You already have a newspaper!"); //if it is less than 11 (max space), it will check if the newspaper variable is equal to 1 as you can't buy more than 1 newspaper. If you try to get another newspaper, it will terminate the command and send you a message, telling you, you can't buy another newspaper! PlayerInfo[playerid][pNewspaper]++; //++ will add 1 to the value of the variable... so of course, you can't buy more than 1 newspaper, so there's no need to add more than 1... PlayerInfo[playerid][pInventory]++; //one newspaper will only take 1 space in the inventory,rather than the 5 the drugs take up... so again, we use ++ to add one.. (if you use -- it will take one away!) format(string, sizeof(string), "You bought a newspaper!",PlayerInfo[playerid][pNewspaper]); //as already explained, this is formatting the string, which will be sent to the player, when you gather a newspaper! SendClientMessage(playerid, -1, string); //sends the string, colour white! } else //switches the if statement for < to =>... so if the inv space is => 11, it will send this message { format(string, sizeof(string), "You ran out of inv space! You have %d/11",PlayerInfo[playerid][pInventory]); //formatting string SendClientMessage(playerid, COLOR_RED, string); //sending string } return 1; }
CMD:inv(playerid, params[]) { ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Inventory:", "Drugs \n Newspaper", "Okay", "Close"); //Adds a dialog with the id: DIALOG_INVENTORY and the LIST style! It will be titled inventory and it only has two items in the list! The \n within the content section will put the next thing on a new line... return 1; }
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case DIALOG_REGISTER: //this is the dialog when registering! { if(!response) return Kick(playerid); //negative response will kick them (if they choose not to sign up and click the right hand button (cancel/quit) if(response) { if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER,DIALOG_STYLE_INPUT,""c_white"Register:",""c_white"Type your desired password below!","Register","Quit"); new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteInt(File,"Password",udb_hash(inputtext)); INI_WriteInt(File,"Cash",0); INI_WriteInt(File,"Admin",0); INI_WriteInt(File,"Kills",0); INI_WriteInt(File,"Deaths",0); INI_WriteInt(File,"pDrugs",0); //adding our variables to the register dialog (this is writing the INI file! The 0 will set the variable value to 0 whenever someone signs up! INI_WriteInt(File,"pNewspaper",0); //explained INI_WriteInt(File,"pInventory",0); //explained! INI_Close(File); SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""c_green"Success!",""c_green"You successfully registered!", "Okay",""); } } case DIALOG_INVENTORY: { if(response) { switch(listitem) { case 0: { new string[256]; //variable string format(string, sizeof(string), "Weed: %d", PlayerInfo[playerid][pDrugs]); //this is formatting the string for the dialog! If you wanted to add any more to this, you would just add the \n after weed %d and then carry on adding more! ShowPlayerDialog(playerid, DIALOG_DRUGS, DIALOG_STYLE_LIST, "Drugs:", string, "Okay", "Close"); //this will show the dialog, the 'string' just makes sure the script/game knows that the format(string we did, is what goes there... } } } return 1; } } case DIALOG_DRUGS: //drugs dialogid! { if(response) { switch(listitem) { case 0: { if(PlayerInfo[playerid][pDrugs] > 1) //this will check if the player has any drugs on him, if he does, the command will continue... { SendClientMessage(playerid, -1, "you consumed 1 Drug!"); PlayerInfo[playerid][pDrugs]--; //this will take away 1 drug using the -- PlayerInfo[playerid][pInventory]--; //this will take 1 from the inventory, making for example, 11, 10... allowing you to gather something else that equals 1 space! } else //switches the if statement! if the player has less than 1, it will send the following message and terminate the command! { SendClientMessage(playerid, COLOR_RED, "You don't have any drugs on you!"); //send the message in red } } } } return 1; } } return 1; }
forward LoadUser_data(playerid,name[],value[]); public LoadUser_data(playerid,name[],value[]) { INI_Int("Password", PlayerInfo[playerid][pPass]); INI_Int("Cash",PlayerInfo[playerid][pCash]); INI_Int("Admin",PlayerInfo[playerid][pAdmin]); INI_Int("Kills",PlayerInfo[playerid][pKills]); INI_Int("Deaths",PlayerInfo[playerid][pDeaths]); INI_Int("Drugs",PlayerInfo[playerid][pDrugs]); //.adds the variable to the load function, loading the variable that was saved! same goes for the other variables that you add/added! INI_Int("Newspaper",PlayerInfo[playerid][pNewspaper]); INI_Int("Inventory",PlayerInfo[playerid][pInventory]); return 1; }
I think the main problem with this tutorial is it's not really an inventory system you have login stuff mixed in and really all this is a shoddy register system with a few extras tossed in (inventory examples).
|
It should be completely separate from your login system your crossing systems which is a very bad practice.
|