SA-MP Forums Archive
Problem when load or attach Item - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem when load or attach Item (/showthread.php?tid=640676)



Problem when load or attach Item - AngeloBrand98 - 05.09.2017

In this script have a cmd /flashlight to spawn flashlight item. But when i typed /flashlight1 or /flashlight2, the item just show like about 1 second. After that its dissapear. I dont know whats wrong, i alread test the cmd using another script and works fine. If you know the problem, please tell me because i really need your help.

Not just the /flashlight1 command, also /fish command didnt work. And also when player bought some item like Hat, Bandana, Mask or Helmet. Its not showing when player try to edit using /itemlist.

Beloww the code :

Code:
CMD:flashlight1(playerid, params[])
{
	if(IsPlayerAttachedObjectSlotUsed(playerid,1)) RemovePlayerAttachedObject(playerid,1);
	if(IsPlayerAttachedObjectSlotUsed(playerid,2)) RemovePlayerAttachedObject(playerid,2);
	SetPlayerAttachedObject(playerid, 1,18656, 5, 0.1, 0.038, -0.1, -90, 180, 0, 0.03, 0.03, 0.03);
	SetPlayerAttachedObject(playerid, 2,18641, 5, 0.1, 0.02, -0.05, 0, 0, 0, 1, 1, 1);
	return 1;
}

CMD:flashlight2(playerid, params[])
{
	if(IsPlayerAttachedObjectSlotUsed(playerid,1)) RemovePlayerAttachedObject(playerid,1);
	if(IsPlayerAttachedObjectSlotUsed(playerid,2)) RemovePlayerAttachedObject(playerid,2);
	SetPlayerAttachedObject(playerid, 1,18656, 5, 0.1, 0.038, -0.01, -90, 180, 0, 0.03, 0.1, 0.03);
	SetPlayerAttachedObject(playerid, 2,18641, 5, 0.1, 0.02, -0.05, 0, 0, 0, 1, 1, 1);
	return 1;
}

CMD:removeflashlight(playerid, params[])
{
    RemovePlayerAttachedObject(playerid,1);
    RemovePlayerAttachedObject(playerid,2);
	return 1;
}

CMD:fish(playerid,params[])
{
	new Float:x,Float:y,Float:z;

    if(IsPlayerInRangeOfPoint(playerid,5.0,354.3251,-2088.7981,7.8359) || IsPlayerInRangeOfPoint(playerid,5.0,362.3351,-2088.7979,7.8359) ||
    IsPlayerInRangeOfPoint(playerid,5.0,367.0258,-2088.7979,7.8359) || IsPlayerInRangeOfPoint(playerid,5.0,369.7540,-2088.7981,7.8359) ||
    IsPlayerInRangeOfPoint(playerid,5.0,374.0645,-2088.7969,7.8359) || IsPlayerInRangeOfPoint(playerid,5.0,383.3422,-2088.7974,7.8359) ||
    IsPlayerInRangeOfPoint(playerid,5.0,390.2083,-2088.7983,7.8359) || IsPlayerInRangeOfPoint(playerid,5.0,396.6046,-2088.7979,7.8359) ||
    IsPlayerInRangeOfPoint(playerid,5.0,403.5682,-2088.7976,7.8359) || IsPlayerInRangeOfPoint(playerid,5.0,409.2429,-2088.6521,7.8359))
    {
		if(FishingRod[playerid] == 0)
			return SendClientMessage(playerid,COLOR_RED,"Error: You dont have a fishing rod!");

		if(Bait[playerid] == 0)
			return SendClientMessage(playerid,COLOR_RED,"Error: You dont have a bait!");

	    if(FishHave[playerid] >= 10)
		    return SendClientMessage(playerid,COLOR_RED,"You have already caught more than 10 fish. Go sell them first.");

		GetPlayerPos(playerid,x,y,z);
	    FishingPosX[playerid] = x;
		FishingPosY[playerid] = y;
		FishingPosZ[playerid] = z;
		ApplyAnimation(playerid,"SWORD","sword_block",50.0 ,0,1,0,1,1);
		SetPlayerAttachedObject(playerid,3, 18632, 6, 0.079376, 0.037070, 0.007706);
		SetTimerEx("PlayerFishing",5000,false,"i",playerid);
		SendClientMessage(playerid,COLOR_WHITE,"Fishing... Don't move!");
		GameTextForPlayer(playerid, "~g~Fishing...", 5000, 3);
        Bait[playerid]--;
	}
	else SendClientMessage(playerid,COLOR_RED,"Error: You are not near any fishing spot!");
	return 1;
Code:
GetClothesItemType(item)
{
	switch (item)
	{
		case 18891, 18892, 18893, 18894, 18895, 18896, 18897, 18898, 18899, 18900, 18901, 18902, 18903, 18904, 18905, 18906, 18907, 18908, 18909, 18910:
		{
			return ITEM_TYPE_BANDANA;
		}
		case 18911, 18912, 18913, 18914, 18915, 18916, 18917, 18918, 18919, 18920, 18974, 19036, 19037, 19038, 19163:
		{
			return ITEM_TYPE_MASK;
		}
		case 18926, 18927, 18928, 18929, 18930, 18931, 18932, 18933, 18934, 18935, 18939, 18940, 18941, 18942, 18943, 18955, 18956, 18957, 18958, 18959, 18960, 18961:
		{
			return ITEM_TYPE_CAP;
		}
		case 18639, 18921, 18922, 18923, 18924, 18947, 18948, 18949, 18950, 18951, 18953, 18954, 18962, 18967, 18968, 18969, 18970, 18971, 18972, 18973, 19067, 19068, 19094, 19095, 19096, 19097, 19098, 19137, 19352, 19487, 19488:
		{
			return ITEM_TYPE_HAT;
		}
		case 19006, 19007, 19008, 19009, 19010, 19011, 19012, 19013, 19014, 19015, 19016, 19017, 19018, 19019, 19020, 19021, 19022, 19023, 19024, 19025, 19026, 19027, 19028, 19029, 19030, 19031, 19032, 19033, 19034, 19035:
		{
			return ITEM_TYPE_GLASSES;
		}
		case 19039, 19040, 19041, 19042, 19043, 19044, 19045, 19046, 19047, 19048, 19049, 19050, 19051, 19052, 19053:
		{
			return ITEM_TYPE_WATCH;
		}
		case 18645, 18936, 18937, 18938, 18952, 18976, 18977, 18978, 18979, 19113, 19114, 19115, 19116, 19117, 19118, 19119, 19120:
		{
			return ITEM_TYPE_HELMET;
		}
	}
	return 0;
}

LoadPlayerClothesItems(playerid)
{
	new string[24], tmp[8], temp1, temp2;
	GetPlayerName(playerid, string, MAX_PLAYER_NAME);
	format(string, 12, "I_%d", dini_Int(AddDirFile(dir_userfiles, string), "account"));
	temp1 = dini_Int(AddDirFile(dir_clothesfiles, string), "clothes");
	for (new i = 0; i < temp1; i++)
	{
		format(tmp, 8, "item%d", i+1);
		temp2 = dini_Int(AddDirFile(dir_clothesfiles, string), tmp);
		pclothesitems[playerid][i] = temp2;
		playeritems[playerid][GetClothesItemType(temp2)] ++;
	}
}

public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
{
	if (response == 1) {
		SetPlayerAttachedObject(playerid, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ);
	}
	new string[256];
	GetPlayerName(playerid, string, MAX_PLAYER_NAME);
	format(string, 24, "P_%d_item%d", dini_Int(AddDirFile(dir_userfiles, string), "account"), GetPVarInt(playerid, "clothesitem3")+1);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "OffsetX", fOffsetX);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "OffsetY", fOffsetY);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "OffsetZ", fOffsetZ);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "RotX", fRotX);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "RotY", fRotY);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "RotZ", fRotZ);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "ScaleX", fScaleX);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "ScaleY", fScaleY);
	dini_FloatSet(AddDirFile(dir_clothesfiles, string), "ScaleZ", fScaleZ);

	return 1;
}