Trunk function (+Added Materials & Drugs) And some bugged.
#1

Код:
new Float:vehTrunkMats[MAX_VEHICLES];
new Float:vehTrunkDrugs[MAX_VEHICLES];
Код:
			else if(strcmp(x_nr,"putmats",true) == 0)
			{
			  new counter = 0;
			  new result;
			  new plyName[MAX_PLAYER_NAME];

			  GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
			  for(new i; i != MAX_VEHICLES; i++)
			  {
			    new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
			    if(dist)
			    {
			      result = i;
			      counter++;
			    }
			  }
			  switch(counter)
			  {
			    case 0:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "No cars with trunk near you");
			      return 1;
			    }

			    case 1:
			    {
			      if(IsPlayerInAnyVehicle(playerid))
			      {
			        SendClientMessage(playerid, COLOR_GREY, "You can't open the trunk while you're in the car");
			        return 1;
			      }
			      if(IsAnOwnableCar(result))
        			{
        			  	if(PlayerInfo[playerid][pPcarkey] == result) { }
        			  	else if(PlayerInfo[playerid][pPcarkey2] == result) { }
        				else if(PlayerInfo[playerid][pPcarkey3] == result) { }
        			  	else
        			  	{
			        		SendClientMessage(playerid, COLOR_GREY, "Trunk is locked !");
			      		return 1;
							}
    					}
			      if(IsABike(result) || IsAOBike(result) || IsAPizzabike(result) || IsABus(result) || IsASweeper(result) || GetVehicleModel(GetPlayerVehicleID(result)) == 523)
        			{
        			  SendClientMessage(playerid, COLOR_GREY, " This vehicle doesn't have the trunk !");
        			  return 1;
        			}

			      //new Float:plyMats;
						//PlayerInfo[playerid][pMats] = plyMats;
						//plyMats = PlayerInfo[playerid][pMats];
			      //GetPlayerArmour(playerid, plyArmour);
            if(PlayerInfo[playerid][pMats] != 0)
			      {
			        //SetPlayerArmour(playerid, 0);
			        //plyMats = vehTrunkMats[result];
			        vehTrunkMats[result] = PlayerInfo[playerid][pMats];
			        GetPlayerName(playerid, sendername, sizeof(sendername));
			        format(string, sizeof(string), "* %s takes off his/her pocket mats and puts it into car trunk.", sendername);
			        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			        SaveTrunk();
			        PlayerInfo[playerid][pMats] = 0;
			        return 1;
			      }
			      else
			      {
			        SendClientMessage(playerid, COLOR_GREY, "Sul ei ole kaasas matse!");
			        return 1;
			      }
			    }

			    default:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  Found more then one car in range");
			      return 1;
			    }
				}
			  return 1;
			}
			else if(strcmp(x_nr,"takemats",true) == 0)
			{
			  new counter = 0;
			  new result;
			  new plyName[MAX_PLAYER_NAME];

			  GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
			  for(new i; i != MAX_VEHICLES; i++)
			  {
			    new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
			    if(dist)
			    {
			      result = i;
			      counter++;
			    }
			  }
			  switch(counter)
			  {
			    case 0:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  No cars with trunk near you");
			      return 1;
			    }

			    case 1:
			    {
			      if(IsPlayerInAnyVehicle(playerid))
			      {
			        SendClientMessage(playerid, COLOR_GREY, "  You can't open the trunk while you're in the car");
			        return 1;
			      }
			      if(IsAnOwnableCar(result))
        			{
        			  	if(PlayerInfo[playerid][pPcarkey] == result) { }
        			  	else if(PlayerInfo[playerid][pPcarkey2] == result) { }
        				else if(PlayerInfo[playerid][pPcarkey3] == result) { }
        			  	else
        			  	{
			        		SendClientMessage(playerid, COLOR_GREY, " Trunk is locked !");
			      		return 1;
							}
    					}
			      if(IsAPlane(result) || IsABike(result) || IsAOBike(result) || IsABoat(result) || IsAPizzabike(result) || IsABus(result) || IsATowcar(result) || IsAHspdCar(result) || IsAHarvest(result) || IsADrugHarvest(result) || IsASweeper(result) || result >=78 && result <= 83 || GetVehicleModel(GetPlayerVehicleID(result)) == 523)
        			{
        			  SendClientMessage(playerid, COLOR_GREY, " This vehicle doesn't have the trunk !");
        			  return 1;
        			}
			      if(vehTrunkMats[result] != 0)
			      {
			        //SetPlayerArmour(playerid, vehTrunkArmour[result]);
							PlayerInfo[playerid][pMats] += vehTrunkMats[result];
			        vehTrunkMats[result] = 0;

			        GetPlayerName(playerid, sendername, sizeof(sendername));
			        format(string, sizeof(string), "* %s takes out the mats from the trunk and puts in pocket.", sendername);
			        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			        SaveTrunk();
			        return 1;
			      }
			      else
			      {
			        SendClientMessage(playerid, COLOR_GREY, "Sellel pagasnikus ei ole matse!");
			        return 1;
			      }
			    }

			    default:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  Found more then one car in range");
			      return 1;
			    }
				}
				return 1;
			}
			else if(strcmp(x_nr,"putdrugs",true) == 0)
			{
			  new counter = 0;
			  new result;
			  new plyName[MAX_PLAYER_NAME];

			  GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
			  for(new i; i != MAX_VEHICLES; i++)
			  {
			    new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
			    if(dist)
			    {
			      result = i;
			      counter++;
			    }
			  }
			  switch(counter)
			  {
			    case 0:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  No cars with trunk near you");
			      return 1;
			    }

			    case 1:
			    {
			      if(IsPlayerInAnyVehicle(playerid))
			      {
			        SendClientMessage(playerid, COLOR_GREY, "  You can't open the trunk while you're in the car");
			        return 1;
			      }
			      if(IsAnOwnableCar(result))
        			{
        			  	if(PlayerInfo[playerid][pPcarkey] == result) { }
        			  	else if(PlayerInfo[playerid][pPcarkey2] == result) { }
        				else if(PlayerInfo[playerid][pPcarkey3] == result) { }
        			  	else
        			  	{
			        		SendClientMessage(playerid, COLOR_GREY, " Trunk is locked !");
			      		return 1;
							}
    					}
			      if(IsABike(result) || IsAOBike(result) || IsAPizzabike(result) || IsABus(result) || IsASweeper(result) || GetVehicleModel(GetPlayerVehicleID(result)) == 523)
        			{
        			  SendClientMessage(playerid, COLOR_GREY, " This vehicle doesn't have the trunk !");
        			  return 1;
        			}

			      //new Float:plyDrugs;
			      //GetPlayerArmour(playerid, plyArmour);
			      //PlayerInfo[playerid][pDrugs] = plyDrugs;
			      //plyDrugs = PlayerInfo[playerid][pDrugs];
            if(PlayerInfo[playerid][pDrugs] != 0)
			      {
			        //SetPlayerArmour(playerid, 0);
			        //vehTrunkArmour[result] = plyDrugs;
							//plyDrugs = vehTrunkDrugs[result];
							vehTrunkDrugs[result] = PlayerInfo[playerid][pDrugs];
			        GetPlayerName(playerid, sendername, sizeof(sendername));
			        format(string, sizeof(string), "* %s takes off his/her pocket drugs and puts it into car trunk.", sendername);
			        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			        SaveTrunk();
			        PlayerInfo[playerid][pDrugs] = 0;
			        return 1;
			      }
			      else
			      {
			        SendClientMessage(playerid, COLOR_GREY, "Sul ei ole mingit uimaste.");
			        return 1;
			      }
			    }

			    default:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  Found more then one car in range");
			      return 1;
			    }
				}
			  return 1;
			}
			else if(strcmp(x_nr,"takedrugs",true) == 0)
			{
			  new counter = 0;
			  new result;
			  new plyName[MAX_PLAYER_NAME];

			  GetPlayerName(playerid, plyName, MAX_PLAYER_NAME);
			  for(new i; i != MAX_VEHICLES; i++)
			  {
			    new dist = CheckPlayerDistanceToVehicle(3.5, playerid, i);
			    if(dist)
			    {
			      result = i;
			      counter++;
			    }
			  }
			  switch(counter)
			  {
			    case 0:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  No cars with trunk near you");
			      return 1;
			    }

			    case 1:
			    {
			      if(IsPlayerInAnyVehicle(playerid))
			      {
			        SendClientMessage(playerid, COLOR_GREY, "  You can't open the trunk while you're in the car");
			        return 1;
			      }
			      if(IsAnOwnableCar(result))
        			{
        			  	if(PlayerInfo[playerid][pPcarkey] == result) { }
        			  	else if(PlayerInfo[playerid][pPcarkey2] == result) { }
        				else if(PlayerInfo[playerid][pPcarkey3] == result) { }
        			  	else
        			  	{
			        		SendClientMessage(playerid, COLOR_GREY, " Trunk is locked !");
			      		return 1;
							}
    					}
			      if(IsAPlane(result) || IsABike(result) || IsAOBike(result) || IsABoat(result) || IsAPizzabike(result) || IsABus(result) || IsATowcar(result) || IsAHspdCar(result) || IsAHarvest(result) || IsADrugHarvest(result) || IsASweeper(result) || result >=78 && result <= 83 || GetVehicleModel(GetPlayerVehicleID(result)) == 523)
        			{
        			  SendClientMessage(playerid, COLOR_GREY, " This vehicle doesn't have the trunk !");
        			  return 1;
        			}
			      if(vehTrunkDrugs[result] != 0)
			      {
			        //SetPlayerArmour(playerid, vehTrunkArmour[result]);
			        PlayerInfo[playerid][pDrugs] += vehTrunkDrugs[result];
			        vehTrunkDrugs[result] = 0;

			        GetPlayerName(playerid, sendername, sizeof(sendername));
			        format(string, sizeof(string), "* %s takes out the body armour from the trunk and puts it on.", sendername);
			        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
			        SaveTrunk();
			        return 1;
			      }
			      else
			      {
			        SendClientMessage(playerid, COLOR_GREY, "Sellel pagasnikus uimaste pole!");
			        return 1;
			      }
			    }

			    default:
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  Found more then one car in range");
			      return 1;
			    }
				}
				return 1;
			}
No errors & warnings.

Explain of bug:
I have nothing drugs, and i give self 100 drugs (/givedrugs), then i do /trunk putdrugs, then system remove my 100 drugs and system puts messy numbers to trunk, then i do /trunk info, i see there 145345234523452345 drugs. Wtf?? 100 drugs?? Same too with materials.
Reply
#2

you didn't edit the Savetrunk et Loadtrunk
Reply
#3

Quote:
Originally Posted by Hip-hop
you didn't edit the Savetrunk et Loadtrunk
I did it.

LoadTrunk

Код:
vehTrunkMats[idx] = floatstr(arrCoords[10]);
vehTrunkDrugs[idx] = floatstr(arrCoords[11]);
SaveTrunk
Код:
vehTrunkMats[idx],
vehTrunkDrugs[idx]);
Reply
#4

new Float:vehTrunkMats[MAX_VEHICLES];
new Float:vehTrunkDrugs[MAX_VEHICLES];

Edit thie by

new vehTrunkMats[MAX_VEHICLES];
new vehTrunkDrugs[MAX_VEHICLES];
Reply
#5

Quote:
Originally Posted by Hip-hop
new Float:vehTrunkMats[MAX_VEHICLES];
new Float:vehTrunkDrugs[MAX_VEHICLES];

Edit thie by

new vehTrunkMats[MAX_VEHICLES];
new vehTrunkDrugs[MAX_VEHICLES];
Done.
Reply
#6

But showed warning's:

Код:
C:\Users\Martin\Desktop\SAMP\gamemodes\sg.pwn(48708) : warning 213: tag mismatch
C:\Users\Martin\Desktop\SAMP\gamemodes\sg.pwn(48709) : warning 213: tag mismatch
Код:
		  vehTrunkMats[idx] = floatstr(arrCoords[10]);
		  vehTrunkDrugs[idx] = floatstr(arrCoords[11]);
// Oh, sorry for doublepost.
Reply
#7

Код:
vehTrunkMats[idx] = strval(arrCoords[10]);
vehTrunkDrugs[idx] = strval(arrCoords[11]);
Reply
#8

I do /trunk takemats

Trunk mats 100 changed to 0
and player stats still 0 mats... must be 100
Reply
#9

Search //trunk system and replace all with the following:

pawn Код:
new vehTrunkCounter[MAX_VEHICLES] = 1;
new vehTrunk[MAX_VEHICLES][MAX_TRUNK_SLOTS];
new vehTrunkAmmo[MAX_VEHICLES][MAX_TRUNK_SLOTS];
new Float:vehTrunkArmour[MAX_VEHICLES];
new vehTrunkDrugs[MAX_VEHICLES];
new vehTrunkMats[MAX_VEHICLES];
new vehTrunkCash[MAX_VEHICLES];
Next, search for SaveTrunk and replace with:

pawn Код:
public SaveTrunk()
{
    new idx;
    new File: file2;
    idx = 1;
    while (idx < sizeof(CarInfo))
    {
        new coordsstring[256];
        format(coordsstring, sizeof(coordsstring), "%i,%i,%i,%i,%i,%i,%i,%i,%i,%f\n",
        vehTrunk[idx][1],
        vehTrunkAmmo[idx][1],
        vehTrunk[idx][2],
        vehTrunkAmmo[idx][2],
        vehTrunk[idx][3],
        vehTrunkAmmo[idx][3],
        vehTrunk[idx][4],
        vehTrunkAmmo[idx][4],
        vehTrunkCounter[idx],
        vehTrunkArmour[idx]);
        if(idx == 1)
        {
            file2 = fopen("trunk.cfg", io_write);
        }
        else
        {
            file2 = fopen("trunk.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}
Next, replace LoadTrunk with this:

pawn Код:
public LoadTrunk()
{
    new arrCoords[13][64];
    new strFromFile2[256];
    new File: file = fopen("trunk.cfg", io_read);
    if (file)
    {
        new idx = 1;
        while (idx < sizeof(CarInfo))
        {
          fread(file, strFromFile2);
          split(strFromFile2, arrCoords, &#39;,');
          vehTrunk[idx][1] = strval(arrCoords[0]);
          vehTrunkAmmo[idx][1] = strval(arrCoords[1]);
          vehTrunk[idx][2] = strval(arrCoords[2]);
          vehTrunkAmmo[idx][2] = strval(arrCoords[3]);
          vehTrunk[idx][3] = strval(arrCoords[4]);
          vehTrunkAmmo[idx][3] = strval(arrCoords[5]);
          vehTrunk[idx][4] = strval(arrCoords[6]);
          vehTrunkAmmo[idx][4] = strval(arrCoords[7]);
          vehTrunkCounter[idx] = strval(arrCoords[8]);
          vehTrunkArmour[idx] = floatstr(arrCoords[9]);
          idx++;
        }
    }
    return 1;
}
Now for the /trunk command:

http://pastebin.com/Uu6LHMDh (( I had to Pastebin it as I exceeded the maximum characters. ))
Reply
#10

PlayerInfo[playerid][pDrugs] = vehTrunkDrugs[result];
vehTrunkDrugs[result] = 0;

Man, that wrong, explain:

I got 100 drugs
trunk got 1 drugs

i take drugs off trunk, and my stats will be 1 drugs...

Should be:

PlayerInfo[playerid][pDrugs] = PlayerInfo[playerid][pDrugs]+vehTrunkDrugs[result];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)