SA-MP Forums Archive
Materials don't decrease. - 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: Materials don't decrease. (/showthread.php?tid=459537)



Materials don't decrease. - Mariooo - 23.08.2013

As the title says, my mats won't decrease when using the command: /acceptgun

Everything works fine except that part. Let's have a look at my code.

Код:
dcmd_acceptgun(playerid, params[])
{
	    if(weaponbeingoffered[playerid] == 0) return SendClientMessage(playerid, COLOR_GRAD1, "No-one has offered you a weapon.");
		if(beingofferedby[playerid] > -1)
		{
			new str[128];
	        waitcheck[playerid] = 1;
	        if(waitcheck[playerid] == 2)
	 		waitcheck[playerid] = 0;
	 		new price;
		    GivePlayerValidWeapon(playerid, weaponbeingoffered[playerid], 60000);
			format(str, sizeof(str), "[SOLD]: %s has accepted the weapon.", GetName(playerid));
			SendClientMessage(beingofferedby[playerid], COLOR_CYAN, str);
			format(str, sizeof(str), "[SOLD]: You have accepted the weapon from %s for $%d.", GetName(beingofferedby[playerid]), price);
			SendClientMessage(beingofferedby[playerid], COLOR_CYAN, str);
			beingofferedby[playerid] = -1;
	  		weaponbeingoffered[playerid] = 0;
			PlayerInfo[playerid][pCash] -= GunPrice[playerid];
			PlayerInfo[playerid][pCash] -= GunOffer[playerid];
			if(weaponbeingoffered[playerid] == 23)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 100;
	  		if(weaponbeingoffered[playerid] == 22)
	    	PlayerInfo[beingofferedby[playerid]][pMaterials] -= 150;
	  		if(weaponbeingoffered[playerid] == 25)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 200;
	  		if(weaponbeingoffered[playerid] == 29)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 400;
	  		if(weaponbeingoffered[playerid] == 5)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 25;
	  		if(weaponbeingoffered[playerid] == 33)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 1500;
	  	  	if(weaponbeingoffered[playerid] == 8)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 50;
	  		if(weaponbeingoffered[playerid] == 30)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 2000;
	  		if(weaponbeingoffered[playerid] == 24)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 1000;
	  		if(weaponbeingoffered[playerid] == 27)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 6000;
	  		if(weaponbeingoffered[playerid] == 31)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 3000;
	  		if(weaponbeingoffered[playerid] == 34)
	  		PlayerInfo[beingofferedby[playerid]][pMaterials] -= 7000;
	  		if(weaponbeingoffered[playerid] == 1)
	    	PlayerInfo[beingofferedby[playerid]][pMaterials] -= 50;
		}
		return 1;
	}
This is my acceptgun command.

I will show you my other two commands also.


/getmats command.
Код:
dcmd_getmats(playerid, params[])
{
	#pragma unused params
	if(PlayerInfo[playerid][pJob] != 9) return SendClientMessage(playerid, COLOR_GRAD2, "You're not a weapon dealer.");
	if(CP[playerid] != 0) return SendClientMessage(playerid, COLOR_GRAD2, "You already have an existing material package or checkpoint.");
	if(IsPlayerInRangeOfPoint(playerid, 5, 2099.64, -105.84, 0.68))
	{
	    SetPlayerCheckpoint(playerid, -331.24, -466.16, -0.54, 5.0); // sets a checkpoint.
	    SendClientMessage(playerid, COLOR_YELLOW, "You have loaded the materials, and a marker have been set on your map to the destination.");
		CP[playerid] = 5011;
		return 1;
	}
	if(!IsPlayerInRangeOfPoint(playerid, 5, 1423.70, -1319, 13.55)) return SendClientMessage(playerid, COLOR_GRAD2, "You are not near enough the material pickup.");
	new rand = random(sizeof(MDestinations));
 	SetPlayerCheckpoint(playerid, MDestinations[rand][0], MDestinations[rand][1], MDestinations[rand][2], 3.0); // sets a checkpoint.
    SendClientMessage(playerid, COLOR_YELLOW, "You have loaded the materials, and a marker have been set on your map to the destination.");
	CP[playerid] = 5011;
	return 1;
}
And my /sellgun command.

Код:
dcmd_sellgun(playerid, params[])
{
	if(PlayerInfo[playerid][pJob] != 9)
	{
		SendClientMessage(playerid, COLOR_GRAD2, "You're not a weapon dealer.");
		return 1;
	}

	new choice[32], str[156];
	new price;
	new giveplayerid;
	if(sscanf(params, "us[32]d", giveplayerid, choice, price))
	{
		SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellgun [ID / name or part of name] [weapon] [price]");
		SendClientMessage(playerid, COLOR_GREY, "Weapon Dealer: sdpistol(100 mats) 9mm(150 mats) shotgun(200 mats) ");
		SendClientMessage(playerid, COLOR_GREY, "Weapon Dealer: mp5(400 mats) bat(25 mats) rifle(1500 mats)");
		SendClientMessage(playerid, COLOR_GREY, "Weapon Dealer: katana(50 mats) ak47(2000 mats) deagle(1000 mats)");
		SendClientMessage(playerid, COLOR_GREY, "Weapon Dealer: spas(6000 mats) m4(3000 mats)");
		SendClientMessage(playerid, COLOR_GREY, "Weapon Dealer: sniper(7000 mats) knuckles(50 mats)");
		return 1;
	}
	if(strcmp(choice, "sdpistol", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 100) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 23;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a silenced pistol for $%d /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "9mm", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 150) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 22;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a 9mm pistol for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "shotgun", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 200) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 25;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a shotgun for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "mp5", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 29;
		beingofferedby[giveplayerid] = playerid;
	   	format(str, sizeof(str), "%s has offered you a mp5 for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "bat", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 25) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 5;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a bat for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "ak47", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 1500) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 30;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you an ak47 for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "m4", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 3000) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
   		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 31;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a m4 for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "rifle", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] >= 2000) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 33;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a rifle for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "deagle", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 1000) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 24;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a desert eagle for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "spas", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 6000) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 27;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a spas for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "katana", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 50) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 8;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a katana for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "sniper", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 7000) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 34;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you a sniper for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	if(strcmp(choice, "knuckles", true) == 0)
	{
	    if(PlayerInfo[playerid][pMaterials] < 50) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough materials.");
		if(price < 0) return SendClientMessage(playerid, COLOR_RED, "You can't sell your gun under 0$!");
		GunPrice[giveplayerid] = price;
		GunOffer[giveplayerid] = playerid;
		weaponbeingoffered[giveplayerid] = 1;
		beingofferedby[giveplayerid] = playerid;
	    format(str, sizeof(str), "%s has offered you some knuckles for $%d. /acceptgun to accept it.", GetName(playerid), price);
		SendClientMessage(giveplayerid, COLOR_CYAN, str);
		return 1;
	}
	return 1;
}
Thank you for reading,

Mariooo