18.12.2013, 14:24
This is not really how a loot system should work.
There is too much for me to really explain how to do it all without spending quite a bit of time but I think I have a loot script somewhere that is basically a scaffold that can be implemented let me see if I can dig it out.
Anyways you would need to create your own pickup function, sqlite saving etc but this gives you the structure of Creating/Deleting inventory items which is the core of this kind of system.
There is too much for me to really explain how to do it all without spending quite a bit of time but I think I have a loot script somewhere that is basically a scaffold that can be implemented let me see if I can dig it out.
Anyways you would need to create your own pickup function, sqlite saving etc but this gives you the structure of Creating/Deleting inventory items which is the core of this kind of system.
pawn Код:
#include <a_samp>
#include <zcmd>
// This would be in a seperate file
#include <YSI\y_iterate>
#include <streamer>
enum TEXTUREINFO
{
tModelID,
tTXD[32],
tTexture[32],
}
// Texture references
stock const TextureData[][TEXTUREINFO] = {
{0,"INVALID","INVALID"},
{3922,"bistro","vent_64"},
{3922,"bistro","Tablecloth"},
{3922,"bistro","sw_wallbrick_01"},
{3922,"bistro","sw_door11"}
};
#define ITEM_TYPE_NONE 0
#define ITEM_TYPE_MEDKIT 1
#define ITEM_TYPE_WATER 2
// Item type definition
enum ITEMTYPEINFO
{
gItemType,
gModelID,
gMaterialRef,
gModelColor,
Float:gItemOffX,
Float:gItemOffY,
Float:gItemOffZ,
Float:gItemOffRX,
Float:gItemOffRY,
Float:gItemOffRZ
};
// Type info
stock const ItemTypeDef[][ITEMTYPEINFO] = {
{ ITEM_TYPE_NONE, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, // Dummy place holder
{ ITEM_TYPE_MEDKIT, 3112, 3, 0, -403.5044,2252.7073,44.4297, 0.0, 0.0, 0.0 },
{ ITEM_TYPE_WATER, 1484, 1, 0xFF0000FF, 0.0, 0.0, -0.5, 0.0, 0.0, 0.0 }
};
#define MAX_ITEM_NAME 32
enum ITEMNAMEINFO
{
ItemType,
ItemName[MAX_ITEM_NAME]
};
stock const ItemNames[][ITEMNAMEINFO] = {
{ ITEM_TYPE_NONE, "None" },
{ ITEM_TYPE_MEDKIT, "First Aid Kit" },
{ ITEM_TYPE_WATER, "Waterbottle" }
};
#define MAX_ITEMS 3000
#define INVALID_ITEM_ID (0xFFFF)
// Item info
enum ITEMDATAINFO
{
gItemType,
gItemObjectID,
gItemTime,
Text3D:gItem3DText,
Float:gItemX,
Float:gItemY,
Float:gItemZ,
Float:gItemRX,
Float:gItemRY,
Float:gItemRZ,
}
new Iterator:ItemIndex<MAX_ITEMS>;
new ItemData[MAX_ITEMS][ITEMDATAINFO];
stock CreateInventoryItem(itemType, Float:posx, Float:posy, Float:posz, vworld = -1, interior = -1, playerid = -1, Float:StreamDist = 300.0, Float:DrawDistance = 300.0)
{
new index = Iter_Free(ItemIndex);
if(index != -1)
{
Iter_Add(ItemIndex, index);
// Record item data
ItemData[index][gItemX] = posx + ItemTypeDef[itemType][gItemOffX];
ItemData[index][gItemY] = posy + ItemTypeDef[itemType][gItemOffY];
ItemData[index][gItemZ] = posz + ItemTypeDef[itemType][gItemOffZ];
ItemData[index][gItemRX] = ItemTypeDef[itemType][gItemOffRX];
ItemData[index][gItemRY] = ItemTypeDef[itemType][gItemOffRY];
ItemData[index][gItemRZ] = ItemTypeDef[itemType][gItemOffRZ];
// Save item type
ItemData[index][gItemType] = itemType;
// Save create time
ItemData[index][gItemTime] = GetTickCount();
// Create object
ItemData[index][gItemObjectID] = CreateDynamicObject(ItemTypeDef[itemType][gModelID],
ItemData[index][gItemX],
ItemData[index][gItemY],
ItemData[index][gItemZ],
ItemData[index][gItemRX],
ItemData[index][gItemRY],
ItemData[index][gItemRZ],
vworld,
interior,
playerid,
StreamDist);
// Set material
if(ItemTypeDef[itemType][gMaterialRef] != 0) SetDynamicObjectMaterial(ItemData[index][gItemObjectID], // gMaterialModel
0, TextureData[ItemTypeDef[itemType][gMaterialRef]][tModelID],
TextureData[ItemTypeDef[itemType][gMaterialRef]][tTXD],
TextureData[ItemTypeDef[itemType][gMaterialRef]][tTexture],
ItemTypeDef[itemType][gModelColor]);
// Create 3D Text
ItemData[index][gItem3DText] = CreateDynamic3DTextLabel(ItemNames[itemType][ItemName], -1,
ItemData[index][gItemX],
ItemData[index][gItemY],
ItemData[index][gItemZ] + 0.5,
300.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID,
0, -1, -1, -1, 30.0);
// Update streamer data
Streamer_SetFloatData(STREAMER_TYPE_OBJECT,ItemData[index][gItemObjectID],E_STREAMER_DRAW_DISTANCE,DrawDistance);
// Save To sqlite
return index;
}
// All item slots full find longest exising item
else
{
new LongestIndex;
new LongestTime = 2147483647;
foreach(new i : ItemIndex)
{
if(ItemData[i][gItemTime] < LongestTime)
{
LongestTime = ItemData[i][gItemTime];
LongestIndex = i;
}
}
// Delete longest existing item
DeleteInventoryItem(LongestIndex);
// Create item again
CreateInventoryItem(itemType, posx, posy, posz, vworld, interior, playerid, StreamDist, DrawDistance);
}
return INVALID_ITEM_ID;
}
stock DeleteInventoryItem(index)
{
if(ItemData[index][gItemType] != ITEM_TYPE_NONE)
{
// Destroy object
DestroyDynamicObject(ItemData[index][gItemObjectID]);
// Destroy 3d text
// Destroy 3d text label
DestroyDynamic3DTextLabel(ItemData[index][gItem3DText]);
// Record item data
ItemData[index][gItemX] = 0.0;
ItemData[index][gItemY] = 0.0;
ItemData[index][gItemZ] = 0.0;
ItemData[index][gItemRX] = 0.0;
ItemData[index][gItemRY] = 0.0;
ItemData[index][gItemRZ] = 0.0;
// Set item type
ItemData[index][gItemType] = ITEM_TYPE_NONE;
Iter_Remove(ItemIndex, index);
// Save to sqlite
return 1;
}
return INVALID_ITEM_ID;
}
CMD:spawnbottle(playerid, arg[])
{
CreateInventoryItem(ITEM_TYPE_WATER, 0.0, 0.0, 3.5, -1, -1, -1, 300.0, 300.0);
return 1;
}
// My other functions here