Forums » Bugs
API bug in unloadsellcargo function
Description page:
http://www.vo-wiki.com/racecar/index.php?title=API_UnloadSellCargo
This function sometimes removes your cargo and takes money from your account instead of adding money to the account. I caught it in the act during some recent plugin work.
I assume since it is removing the cargo that it received good data on the itemid amd quantity.
Why it is removing money from the account I dont know - It should never do that in any circumstance.
Here is the relevent code I was using:
-- sell the current cargo unless -1 error preset
if (ST.LastSector) and (ST.LastSector ~= -1) then
FM.Print("Selling cargo")
local Cargo = {}
for _,StockNumber in ipairs(GetShipInventory(GetActiveShipID()).cargo) do
local Amount = GetInventoryItemQuantity(StockNumber)
local ItemName = GetInventoryItemName(StockNumber)
table.insert(Cargo, {itemid=StockNumber, quantity=Amount})
end
UnloadSellCargo(Cargo,nil)
I also recently found a similar problem in the purchase function in that if theres error it takes your money but does not deliver the cargo. (Partially my fault)
http://www.vo-wiki.com/racecar/index.php?title=API_UnloadSellCargo
This function sometimes removes your cargo and takes money from your account instead of adding money to the account. I caught it in the act during some recent plugin work.
I assume since it is removing the cargo that it received good data on the itemid amd quantity.
Why it is removing money from the account I dont know - It should never do that in any circumstance.
Here is the relevent code I was using:
-- sell the current cargo unless -1 error preset
if (ST.LastSector) and (ST.LastSector ~= -1) then
FM.Print("Selling cargo")
local Cargo = {}
for _,StockNumber in ipairs(GetShipInventory(GetActiveShipID()).cargo) do
local Amount = GetInventoryItemQuantity(StockNumber)
local ItemName = GetInventoryItemName(StockNumber)
table.insert(Cargo, {itemid=StockNumber, quantity=Amount})
end
UnloadSellCargo(Cargo,nil)
I also recently found a similar problem in the purchase function in that if theres error it takes your money but does not deliver the cargo. (Partially my fault)
I rewrote the function today and I am finally certain I am feeding the right information to both functions however UnLoadSell and PurchaseMerchandiseItem frequently seem to handle the credits backwards. UnloadSell deducts credits while PurchaseMerchandise credits you with the amount.
If you need a copy of the plug in let me know and I can forward you a copy.
If you need a copy of the plug in let me know and I can forward you a copy.
Thanks for the report.
Mom et al,
This bug is caused by the speed differance between my local plug in and the time it takes to query the server and get a response. Put another way I was purchasing new cargo before the old cargo was finished being sold and it got confused as to which was which. If it wasnt for the random nature of the bug It could be used as an exploit...
(Seemingly random events are rarely random but I didnt feel like figuring out the pattern)
I solved the problem on my end by forcing a delay until the last action was finished but you may want to prevent functions which involve calls to the server from returning until the server responds.
This bug is caused by the speed differance between my local plug in and the time it takes to query the server and get a response. Put another way I was purchasing new cargo before the old cargo was finished being sold and it got confused as to which was which. If it wasnt for the random nature of the bug It could be used as an exploit...
(Seemingly random events are rarely random but I didnt feel like figuring out the pattern)
I solved the problem on my end by forcing a delay until the last action was finished but you may want to prevent functions which involve calls to the server from returning until the server responds.
No, because that can hang the client. I think that those functions trigger the TRANSACTION events, or something else. So register something to watch for transactions and you should be safe. I think this is how Ray does it with the default UI.
No Dragath - I was using the transaction events before but I had to change it to a timer delay loop untill isTransactionPending clears and then create a flag based dispatcher to handle the waiting list....
The problem I think with using the transaction event directly is that each inventory item creates a new transaction so it gets called multiple times and well before everything is finished...
And yes I tried using the transaction event and checking if istransactionpending was clear but frequently the transaction would complete before I exitted so I wasnt being called again due to race conditions....
In any case I fixed it on my end and its up to Guild if they want to fix thier end - Im sure they can figure out a way to fix it without causing client lock ups... Their good... really.
The problem I think with using the transaction event directly is that each inventory item creates a new transaction so it gets called multiple times and well before everything is finished...
And yes I tried using the transaction event and checking if istransactionpending was clear but frequently the transaction would complete before I exitted so I wasnt being called again due to race conditions....
In any case I fixed it on my end and its up to Guild if they want to fix thier end - Im sure they can figure out a way to fix it without causing client lock ups... Their good... really.