Problem u vezi prodavnice i provere oruzja.

Započeo gasmon, Novembar 05, 2017, 18:50:37 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 1 gost pregledaju ovu temu.

Skripta koju koristim: 0
Detaljan opis problema: Najobicnija prodavnica me koci ceo dan. Pokusavam da dam igracu emku, ali pre toga da proverim da li ima nesto na tom slotu, ako ima da mu to oruzje obrise.
Dio skripte:

OnPlayerDialogResponse --->
[pawn]
               case 6: // M4A1
               {
                  if(IsMoneyHack(playerid))
                  return 1;

                  if(pInfo[playerid][Money] < COST_MAFIA_M4A1)
                  {
                     SendErrorMessage(playerid, "You don't have enough money to buy m4a1.");
                     return 1;
                  }
                  
                  if(IsPlayerUsingWeapon(playerid, 31)) // Ovo mi pravi probleme.
                  {
                     SendErrorMessage(playerid, "You already have m4a1.");
                     return 1;
                  }
                  
                                                pInfo[playerid][Money] -= COST_MAFIA_M4A1
                                                LevelMoney(playerid);
                  GivePlayerWeapon(playerid, 31, 300);
                  SendInfoMessage(playerid, "You bought m4a1.");
               }
[/pawn]

IsPlayerUsingWeapon ---->

[pawn]
IsPlayerUsingWeapon(playerid, _weaponid)
{
   const MAX_WEAPONS_SLOTS = 13;
   static ammo, weaponid;
   
   for (new i; i != MAX_WEAPONS_SLOTS; i++)
   {
      if (GetPlayerWeaponData(playerid, i, weaponid, ammo) == 0)
      {
         return 0;   
      }
      
      if(weaponid && weaponid != _weaponid)
      {
         RemovePlayerWeapon(playerid, weaponid);
         return 0;
      }
      
      if (weaponid == _weaponid && ammo > 0) // you already have...
      {
         return 1;
      }
      
      if(weaponid == _weaponid && ammo < 1) // Give selected weapon
      {
         return 0;      
      }
   }
   return 0;
}
[/pawn]

RemovePlayerWeapon ---->

[pawn]
RemovePlayerWeapon(playerid, weaponid)
{
   new plyWeapons[12];
   new plyAmmo[12];

   for(new slot = 0; slot != 12; slot++)
   {
      new wep, ammo;
      GetPlayerWeaponData(playerid, slot, wep, ammo);
      
      if(wep != weaponid)
      {
         GetPlayerWeaponData(playerid, slot, plyWeapons[slot], plyAmmo[slot]);
      }
   }
   
   ResetPlayerWeapons(playerid);
   for(new slot = 0; slot != 12; slot++)
   {
      GivePlayerWeapon(playerid, plyWeapons[slot], plyAmmo[slot]);
   }
}
[/pawn]
Neke slike/video za lakse dobivanje pomoci(neobavezno):
Poslednja Izmena: Novembar 05, 2017, 18:52:05 POSLE PODNE od gasmon

Resio sam uz pomoc funkcije koju sam smislio, napokon!
Ako je neko nakada imao ili ima isti problem evo resenja ispod.

Ako dajete recimo oruzje emku (koje je slot 5) i igrac ima kalas, broj metkova koje
ste dali igracu sa emkom ce da se sabere sa brojem metkova od kalasa i igrac ce
da dobije emku sa zbirom metkova. Kako bi se to izbeglo koristite funkciju ispod.

SlotToCheck - Broj slota koji se proverava
WeaponToSkip - ID Oruzja koje dajete igracu drugom komandom

[pawn]
CheckForOtherWeapons(playerid, SlotToCheck, WeaponToSkip)
{
   const MAX_WEAPONS_SLOTS = 13;
   static ammo, _weaponid;
   
   for (new i; i != MAX_WEAPONS_SLOTS; i++)
   {
      GetPlayerWeaponData(playerid, i, _weaponid, ammo);

      if (i == SlotToCheck && _weaponid != 0 && ammo > 0 && _weaponid != WeaponToSkip)
      {
         RemovePlayerWeapon(playerid, _weaponid);
      }
   }
}
[/pawn]