Compression

Started by p0ki, September 10, 2015, 12:20:03 PM

p0ki

So I tried to make a dialog where you can trade 200 glepsite to 1 compressed glepsite.
But when I have 100 glepsite in my ship it works as well, I had to cramp up the checking amount to 400.
Now everything works as intended, but why is that?

<?php //php for the colors
using(npc);
include(
meta.js);
using(relations);
using(console);
using(ship);
using(generator);
using(game);
using(player);
using(storage);


function 
OnCheckRequirements()
{
var bp_npc_id topic.GetCurrentNpcShipId();

if (npc.GetTag(bp_npc_id"class") == "station.commander"//Every Station should do it.
{
return true;
}
return false;
}

function 
OnDialogue()
{
var input topic.GetInput();
    var 
state topic.GetState();

    var 
bp_npc_id topic.GetCurrentNpcShipId();

topic.AddTopic("generic_compress_glepsite");

if (state == 0)
{
if (input == NO_INPUT)
{
topic.AddPhrase($p001); // How much you want to compress?

topic.AddChoice(1$cyes1);
topic.AddChoice(2$cyes2);
topic.AddChoice(3$cyes3);
topic.AddChoice(4$cno);
topic.AddChoice(5$cwhat);
}
else if (input == 1)  // Compress 200
{
var hasCargo ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite"400);
if (!hasCargo)
{
topic.AddPhrase($pmor);
topic.AddPhrase($pbye);
}
else 
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite"200);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite1"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(1$cyes);
topic.AddChoice(4$cno);
}
}
else if (input == 2)  // Compress 2.000
{
var hasCargo ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite"4000);
var hasCargo1 ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite1"20);
if (!hasCargo)
{
if (!hasCargo1)
{
topic.AddPhrase($pmor);
topic.AddPhrase($pbye);
}
else
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite1"10);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite2"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(2$cyes);
topic.AddChoice(4$cno);
}
}
else 
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite"2000);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite2"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(2$cyes);
topic.AddChoice(4$cno);
}
}
else if (input == 3)  // Compress 10.000
{
var hasCargo ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite"20000);
var hasCargo1 ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite1"100);
var hasCargo2 ship.HasCargoAmount(PLAYER_SHIP"ore_glepsite2"10);
if (!hasCargo)
{
if (!hasCargo1)
{
if (!hasCargo2)
{
topic.AddPhrase($pmor);
topic.AddPhrase($pbye);
}
else
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite2"5);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite3"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(3$cyes);
topic.AddChoice(4$cno);
}
}
else
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite1"50);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite3"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(3$cyes);
topic.AddChoice(4$cno);
}
}
else 
{
topic.AddPhrase($p002); //Compressing...
ship.RemoveCargoByType(PLAYER_SHIP"ore_glepsite"10000);
ship.AddItemToStorage(PLAYER_SHIP"ore_glepsite3"1);
topic.AddPhrase($pdon);
topic.AddPhrase($paga);

topic.AddChoice(3$cyes);
topic.AddChoice(4$cno);
}
}
else if (input == 4)
{
topic.AddPhrase($pbye);
}
else if (input == 5)
{
topic.AddPhrase($pex1);
topic.AddPhrase($pex2);

topic.AddChoice(1$cyes1);
topic.AddChoice(2$cyes2);
topic.AddChoice(3$cyes3);
topic.AddChoice(4$cno);
}
}

}

ai_enabled

Hello!
You've found a bug in our code, it get twice amount of cargo in storage when check ship.HasCargoAmount().
Will be fixed with the next patch.
Regards!

p0ki

Thanks, I'll read the changelog carefully and adjust the mod once it's fixed :)