07.09.2013, 08:09
Hi,I have this inventory system.How can I make "/giveitem (playerid) (slot)" and "/sellitem (playerid) (slot) (price)?
Код:
#include <a_samp> #include <Dini> #define YELLOW 0xFFFF00FF //============ Defines of Bag IDS #define MAX_ITEMS 10 #define BAGCOUNT 5 #define EMPTY_BAGSPACE -1 #define ecard 1 #define smedal 2 #define gmedal 3 #define mayorsig 4 #define swatsig 5 #define sdoc1 6 #define sdoc2 7 #define sdoc3 8 #define sdoc4 9 #define sdocfull 10 new Bags[MAX_PLAYERS][BAGCOUNT]; new ItemNames[MAX_ITEMS][32] = { {"Electronic Card"}, {"S Medal"}, {"G Medal"}, {"Mayor Sig"}, {"Swat Sig"}, {"S Document 1"}, {"S Document 2"}, {"S Document 3"}, {"S Document 4"}, {"S Full Document"} }; main(); public OnGameModeInit() { SetGameModeText("test"); AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0); return 1; } public OnPlayerConnect(playerid) { // Resets for(new s; s < BAGCOUNT; s++) { Bags[playerid] = EMPTY_BAGSPACE; } // Loads LoadPlayerBagFromFile(playerid); } public OnPlayerDisconnect(playerid) { // Save SavePlayerBagToFile(playerid); } public OnPlayerRequestClass(playerid, classid) { SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746); SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746); return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { if(strcmp(cmdtext, "/mybag", true) == 0) { new bagitem[128]; SendClientMessage(playerid, YELLOW, "-----------------------------------------------"); SendClientMessage(playerid, YELLOW, " Your Bag"); SendClientMessage(playerid, YELLOW, "-----------------------------------------------"); for (new i = 0; i < BAGCOUNT; i++) { if (Bags[playerid][i] == EMPTY_BAGSPACE) format(bagitem, sizeof(bagitem), "Item %d: ", i + 1); else format(bagitem, sizeof(bagitem), "Item %d: %s", i + 1, ItemNames[Bags[playerid][i] - 1]); SendClientMessage(playerid, 0xffffffff, bagitem); } SendClientMessage(playerid, YELLOW, "-----------------------------------------------"); return 1; } if(strcmp(cmdtext, "/killbag", true) == 0) { for(new s; s < BAGCOUNT; s++) { Bags[playerid][s] = EMPTY_BAGSPACE; } SendClientMessage(playerid, YELLOW, "[ ! ] Your bag is now empty!"); return 1; } if(strcmp(cmdtext, "/putecard", true) == 0) { new space = FindPlayerBagSpace(playerid); if (space == EMPTY_BAGSPACE) return SendClientMessage(playerid, YELLOW, "[ ! ] Your bag is full!"); Bags[playerid][space] = ecard; SendClientMessage(playerid, YELLOW, "[ ! ] You have got an electing card !"); return 1; } return 0; } stock FindPlayerBagSpace(playerid) { for(new s; s < BAGCOUNT; s++) { if (Bags[playerid] == EMPTY_BAGSPACE) return s; } return EMPTY_BAGSPACE; } stock Player(playerid) { new player[MAX_PLAYER_NAME]; GetPlayerName(playerid, player, sizeof(player)); return player; } stock i_path(playerid) { new a[256]; format(a, sizeof(a), "%s's_Bag.ini",Player(playerid)); return a; } stock SavePlayerBagToFile(playerid){ if(!dini_Exists(i_path(playerid))) dini_Create(i_path(playerid)); new bagdinikey[256], bagitemline[256]; for(new i = 0; i < BAGCOUNT; i++){ format(bagdinikey, 256, "slot:%d", i+1); format(bagitemline, 256, "%d", Bags[playerid][i]); dini_Set(i_path(playerid), bagdinikey, bagitemline); } return 1; } stock LoadPlayerBagFromFile(playerid) { new filename[256]; format(filename, sizeof(filename), "%s's_Bag.ini", Player(playerid)); if (fexist(filename)) { new File: BagFile; BagFile = fopen(filename, io_read); if(BagFile) { new key[128]; new Data[128]; while(fread(BagFile, Data, sizeof(Data))) { key = ini_GetKey(Data); if(strcmp(key, "slot:1", true)==0) { Bags[playerid][0]=strval(ini_GetValue(Data)); } if(strcmp(key, "slot:2", true)==0) { Bags[playerid][1]=strval(ini_GetValue(Data)); } if(strcmp(key, "slot:3", true)==0) { Bags[playerid][2]=strval(ini_GetValue(Data)); } if(strcmp(key, "slot:4", true)==0) { Bags[playerid][3]=strval(ini_GetValue(Data)); } if(strcmp(key, "slot:5", true)==0) { Bags[playerid][4]=strval(ini_GetValue(Data)); } } } fclose(BagFile); } return 1; } stock ini_GetKey(line[]) { new keyRes[128]; keyRes[0] = 0; if(strfind(line, "=", true) == -1) return keyRes; strmid(keyRes, line, 0, strfind(line, "=", true), sizeof(keyRes)); return keyRes; } stock ini_GetValue(line[]) { new valRes[128]; valRes[0] = 0; if(strfind(line, "=", true) == -1) return valRes; strmid(valRes, line, strfind(line, "=", true)+1, strlen(line), sizeof(valRes)); return valRes; }