11.10.2016, 21:07
Hello everyone,
I cant figure out how i could use this item system to pick up the items that have been saved,
and by picking them up, deleting the item file, and when i want to drop them, create another
file with the item pos in it, modelid and all,
For example i create an item at X,Y,Z using the /citem command, and it automaticly saves in scriptfiles
as Item_1, Item_2... And when i want to pick it up, it deletes the item that i picked up with its file, and
when i drop it it creates another one.
Is this even the right way of doing this, or is there any other way?
I'm not so good at explaining, i hope you get what i mean, the problem is basicaly in OnPlayerPickupItem
Here is the whole script
I cant figure out how i could use this item system to pick up the items that have been saved,
and by picking them up, deleting the item file, and when i want to drop them, create another
file with the item pos in it, modelid and all,
For example i create an item at X,Y,Z using the /citem command, and it automaticly saves in scriptfiles
as Item_1, Item_2... And when i want to pick it up, it deletes the item that i picked up with its file, and
when i drop it it creates another one.
Is this even the right way of doing this, or is there any other way?
I'm not so good at explaining, i hope you get what i mean, the problem is basicaly in OnPlayerPickupItem
Here is the whole script
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>
#include <YSI\y_ini>
#define MAX_ITEMS 100
#define ORANGERED 0xFF4500FF
#define FILE_PATH "Items/Item_%d.ini"
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
main(){}
new IdofFile[MAX_PLAYERS];
enum ItemEnum
{
ItemID,
ItemModel,
Float:ItemPosX,
Float:ItemPosY,
Float:ItemPosZ,
Text3D:ItemText[128],
ItemTextSave[128],
}
new ItemInfo[MAX_ITEMS][ItemEnum];
forward SaveItem(fileid);
public SaveItem(fileid)
{
new dFile[128];
format(dFile, sizeof(dFile),FILE_PATH,fileid);
new INI:File = INI_Open(dFile);
INI_WriteInt(File,"Model",ItemInfo[fileid][ItemModel]);
INI_WriteFloat(File,"X",ItemInfo[fileid][ItemPosX]);
INI_WriteFloat(File,"Y",ItemInfo[fileid][ItemPosY]);
INI_WriteFloat(File,"Z",ItemInfo[fileid][ItemPosZ]);
INI_WriteString(File,"Text", ItemInfo[fileid][ItemTextSave]);
INI_Close(File);
return 1;
}
forward LoadItem(fileid, name[], value[]);
public LoadItem(fileid, name[], value[])
{
INI_Int("Model",ItemInfo[fileid][ItemModel]);
INI_Float("X",ItemInfo[fileid][ItemPosX]);
INI_Float("Y",ItemInfo[fileid][ItemPosY]);
INI_Float("Z",ItemInfo[fileid][ItemPosZ]);
INI_String("Text",ItemInfo[fileid][ItemTextSave], 128);
return 1;
}
forward OnPlayerPickupItem(playerid);
public OnPlayerPickupItem(playerid)
{
for(new i = 0; i < sizeof(ItemInfo); i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.0,ItemInfo[i][ItemPosX],ItemInfo[i][ItemPosY],ItemInfo[i][ItemPosZ]))
{
new dFile[128], fileid;
IdofFile[i] = fileid;
format(dFile, sizeof(dFile),FILE_PATH,fileid);
if(!fexist(dFile)) return SendClientMessage(playerid, -1, "That file does not exist!");
fremove(dFile);
DestroyDynamicObject(ItemInfo[fileid][ItemID]);
Delete3DTextLabel(ItemInfo[fileid][ItemText]);
ItemInfo[fileid][ItemModel] = 0;
ItemInfo[fileid][ItemPosX] = 0.0;
ItemInfo[fileid][ItemPosY] = 0.0;
ItemInfo[fileid][ItemPosZ] = 0.0;
ItemInfo[fileid][ItemTextSave] = 0;
}
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_WALK))
{
OnPlayerPickupItem(playerid);
}
return 1;
}
public OnGameModeInit()
{
for(new b = 0; b < sizeof(ItemInfo); b++)
{
new gFile[35];
format(gFile, 50, FILE_PATH ,b);
if(fexist(gFile))
{
INI_ParseFile(gFile, "LoadItem", .bExtra = true, .extra = b);
if(ItemInfo[b][ItemModel] != 0)
{
ItemInfo[b][ItemID] = CreateDynamicObject(ItemInfo[b][ItemModel], ItemInfo[b][ItemPosX], ItemInfo[b][ItemPosY], ItemInfo[b][ItemPosZ],0,0,0,-1, -1, -1);
}
}
}
return 1;
}
public OnPlayerConnect(playerid)
{
IdofFile[playerid] = -1;
return 1;
}
CMD:citem(playerid, params[])
{
new fileid = 0;
for(new i = 0; i < sizeof(ItemInfo); i++)
{
if(ItemInfo[i][ItemModel] != 0)
{
fileid = i+1;
}
}
if(fileid > MAX_ITEMS) return SendClientMessage(playerid, -1, "MAX_ITEMS reached, u cannot create more ITEMS");
new ObjectID, ObjectName[128], Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
if(sscanf(params, "ds[128]", ObjectID, ObjectName)) return SendClientMessage(playerid, ORANGERED, "USAGE: {FFFFFF}/item [Item ID][Item name]");
ItemInfo[fileid][ItemModel] = ObjectID;
ItemInfo[fileid][ItemPosX] = X;
ItemInfo[fileid][ItemPosY] = Y;
ItemInfo[fileid][ItemPosZ] = Z;
ItemInfo[fileid][ItemText] = Create3DTextLabel(ObjectName, 0x1E90FFFF,X,Y,Z, 5.0, 0, 0);
ItemInfo[fileid][ItemID] = CreateDynamicObject(ObjectID, X, Y, Z-1,0,0,0,-1, -1, -1);
ItemInfo[fileid][ItemTextSave] = ObjectName;
IdofFile[playerid] = fileid;
SaveItem(IdofFile[playerid]);
SendClientMessage(playerid, -1, "You have created an object");
return 1;
}
CMD:ditem(playerid, params[])
{
new dFile[128], fileid;
if(sscanf(params, "i", fileid))
{
SendClientMessage(playerid, -1, "/ditem [FILE ID]");
return 1;
}
format(dFile, sizeof(dFile),FILE_PATH,fileid);
if(!fexist(dFile)) return SendClientMessage(playerid, -1, "That file does not exist!");
fremove(dFile);
DestroyDynamicObject(ItemInfo[fileid][ItemID]);
Delete3DTextLabel(ItemInfo[fileid][ItemText]);
ItemInfo[fileid][ItemModel] = 0;
ItemInfo[fileid][ItemPosX] = 0.0;
ItemInfo[fileid][ItemPosY] = 0.0;
ItemInfo[fileid][ItemPosZ] = 0.0;
ItemInfo[fileid][ItemTextSave] = 0;
SendClientMessage(playerid, -1, "You have destroyed item");
return 1;
}