[Help] with /buygun !! doesnt work for ammo
#1

Hi i have this problem with this command.
I think its the same command and kind for many roleplays
Well the problem is that i cant buy ammo and i still dont know why but im sure that the problem is here:

Код:
	if (strcmp(cmd, "/buygun", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(GetPlayerMoney(playerid) < 1)
			{
			    SendClientMessage(playerid, COLOR_GREY, "   You dont have enough money with you !");
			    return 1;
			}
			new gun;
			new gunid[16];
			new gunstring1[256];
			new gunstring2[256];
			new gunstring3[256];
			new gunstring4[256];
			new gunstring5[256];
			new infostring[256];
			new guncharge;
			new ammocharge;
			new location = PlayerInfo[playerid][pLocal];
			if(location == 99 || location == 100 || location == 102 || location == 104 || location == 105 || location == 108)
			{
			    if(BizzInfo[location-99][bProducts] <= 0)
			    {
			        GameTextForPlayer(playerid, "~r~Out Of Stock", 5000, 1);
					return 1;
			    }
				new mod = 100;
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					format(string, sizeof(string), "USAGE: /buygun [gunname] [ammoamount]");
					SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
					SendClientMessage(playerid, COLOR_WHITE,"*** Guns & Ammo ***");
					SendClientMessage(playerid, COLOR_GRAD2,string);
					format(gunstring1, 256, "Weapons: parachute ($%d) golfclub ($%d) nightstick ($%d) baseballbat ($%d) shovel ($%d) poolcue ($%d)",
					GunPrice[0][0]/100*mod,GunPrice[1][0]/100*mod,GunPrice[2][0]/100*mod,GunPrice[3][0]/100*mod,GunPrice[4][0]/100*mod,GunPrice[5][0]/100*mod,GunPrice[6][0]/100*mod);
					SendClientMessage(playerid, COLOR_GRAD3, gunstring1);
					format(gunstring2, 256, "Weapons: purpledildo ($%d) whitedildo ($%d) longwhitedildo ($%d) whitedildo2 ($%d) flowers ($%d) cane",
					GunPrice[7][0]/100*mod,GunPrice[8][0]/100*mod,GunPrice[9][0]/100*mod,GunPrice[10][0]/100*mod,GunPrice[11][0]/100*mod,GunPrice[12][0]/100*mod);
					SendClientMessage(playerid, COLOR_GRAD3, gunstring2);
					format(gunstring3, 256, "Weapons: sdpistol ($%d) deagle ($%d) mp5 ($%d)",
					GunPrice[13][0]/100*mod,GunPrice[14][0]/100*mod,GunPrice[15][0]/100*mod,GunPrice[16][0]/100*mod,GunPrice[17][0]/100*mod,GunPrice[18][0]/100*mod);
					SendClientMessage(playerid, COLOR_GRAD3, gunstring3);
					format(gunstring4, 256, "Weapons: shotgun ($%d) ak47 ($%d) m4 ($%d) rifle ($%d)",
					GunPrice[19][0]/100*mod,GunPrice[20][0]/100*mod,GunPrice[21][0]/100*mod,GunPrice[22][0]/100*mod,GunPrice[23][0]/100*mod,GunPrice[24][0]/100*mod);
					SendClientMessage(playerid, COLOR_GRAD3, gunstring4);
					format(gunstring5, 256, "Weapons: deagleammo ($5) shotgunammo ($5) m4ammo ($5) mp5ammo ($5) rifleammo ($5)");
					SendClientMessage(playerid, COLOR_GRAD3, gunstring5);
					SendClientMessage(playerid, COLOR_GRAD3, "Weapons: bomb ($150000)");
					SendClientMessage(playerid, COLOR_GREEN,"_______________________________________");
					return 1;
				}
				strmid(gunid, tmp, 0, strlen(cmdtext), 255);
				tmp = strtok(cmdtext, idx);
				if(!strlen(tmp))
				{
					format(string, sizeof(string), "USAGE: /buygun [gunname] [ammoamount]");
					return 1;
				}
				new ammo = strval(tmp);
				if(ammo < 1 || ammo > 999) { SendClientMessage(playerid, COLOR_GREY, "   Ammo ammount not lower then 1 or higher then 999 !"); return 1; }
				if (strcmp(gunid, "parachute", true, strlen(gunid)) == 0)
				{
					gun = 46;
					guncharge = GunPrice[0][0]/100*mod;
					ammocharge = 0;
				}
				else if (strcmp(gunid, "golfclub", true, strlen(gunid)) == 0)
				{
					gun = 2; guncharge = GunPrice[1][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 2; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "nightstick", true, strlen(gunid)) == 0)
				{
					gun = 3; guncharge = GunPrice[2][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 3; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "baseballbat", true, strlen(gunid)) == 0)
				{
					gun = 5; guncharge = GunPrice[4][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 5; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "shovel", true, strlen(gunid)) == 0)
				{
					gun = 6; guncharge = GunPrice[5][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 6; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "poolcue", true, strlen(gunid)) == 0)
				{
					gun = 7; guncharge = GunPrice[6][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 7; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "purpledildo", true, strlen(gunid)) == 0)
				{
					gun = 10; guncharge = GunPrice[7][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 10; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "whitedildo", true, strlen(gunid)) == 0)
				{
					gun = 11; guncharge = GunPrice[8][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 11; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "longwhitedildo", true, strlen(gunid)) == 0)
				{
					gun = 12; guncharge = GunPrice[9][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 12; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "whitedildo2", true, strlen(gunid)) == 0)
				{
					gun = 13; guncharge = GunPrice[10][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 13; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "flowers", true, strlen(gunid)) == 0)
				{
					gun = 14; guncharge = GunPrice[11][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 14; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "cane", true, strlen(gunid)) == 0)
				{
					gun = 15; guncharge = GunPrice[12][0]/100*mod; ammocharge = 0;
					PlayerInfo[playerid][pGun1] = 15; PlayerInfo[playerid][pAmmo1] = 1;
				}
				else if (strcmp(gunid, "sdpistol", true, strlen(gunid)) == 0)
				{
					gun = 23; guncharge = GunPrice[13][0]/100*mod; ammocharge = GunPrice[25][0]*ammo;
					PlayerInfo[playerid][pGun2] = 23; PlayerInfo[playerid][pAmmo2] = ammo;
				}
				else if (strcmp(gunid, "deagle", true, strlen(gunid)) == 0)
				{
					gun = 24; guncharge = GunPrice[15][0]/100*mod; ammocharge = GunPrice[25][0]*ammo;
					PlayerInfo[playerid][pGun2] = 24; PlayerInfo[playerid][pAmmo2] = ammo;
				}
				else if (strcmp(gunid, "mp5", true, strlen(gunid)) == 0)
				{
					gun = 29; guncharge = GunPrice[18][0]/100*mod; ammocharge = GunPrice[27][0]*ammo;
					PlayerInfo[playerid][pGun3] = 29; PlayerInfo[playerid][pAmmo3] = ammo;
				}
				else if (strcmp(gunid, "shotgun", true, strlen(gunid)) == 0)
				{
					gun = 25; guncharge = GunPrice[19][0]/100*mod; ammocharge = GunPrice[26][0]*ammo;
					PlayerInfo[playerid][pGun3] = 25; PlayerInfo[playerid][pAmmo3] = ammo;
				}
				else if (strcmp(gunid, "ak47", true, strlen(gunid)) == 0)
				{
					gun = 30; guncharge = GunPrice[22][0]/100*mod; ammocharge = GunPrice[28][0]*ammo;
					PlayerInfo[playerid][pGun4] = 30; PlayerInfo[playerid][pAmmo4] = ammo;
				}
				else if (strcmp(gunid, "m4", true, strlen(gunid)) == 0)
				{
					gun = 31; guncharge = GunPrice[23][0]/100*mod; ammocharge = GunPrice[28][0]*ammo;
					PlayerInfo[playerid][pGun4] = 31; PlayerInfo[playerid][pAmmo4] = ammo;
				}
				else if (strcmp(gunid, "rifle", true, strlen(gunid)) == 0)
				{
					gun = 33; guncharge = GunPrice[24][0]/100*mod; ammocharge = GunPrice[29][0]*ammo;
					PlayerInfo[playerid][pGun4] = 33; PlayerInfo[playerid][pAmmo4] = ammo;
				}
				else if (strcmp(gunid, "deagleammo", true, strlen(gunid)) == 0)
				{
					if(PlayerInfo[playerid][pGun4] != 24) {}
					else
					{
						SCM(playerid,COLOR_GREY," You need a deagle"," Tu nao tens uma deagle!");
					}
					PlayerInfo[playerid][pAmmo2] = ammo;
				}
				else if (strcmp(gunid, "shotgunammo", true, strlen(gunid)) == 0)
				{
					if(PlayerInfo[playerid][pGun4] != 25) {}
					else
					{
						SCM(playerid,COLOR_GREY," You need a shotgun"," Tu nao tens uma shotgun!");
					}
					PlayerInfo[playerid][pAmmo3] = ammo;
				}
				else if (strcmp(gunid, "m4ammo", true, strlen(gunid)) == 0)
				{
					if(PlayerInfo[playerid][pGun4] != 31) {}
					else
					{
						SCM(playerid,COLOR_GREY," You need a M4"," Tu nao tens uma M4!");
					}
					PlayerInfo[playerid][pAmmo4] = ammo;
				}
				else if (strcmp(gunid, "mp5ammo", true, strlen(gunid)) == 0)
				{
					if(PlayerInfo[playerid][pGun4] != 29) {}
					else
					{
						SCM(playerid,COLOR_GREY," You need a MP5"," Tu nao tens uma MP5!");
					}
					PlayerInfo[playerid][pAmmo3] = ammo;
				}
				else if (strcmp(gunid, "rifleammo", true, strlen(gunid)) == 0)
				{
					if(PlayerInfo[playerid][pGun4] != 33) {}
					else
					{
						SCM(playerid,COLOR_GREY," You need a Rifle"," Tu nao tens uma Rifle!");
					}
					PlayerInfo[playerid][pAmmo4] = ammo;
				}
				else if (strcmp(gunid, "bomb", true, strlen(gunid)) == 0)
				{
					ammocharge = 75000;
					guncharge = 75000;
					gun = 999;
				}
				else
				{
					SendClientMessage(playerid, COLOR_GRAD6, "ShopKeeper says: I have never heard of that weapon.");
					return 1;
				}
				if((guncharge+ammocharge) > GetPlayerMoney(playerid))
				{
					format(infostring, 256, "   You don't have $%d !",guncharge+ammocharge);
					SendClientMessage(playerid, COLOR_GRAD3, infostring);
					return 1;
				}
				if(GetPlayerMoney(playerid) < (guncharge+ammocharge))
				{
				    SendClientMessage(playerid, COLOR_GREY, "   Can't afford that !");
				    return 1;
				}
				if(gun == 999)
				{
				    ammo = 1;
				}
				new payout = guncharge + ammocharge;
				format(infostring, 256, "You have purchased %s with %d ammo for $%d",gunid,ammo,payout);
				SendClientMessage(playerid, COLOR_GRAD3, infostring);
				if(location == 102 && IsACop(playerid)) { }
				else if(location == 104 && IsACop(playerid)) { }
				else if(location == 105 && IsACop(playerid)) { }
				else { GivePlayerMoney(playerid, - payout); }
				if(gun != 999) {  BizzInfo[location-99][bTill] += payout; ExtortionBiz(location-99, payout);  }
				else { BizzInfo[location-99][bTill] += 15000; ExtortionBiz(location-99, 15000);  }
				BizzInfo[location-99][bProducts]-=2;
				PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
				if(gun != 999) {  GivePlayerWeapon(playerid, gun, ammo);  }
				else { PlayerInfo[playerid][pBomb] += ammo; }
				if(IsACop(playerid) && OnDuty[playerid] < 1) { PlayerInfo[playerid][pBomb] = 0; }
				GetPlayerName(playerid, sendername, sizeof(sendername));
				format(string, sizeof(string), "%s bought weapons for $%d at biz %d", sendername, payout, location-99);
				printf("%s", string);
				PayLog(string);
			}
			else
			{
			    SendClientMessage(playerid, COLOR_WHITE,"You are not in a store.");
				return 1;
			}
		}
		return 1;
	}

I can do /buygun m4ammo 400 but i get this message
"You have bought 400ammo for 0$ "
but this gives no ammo
Reply
#2

you forgot to mention SetPlayerAmmo
Reply
#3

Quote:
Originally Posted by Mr.Stranger
Посмотреть сообщение
you forgot to mention SetPlayerAmmo
That ^ and....

pawn Код:
new gunstring1[256];
            new gunstring2[256];
            new gunstring3[256];
            new gunstring4[256];
            new gunstring5[256];
            new infostring[256];
You will find some very useful information about strings and cell allocation here: https://sampforum.blast.hk/showthread.php?tid=55261
Reply
#4

Thx Mr Strange but Im not good scripter to do that , can someone try to make it for me ?

PD @funky thx too but i already did that
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)