04.06.2014, 07:23
(
Последний раз редактировалось Dignity; 04.06.2014 в 10:44.
)
I made this in attempt to learn arrays. It mainly consists of 2D-arrays, and it's my first release with arrays that I actually made myself so please be gentle with feedback as it was my first attempt. I'm eager for feedback and constructive criticism though, so please do reply if you see anything void! This was the first version of my first inventory system (ever), which was originally meant to be used for a server but as we've decided to resort to textdraws and dialogs, I am now releasing this version.
Some things you should know before using this script:
- Item ID 0 isn't used. Reasons for this are that the inventory determines empty slots if the slot ID is 0, so adding item ID 0 will make the inventory believe the slot is empty. (Since I store item IDs inside the slots)
- This script uses ALOT of arrays, variables and loops. Make sure you know atleast the basics of them before trying to use it.
- The command /useitem is empty. It only shows a message and removes the item incase the value exceeds the value the item has.
Video of usage (which was made yesterday, some things have been modifed (i.e. text colors, some params, etc) for the script to be actually plug and play worthy):
[ame]http://www.youtube.com/watch?v=2OLPB3f1_BM[/ame]
Please don't rerelease this without my permission. You're not obiliged to give credits and you can edit this however you want. If there are any bugs, please comment here and I'll fix them.
Some things you should know before using this script:
- Item ID 0 isn't used. Reasons for this are that the inventory determines empty slots if the slot ID is 0, so adding item ID 0 will make the inventory believe the slot is empty. (Since I store item IDs inside the slots)
- This script uses ALOT of arrays, variables and loops. Make sure you know atleast the basics of them before trying to use it.
- The command /useitem is empty. It only shows a message and removes the item incase the value exceeds the value the item has.
Quote:
Commands: /inventory
|
[ame]http://www.youtube.com/watch?v=2OLPB3f1_BM[/ame]
pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define MAX_INV_SLOTS 5
#define MAX_INV_ITEMS 15
#define MAX_DROP_OBJ 50
// Store item ID inside of this
new pInv_Item[MAX_PLAYERS][MAX_INV_SLOTS];
new pInv_Value[MAX_PLAYERS][MAX_INV_SLOTS];
new DroppedItemsObj[MAX_DROP_OBJ];
new Text3D: DroppedItemsLab[MAX_DROP_OBJ];
new DroppedItemsVal[MAX_DROP_OBJ];
new DroppedItemsItem[MAX_DROP_OBJ];
new DroppedItemsTime[MAX_DROP_OBJ];
new InventoryItems[MAX_INV_ITEMS][] = {
// ID, "Name of Item"
{0, "Untitled"}, // Can't be given
{1, "Untitled"},
{2, "Untitled"},
{3, "Untitled"},
{4, "Untitled"},
{5, "Untitled"},
{6, "Untitled"},
{7, "Untitled"},
{8, "Untitled"},
{9, "Untitled"},
{10, "Untitled"},
{11, "Untitled"},
{12, "Untitled"},
{13, "Untitled"},
{14, "Untitled"}
};
public OnFilterScriptExit()
{
for(new i = 0; i < MAX_DROP_OBJ ; i ++)
{
DestroyObject(DroppedItemsObj[i]);
Delete3DTextLabel(DroppedItemsLab[i]);
}
return 1;
}
CMD:inventory(playerid, params[])
{
new string[128];
for(new i = 0; i < MAX_INV_SLOTS; i ++)
{
if(pInv_Item[playerid][i] > 0)
{
format(string, sizeof(string), "Item Slot %d: {549E63}%s{FFFFFF} (V: %d)", i, InventoryItems[pInv_Item[playerid][i]][1], pInv_Value[playerid][i]);
SendClientMessage(playerid, -1, string);
}
else if(pInv_Item[playerid][i] == 0)
{
format(string, sizeof(string), "Item Slot %d: {BF5050}EMPTY{FFFFFF}", i);
SendClientMessage(playerid, -1, string);
}
}
return 1;
}
CMD:useitem(playerid, params[])
{
new slot, value, string[128];
if(sscanf(params, "i", slot, value)) return SendClientMessage(playerid, -1, "/useitem [slot]");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
if(pInv_Item[playerid][slot] == 0) return SendClientMessage(playerid, -1, "There's nothing in that inventory slot!");
if(pInv_Value[playerid][slot] < value) return SendClientMessage(playerid, -1, "The value you specified is incorrect! You don't have that much of the item you selected!");
format(string, sizeof(string), "You used item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} from {50A0BF}slot %d{FFFFFF}.", InventoryItems[pInv_Item[playerid][slot]][0], InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], slot);
SendClientMessage(playerid, -1, string);
pInv_Value[playerid][slot] -= value;
if(pInv_Value[playerid][slot] == 0) pInv_Item[playerid][slot] = 0;
return 1;
}
CMD:pickupitem(playerid, params[])
{
new Float: X, Float: Y, Float: Z, string[128], item;
if(sscanf(params, "i", item)) return SendClientMessage(playerid, -1, "/pickupitem [id]");
GetObjectPos(DroppedItemsObj[item], X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, 3.0, X, Y, Z))
{
for(new i = 0; i < MAX_INV_SLOTS; i ++)
{
if(pInv_Item[playerid][i] == 0)
{
pInv_Item[playerid][i] = DroppedItemsItem[item];
pInv_Value[playerid][i] = DroppedItemsVal[item];
format(string, sizeof(string), "Picked up item {50A0BF}ID (%d){FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF}. Stored in {50A0BF}slot %d{FFFFFF}.", item, InventoryItems[DroppedItemsItem[item]][1], DroppedItemsVal[item], i);
SendClientMessage(playerid, -1, string);
break;
}
}
DestroyObject(DroppedItemsObj[item]);
Delete3DTextLabel(DroppedItemsLab[item]);
DroppedItemsObj[item] = 0;
DroppedItemsVal[item] = 0;
DroppedItemsItem[item] = 0;
}
else SendClientMessage(playerid, -1, "You're not near that object!");
return 1;
}
CMD:dropitem(playerid, params[])
{
new slot, string[128], labstring[128], Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid, X, Y, Z);
if(sscanf(params, "i", slot)) return SendClientMessage(playerid, -1, "/dropitem [slot]");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
if(pInv_Item[playerid][slot] == 0) return SendClientMessage(playerid, -1, "There's nothing in that inventory slot!");
for(new i = 0; i < MAX_DROP_OBJ; i ++)
{
if(DroppedItemsObj[i] == 0)
{
format(labstring, sizeof(labstring), "[{B2E66E}LOOTABLE ITEM{FFFFFF}]\n %s (%d)\n[{B2E66E}/pickupitem{FFFFFF} ID: {B2E66E}%d{FFFFFF}]", InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], i);
DroppedItemsLab[i] = Create3DTextLabel(labstring, 0xFFFFFFFF, X +0.1, Y, Z -0.4, 15.0, GetPlayerVirtualWorld(playerid), 1);
DroppedItemsObj[i] = CreateObject(3014, X, Y, Z -0.8, 0.00, 0.00, 0.00);
SetPlayerPos(playerid, X, Y, Z +0.9);
DroppedItemsVal[i] = pInv_Value[playerid][slot];
DroppedItemsItem[i] = pInv_Item[playerid][slot];
DroppedItemsTime[i] = 300;
format(string, sizeof(string), "You dropped item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} from {50A0BF}slot %d{FFFFFF}.", InventoryItems[pInv_Item[playerid][slot]][0], InventoryItems[pInv_Item[playerid][slot]][1], pInv_Value[playerid][slot], slot);
SendClientMessage(playerid, -1, string);
break;
}
}
pInv_Item[playerid][slot] = 0;
pInv_Value[playerid][slot] = 0;
return 1;
}
// ADMIN COMMANDS
CMD:giveitem(playerid, params[])
{
new targetid, slot, item, value, string[128];
if(sscanf(params, "uiii", targetid, slot, item, value)) return SendClientMessage(playerid, -1, "/additem [targetid] [slot] [item] [value]");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be an RCON admin in order to use this command!");
if(item > 15 || item < 1) return SendClientMessage(playerid, -1, "The item ID you entered does not exist. For a list of items, type: {50A0BF}/itemlist{FFFFFF}.");
if(slot > 4) return SendClientMessage(playerid, -1, "There are only {50A0BF}five{FFFFFF} slots you can use! (0-4)");
pInv_Item[playerid][slot] = item;
pInv_Value[playerid][slot] = value;
format(string, sizeof(string), "Item {50A0BF}ID %d{FFFFFF} ({50A0BF}%s{FFFFFF}) {50A0BF}(%d){FFFFFF} added to {50A0BF}slot %d{FFFFFF}.", item, InventoryItems[item][1], value, slot);
SendClientMessage(playerid, -1, string);
return 1;
}
CMD:itemlist(playerid, params[])
{
new string[128];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be an RCON admin in order to use this command!");
for(new i = 1; i < MAX_INV_ITEMS; i ++)
{
format(string, sizeof(string), "Item ID: {50A0BF}''%d''{FFFFFF} - Name: {50A0BF}''%s''{FFFFFF}", InventoryItems[i][0], InventoryItems[i][1]);
SendClientMessage(playerid, -1, string);
}
return 1;
}