Boosters in shop not working

09/16/2020 17:12 KnightCreeper023#1
Hi I want to ask why it doesn't work for me to join the game when I buy a booster. In emulator 10.

tell me that

Code:
Failed loading user ship / ShipInitializationHandler ERROR
but when I throw it in a chat game it works.

I would like to ask if this code is spelled correctly.

Code:
try{
		  if ($_SERVER['REQUEST_METHOD'] === 'POST' && Functions::IsLoggedIn()) {
			$player = Functions::GetPlayer();
		$notOnlineOrOnlineAndInEquipZone =  (!Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)));
if ($notOnlineOrOnlineAndInEquipZone) {
				  if ($shop['items'][$itemId]['category'] == 'boosters') {
            if ($shop['items'][$itemId]['category'] == 'boosters') { // Ships
              
               //array_push($boosters->Type, $shop['items'][$itemId]['shipId']);
               //1     mysql_fetch_object($boosters,$shop['items'][$itemId]['shipId']);
			   $boosters= $shop['items'][$itemId]['shipId'];
                $status = true;
              
            }
          }
				} else {
					 $json['message'] = 'ERROR, you are logged in, please log out';
				}
		
		
	    }
}
09/16/2020 18:10 Rushle#2
It's hard to tell as the PHP code that you've provided inherits variables that isn't included

Both the $shop and $itemId isn't declared any where in the code and I also noticed

PHP Code:
if ($shop['items'][$itemId]['category'] == 'boosters') {
            if (
$shop['items'][$itemId]['category'] == 'boosters') { // Ships 
Is duplicated

However I'm not sure this code will change anything but I've cleaned the code a bit so the if statements isnt nested like before

PHP Code:
try{
    if (! 
$_SERVER['REQUEST_METHOD'] === 'POST' && ! Functions::IsLoggedIn()) {
        die(
"Method wasn't a POST and you aren't logged in");
    }

    
$player Functions::GetPlayer();
    
$notOnlineOrOnlineAndInEquipZone = (!Socket::Get('IsOnline', array('UserId' => $player['userId'], 'Return' => false)));

    if (! 
$notOnlineOrOnlineAndInEquipZone) {
        
$json['message'] = 'ERROR, you are logged in, please log out';
        exit;
    }

    if (! 
$shop['items'][$itemId]['category'] == 'boosters') { // Ships
        
die("Not a booster");
    }

    
//array_push($boosters->Type, $shop['items'][$itemId]['shipId']);
    //1     mysql_fetch_object($boosters,$shop['items'][$itemId]['shipId']);
    
$boosters$shop['items'][$itemId]['shipId'];
    
$status true;

09/16/2020 18:14 KnightCreeper023#3
Now i have tried your code and it doesn't work to buy me a booster.


I'm sorry but I'm learning now in codes: D
09/16/2020 18:20 Rushle#4
Quote:
Originally Posted by KnightCreeper023 View Post
Now i have tried your code and it doesn't work to buy me a booster.


I'm sorry but I'm learning now in codes: D
Do you still get the same error? I've never tried to look into Darkorbit stuff private server stuff, so I have no clue on how your CMS or other stuff is coded

**PS** I just noticed i forgot to paste the ending of the try phrase. So i've updated the code
09/16/2020 18:22 KnightCreeper023#5
yeah i have infinityorbit files but everything there works like me but stupid boosters.

and now it doesn't even tell me I bought a booster.
09/16/2020 18:27 Rushle#6
Quote:
Originally Posted by KnightCreeper023 View Post
yeah i have infinityorbit files but everything there works like me but stupid boosters.

and now it doesn't even tell me I bought a booster.
Try the code again after I've remembered to include the ending of the try phrase

And please return here with the error you received when trying to buy
09/16/2020 21:04 KnightCreeper023#7
I tried it so I had it at the beginning but I didn't want to connect it to the server
09/17/2020 08:56 Rushle#8
Quote:
Originally Posted by KnightCreeper023 View Post
I tried it so I had it at the beginning but I didn't want to connect it to the server
Did you try the updated Code as i stated? There shouldbt be a difference in how it works just easier to read + removal of the duplicate

Ofc you have to replace your old code with it
09/17/2020 14:11 KnightCreeper023#9
yes i tried your code now but i buy booster.

But still have error in server console.
Code:
[17.09.2020 14:10:31] - Failed loading user ship / ShipInitializationHandler ERROR
Or I want to ask if this code you gave me would be done in such a way that it would automatically happen even without turning off the game
09/17/2020 14:26 Rushle#10
Quote:
Originally Posted by KnightCreeper023 View Post
yes i tried your code now but i buy booster.

But still have error in server console.
Code:
[17.09.2020 14:10:31] - Failed loading user ship / ShipInitializationHandler ERROR
Or I want to ask if this code you gave me would be done in such a way that it would automatically happen even without turning off the game
Where do you get that Error - on the site or in the emulator?
09/17/2020 14:30 KnightCreeper023#11
Emulator
09/17/2020 14:45 Rushle#12
Quote:
Originally Posted by KnightCreeper023 View Post
Emulator
Then you'll have to find the code that produces the error in the emulgator i would assume
09/17/2020 14:55 KnightCreeper023#13
i found file "boostermanager" but idk if that's it: /

I'll send you all the code here and check it out because I'm not sure if it's here

Code:
namespace Ow.Game.Objects.Players.Managers
{
    public class BoosterBase
    {
        public short Type { get; set; }
        public int Seconds { get; set; }

        public BoosterBase(short type, int seconds)
        {
            Type = type;
            Seconds = seconds;
        }
    }

    class BoosterManager : AbstractManager
    {
        public Dictionary<short, List<BoosterBase>> Boosters = new Dictionary<short, List<BoosterBase>>();

        public BoosterManager(Player player) : base(player) { }

        private DateTime boosterTime = new DateTime();
        public void Tick()
        {
            if (boosterTime.AddSeconds(5) < DateTime.Now)
            {
                for (short i = 0; i < Boosters.ToList().Count; i++)
                {
                    var boosters = Boosters.ToList()[i].Value;

                    for (short k = 0; k < boosters.Count; k++)
                    {
                        boosters[k].Seconds -= 5;

                        if (boosters[k].Seconds <= 0)
                            Remove((BoosterType)boosters[k].Type);
                    }
                }
                boosterTime = DateTime.Now;
            }
        }

        public void Add(BoosterType boosterType, int hours)
        {
            Player.SendPacket($"0|A|STM|booster_found|%BOOSTERNAME%|{boosterType.ToString()}|%HOURS%|{hours}");

            var seconds = (int)TimeSpan.FromHours(hours).TotalSeconds;
            short boostedAttributeType = GetBoosterType((short)boosterType);

            if (boostedAttributeType != 0)
            {
                if (!Boosters.ContainsKey((short)boostedAttributeType))
                    Boosters[boostedAttributeType] = new List<BoosterBase>();

                if (Boosters[boostedAttributeType].Where(x => x.Type == (short)boosterType).Count() <= 0)
                    Boosters[boostedAttributeType].Add(new BoosterBase((short)boosterType, seconds));
                else
                    Boosters[boostedAttributeType].Where(x => x.Type == (short)boosterType).FirstOrDefault().Seconds += seconds;

                Update();
                QueryManager.SavePlayer.Boosters(Player);
            }
        }

        public void Remove(BoosterType boosterType)
        {
            short boostedAttributeType = GetBoosterType((short)boosterType);

            if (boostedAttributeType != 0)
            {
                if (Boosters.ContainsKey(boostedAttributeType))
                    Boosters[boostedAttributeType].Remove(Boosters[boostedAttributeType].Where(x => x.Type == (short)boosterType).FirstOrDefault());

                if (Boosters[boostedAttributeType].Count == 0)
                    Boosters.Remove(boostedAttributeType);

                Update();
                QueryManager.SavePlayer.Boosters(Player);
            }
        }

        public void Update()
        {
            var boostedAttributes = new List<BoosterUpdateModule>();

            if (Boosters.ContainsKey((short)BoostedAttributeType.DAMAGE) && Boosters[(short)BoostedAttributeType.DAMAGE].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.DAMAGE), GetPercentage(BoostedAttributeType.DAMAGE), Boosters[(short)BoostedAttributeType.DAMAGE].Select(x => new BoosterTypeModule(x.Type)).ToList()));
            if (Boosters.ContainsKey((short)BoostedAttributeType.SHIELD) && Boosters[(short)BoostedAttributeType.SHIELD].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.SHIELD), GetPercentage(BoostedAttributeType.SHIELD), Boosters[(short)BoostedAttributeType.SHIELD].Select(x => new BoosterTypeModule(x.Type)).ToList()));
            if (Boosters.ContainsKey((short)BoostedAttributeType.MAXHP) && Boosters[(short)BoostedAttributeType.MAXHP].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.MAXHP), GetPercentage(BoostedAttributeType.MAXHP), Boosters[(short)BoostedAttributeType.MAXHP].Select(x => new BoosterTypeModule(x.Type)).ToList()));
            if (Boosters.ContainsKey((short)BoostedAttributeType.REPAIR) && Boosters[(short)BoostedAttributeType.REPAIR].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.REPAIR), GetPercentage(BoostedAttributeType.REPAIR), Boosters[(short)BoostedAttributeType.REPAIR].Select(x => new BoosterTypeModule(x.Type)).ToList()));
            if (Boosters.ContainsKey((short)BoostedAttributeType.HONOUR) && Boosters[(short)BoostedAttributeType.HONOUR].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.HONOUR), GetPercentage(BoostedAttributeType.HONOUR), Boosters[(short)BoostedAttributeType.HONOUR].Select(x => new BoosterTypeModule(x.Type)).ToList()));
            if (Boosters.ContainsKey((short)BoostedAttributeType.EP) && Boosters[(short)BoostedAttributeType.EP].Count >= 1)
                boostedAttributes.Add(new BoosterUpdateModule(new BoostedAttributeTypeModule(BoostedAttributeTypeModule.EP), GetPercentage(BoostedAttributeType.EP), Boosters[(short)BoostedAttributeType.EP].Select(x => new BoosterTypeModule(x.Type)).ToList()));

            Player.SendCommand(AttributeBoosterUpdateCommand.write(boostedAttributes));
            Player.SendCommand(AttributeHitpointUpdateCommand.write(Player.CurrentHitPoints, Player.MaxHitPoints, Player.CurrentNanoHull, Player.MaxNanoHull));
            Player.SendCommand(AttributeShieldUpdateCommand.write(Player.CurrentShieldPoints, Player.MaxShieldPoints));

            //TODO dont need every time
            Player.SettingsManager.SendMenuBarsCommand();
        }

        public int GetPercentage(BoostedAttributeType boostedAttributeType)
        {
            var percentage = 0;

            if (Boosters.ContainsKey((short)boostedAttributeType))
                foreach (var booster in Boosters[(short)boostedAttributeType])
                    percentage += GetBoosterPercentage(booster.Type);

            return percentage;
        }

        private short GetBoosterType(short boosterType)
        {
            short boostedAttributeType = 0;

            switch (boosterType)
            {
                case BoosterTypeModule.DMG_B01:
                case BoosterTypeModule.DMG_B02:
                    boostedAttributeType = (short)BoostedAttributeType.DAMAGE;
                    break;
                case BoosterTypeModule.SHD_B01:
                case BoosterTypeModule.SHD_B02:
                    boostedAttributeType = (short)BoostedAttributeType.SHIELD;
                    break;
                case BoosterTypeModule.HP_B01:
                case BoosterTypeModule.HP_B02:
                    boostedAttributeType = (short)BoostedAttributeType.MAXHP;
                    break;
                case BoosterTypeModule.REP_B01:
                case BoosterTypeModule.REP_B02:
                case BoosterTypeModule.REP_S01:
                    boostedAttributeType = (short)BoostedAttributeType.REPAIR;
                    break;
                case BoosterTypeModule.HON_B01:
                case BoosterTypeModule.HON_B02:
                case BoosterTypeModule.HON50:
                    boostedAttributeType = (short)BoostedAttributeType.HONOUR;
                    break;
                case BoosterTypeModule.EP_B01:
                case BoosterTypeModule.EP_B02:
                case BoosterTypeModule.EP50:
                    boostedAttributeType = (short)BoostedAttributeType.EP;
                    break;
            }

            return boostedAttributeType;
        }

        private int GetBoosterPercentage(short boosterTypeModule)
        {
            var percentage = 0;

            switch (boosterTypeModule)
            {
                case BoosterTypeModule.DMG_B01:
                case BoosterTypeModule.DMG_B02:
                case BoosterTypeModule.HP_B01:
                case BoosterTypeModule.HP_B02:
                case BoosterTypeModule.REP_B01:
                case BoosterTypeModule.REP_B02:
                case BoosterTypeModule.REP_S01:
                case BoosterTypeModule.HON_B01:
                case BoosterTypeModule.HON_B02:
                case BoosterTypeModule.EP_B01:
                case BoosterTypeModule.EP_B02:
                    percentage = 10;
                    break;
                case BoosterTypeModule.SHD_B01:
                case BoosterTypeModule.SHD_B02:
                    percentage = 25;
                    break;
                case BoosterTypeModule.HON50:
                case BoosterTypeModule.EP50:
                    percentage = 50;
                    break;
            }

            return percentage;
        }
    }
}
09/17/2020 15:04 borsbence#14
go to phpMyadmin -> server database -> Player_equipment -> boosters table
Copy this into PhpMyadmin---->{"2":[{"Type":1,"Seconds":3600}]}
the problem with parentheses is the emulator is not able to define the parentheses
09/17/2020 15:30 KnightCreeper023#15
This is working.but i buy booster in shop and i donīt go to spacemap.

friends, I found out that I had the endings set "" and you don't have to be there because the beginning must be {and I had "" so that's why it didn't work, but thank you for your help.

so I figured it out when I took it off so I can't get the page
:D :D

I have this code
Code:
		
        [
          'id' => 22,
	  'shipId' => '{"2":[{"Type":1,"Seconds":36000}]}',
	  'category' => 'boosters',
	  'description'=> '(10 HOURS PLAYING )',
          'name' => 'DMG 10%',
          'price' => 2500000,
          'priceType' => 'uridium',
          'amount' => false,
          'image' => 'do_img/global/items/booster_dmg-b02_100x100.png',
          'active' => true
        ]
and i have a question. How to remove from the player's mini map to 4-4?