#define PRESSED (%0) #define MAX_LOOTS 100 new LootObjects[MAX_LOOTS] = { INVALID_OBJECT_ID, ... };
// Objects LootObjects[0] = CreateDynamicObject(1210, 254.31627, 4158.11377, 8.95453, 0.00000, 0.00000, 0.00000); // Medkit LootObjects[1] = CreateDynamicObject(1484, 247.87740, 4188.77002, 8.90115, 0.00000, 0.00000, 0.00000); // Beer Bottle LootObjects[2] = CreateDynamicObject(2806, 247.98601, 4100.01758, 3.42860, 0.00000, 0.00000, 0.00000); // Human Meat LootObjects[3] = CreateDynamicObject(2806, 248.70003, 4103.33936, 4.03377, 0.00000, 0.00000, 0.00000); // Human Meat LootObjects[4] = CreateDynamicObject(336, 136.25269, 4179.93018, 28.80020, -50.00000, 0.00000, 0.00000); // Bat in tree LootObjects[5] = CreateDynamicObject(1265, 289.96664, 4068.64990, 0.57592, 0.00000, 0.00000, 0.00000); // Bag with: Medkit, bandage LootObjects[6] = CreateDynamicObject(2891, 201.18965, 4179.41357, 8.75100, 0.00000, 0.00000, 0.00000); // Bandage LootObjects[7] = CreateDynamicObject(1582, 126.10010, 4083.24170, 0.07406, 10.00000, 0.00000, 0.00000); // Stranded Pizza
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if (newkeys & KEY_YES) { ShowInventory(playerid); return 1; } if (newkeys & KEY_NO) { if(IsValidObject(LootObjects[0]) && IsPlayerInRangeOfPoint(playerid,3.0, 254.31627, 4158.11377, 8.95453)) { ApplyAnimation(playerid,"BOMBER","BOM_PLANT_2IDLE",4.1,1,1,1,1,1,1); AddItem(playerid,"Small Medkit",1); SendClientMessage(playerid, -4, "* Small medical kit added to your inventory."); DestroyObject(LootObjects[0]); } } return 1; }
public OnPlayerUseItem(playerid,ItemName[]) { if(!strcmp(ItemName,"Medkit",true)) { new Float:hp; GetPlayerHealth(playerid,hp); if(hp>=100)return SendClientMessage(playerid,-1,"* You already have full health!"); SetPlayerHealth(playerid,100); RemoveItem(playerid,ItemName,1); return SendClientMessage(playerid,-1,"* You used a medkit."); } return 0; }
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
I am occuring a problem with the looting system I'm developing for my server. I can't pick up objects somehow, and I'd be happy if somebody could help me.
Code: Код:
#define PRESSED (%0) #define MAX_LOOTS 100 new LootObjects[MAX_LOOTS] = { INVALID_OBJECT_ID, ... }; Код:
// Objects LootObjects[0] = CreateDynamicObject(1210, 254.31627, 4158.11377, 8.95453, 0.00000, 0.00000, 0.00000); // Medkit LootObjects[1] = CreateDynamicObject(1484, 247.87740, 4188.77002, 8.90115, 0.00000, 0.00000, 0.00000); // Beer Bottle LootObjects[2] = CreateDynamicObject(2806, 247.98601, 4100.01758, 3.42860, 0.00000, 0.00000, 0.00000); // Human Meat LootObjects[3] = CreateDynamicObject(2806, 248.70003, 4103.33936, 4.03377, 0.00000, 0.00000, 0.00000); // Human Meat LootObjects[4] = CreateDynamicObject(336, 136.25269, 4179.93018, 28.80020, -50.00000, 0.00000, 0.00000); // Bat in tree LootObjects[5] = CreateDynamicObject(1265, 289.96664, 4068.64990, 0.57592, 0.00000, 0.00000, 0.00000); // Bag with: Medkit, bandage LootObjects[6] = CreateDynamicObject(2891, 201.18965, 4179.41357, 8.75100, 0.00000, 0.00000, 0.00000); // Bandage LootObjects[7] = CreateDynamicObject(1582, 126.10010, 4083.24170, 0.07406, 10.00000, 0.00000, 0.00000); // Stranded Pizza Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if (newkeys & KEY_YES) { ShowInventory(playerid); return 1; } if (newkeys & KEY_NO) { if(IsValidObject(LootObjects[0]) && IsPlayerInRangeOfPoint(playerid,3.0, 254.31627, 4158.11377, 8.95453)) { ApplyAnimation(playerid,"BOMBER","BOM_PLANT_2IDLE",4.1,1,1,1,1,1,1); AddItem(playerid,"Small Medkit",1); SendClientMessage(playerid, -4, "* Small medical kit added to your inventory."); DestroyObject(LootObjects[0]); } } return 1; } Код:
public OnPlayerUseItem(playerid,ItemName[]) { if(!strcmp(ItemName,"Medkit",true)) { new Float:hp; GetPlayerHealth(playerid,hp); if(hp>=100)return SendClientMessage(playerid,-1,"* You already have full health!"); SetPlayerHealth(playerid,100); RemoveItem(playerid,ItemName,1); return SendClientMessage(playerid,-1,"* You used a medkit."); } return 0; } Код:
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase |
new Float:health; GetPlayerHealth(playerid,health); if (health < 100.0) { SendClientMessage(playerid,-1,"* You already have full health!"); } return 1; }
#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
Код:
new Float:health; GetPlayerHealth(playerid,health); if (health < 100.0) { SendClientMessage(playerid,-1,"* You already have full health!"); } return 1; } |
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. pawn Код:
|
That's a useless one, actually. But thanks for the attempt
That should do the trick. Thanks! |
I didn't read the whole threath sry Im lazy.I thought you had another error...
|
How does somebody pick up an object. And how does somebody enter his inventory?
|
#define PICKUP_RANGE 1.0
stock TryPickupItem(playerid)
{
foreach(new i : ItemIndex)
{
if(IsPlayerInRangeOfPoint(playerid, PICKUP_RANGE, ItemData[index][gItemX], ItemData[index][gItemY], ItemData[index][gItemZ])) return i;
}
return INVALID_ITEM_ID;
}