Created
December 10, 2023 00:20
-
-
Save ultraviolet-jordan/556de9767088efaa24d42452b7c89c9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[proc,moveallinv](inv $src, inv $dest) | |
def_int $size = inv_size($src); | |
def_int $i = 0; | |
while ($i < $size) { | |
def_obj $obj = inv_getobj($src, $i); | |
if ($obj ! null) { | |
inv_moveitem($src, $dest, $obj, inv_total($src, $obj)); | |
} | |
$i = add($i, 1); | |
} | |
// ---- | |
[opplayer4,_] | |
if (.busy = true) { | |
mes("<.displayname> is busy at the moment."); | |
return; | |
} | |
// this message always sends, even if this player is responding to a trade request | |
mes("Sending trade offer..."); | |
%tradepartner = .uid; | |
if (.%tradepartner = uid) { | |
if_settext(trade:status, ""); | |
if_settext(trade:otherplayer, "Trading With: <.displayname>"); | |
inv_clear(tempinv); | |
inv_transmit(tempinv, trade:inv); | |
invother_transmit(.uid, tempinv, trade:otherinv); | |
inv_transmit(inv, trade_offer:inv); | |
.if_settext(trade:status, ""); | |
.if_settext(trade:otherplayer, "Trading With: <displayname>"); | |
.inv_clear(tempinv); | |
.inv_transmit(tempinv, trade:inv); | |
.invother_transmit(uid, tempinv, trade:otherinv); | |
.inv_transmit(inv, trade_offer:inv); | |
if_openmainmodalsideoverlay(trade, trade_offer); | |
.if_openmainmodalsideoverlay(trade, trade_offer); | |
%tradestatus = 0; | |
.%tradestatus = 0; | |
} else { | |
.mes("<displayname>:tradereq:"); | |
} | |
[if_button,trade:accept] | |
%tradestatus = 1; | |
if (.finduid(%tradepartner) = true) { | |
if (.%tradestatus = 1) { | |
inv_stoptransmit(trade:inv); | |
inv_stoptransmit(trade:otherinv); | |
inv_stoptransmit(trade_offer:inv); | |
.inv_stoptransmit(trade:inv); | |
.inv_stoptransmit(trade:otherinv); | |
.inv_stoptransmit(trade_offer:inv); | |
// check if contents of tempinv fits in other player's inv | |
def_int $size = inv_size(tempinv); | |
def_int $slot = 0; | |
while ($slot < $size) { | |
def_obj $obj = inv_getobj(tempinv, $slot); | |
def_int $num = inv_getnum(tempinv, $slot); | |
if ($obj ! null) { | |
if (.inv_itemspace(inv, $obj, $num, sub(inv_size(inv), $slot)) = false) { | |
mes("Other player doesn't have enough inventory space for this trade."); | |
.mes("You don't have enough inventory space for this trade."); | |
if_close; | |
.if_close; | |
return; | |
} | |
} | |
$slot = add($slot, 1); | |
} | |
// and in the reverse direction | |
$slot = 0; | |
while ($slot < $size) { | |
def_obj $obj = .inv_getobj(tempinv, $slot); | |
def_int $num = .inv_getnum(tempinv, $slot); | |
if ($obj ! null) { | |
if (inv_itemspace(inv, $obj, $num, sub(inv_size(inv), $slot)) = false) { | |
mes("You don't have enough inventory space for this trade."); | |
.mes("Other player doesn't have enough inventory space for this trade."); | |
if_close; | |
.if_close; | |
return; | |
} | |
} | |
$slot = add($slot, 1); | |
} | |
def_int $tempinvused = sub(inv_size(tempinv), inv_freespace(tempinv)); | |
if ($tempinvused < 1) { | |
if_settext(trade_confirm:inv_nothing, "Absolutely nothing!"); | |
.if_settext(trade_confirm:otherinv_nothing, "Absolutely nothing!"); | |
} else if ($tempinvused < 14) { | |
if_settext(trade_confirm:inv_nothing, ""); | |
.if_settext(trade_confirm:otherinv_nothing, ""); | |
inv_transmit(tempinv, trade_confirm:inv1); | |
.invother_transmit(uid, tempinv, trade_confirm:otherinv1); | |
} else { | |
if_settext(trade_confirm:inv_nothing, ""); | |
.if_settext(trade_confirm:otherinv_nothing, ""); | |
inv_transmit(tempinv, trade_confirm:inv2); | |
.invother_transmit(uid, tempinv, trade_confirm:otherinv2); | |
} | |
def_int $other_tempinvused = sub(inv_size(tempinv), .inv_freespace(tempinv)); | |
if ($other_tempinvused < 1) { | |
if_settext(trade_confirm:otherinv_nothing, "Absolutely nothing!"); | |
.if_settext(trade_confirm:inv_nothing, "Absolutely nothing!"); | |
} else if ($other_tempinvused < 14) { | |
if_settext(trade_confirm:otherinv_nothing, ""); | |
.if_settext(trade_confirm:inv_nothing, ""); | |
invother_transmit(.uid, tempinv, trade_confirm:otherinv1); | |
.inv_transmit(tempinv, trade_confirm:inv1); | |
} else { | |
if_settext(trade_confirm:otherinv_nothing, ""); | |
.if_settext(trade_confirm:inv_nothing, ""); | |
invother_transmit(.uid, tempinv, trade_confirm:otherinv2); | |
.inv_transmit(tempinv, trade_confirm:inv2); | |
} | |
if_openmainmodal(trade_confirm); | |
.if_openmainmodal(trade_confirm); | |
%tradestatus = 2; | |
.%tradestatus = 2; | |
} else { | |
if_settext(trade:status, "Waiting for other player"); | |
} | |
} | |
[if_close,trade] | |
inv_stoptransmit(trade:inv); | |
inv_stoptransmit(trade:otherinv); | |
inv_stoptransmit(trade_offer:inv); | |
~moveallinv(tempinv, inv); | |
if (.finduid(%tradepartner) = true) { | |
.%tradepartner = null; | |
.if_close; | |
} | |
%tradepartner = null; | |
[if_button,trade_confirm:accept] | |
%tradestatus = 3; | |
if (.finduid(%tradepartner) = true) { | |
if (.%tradestatus = 3) { | |
mes("Accepted trade."); | |
.mes("Accepted trade."); | |
both_moveinv(tempinv, inv); | |
.both_moveinv(tempinv, inv); | |
%tradepartner = null; | |
.%tradepartner = null; | |
if_close; | |
.if_close; | |
} | |
} | |
[if_close,trade_confirm] | |
inv_stoptransmit(trade_confirm:inv1); | |
inv_stoptransmit(trade_confirm:inv2); | |
inv_stoptransmit(trade_confirm:otherinv1); | |
inv_stoptransmit(trade_confirm:otherinv2); | |
if (%tradestatus ! 3) { | |
~moveallinv(tempinv, inv); | |
if (.finduid(%tradepartner) = true) { | |
.%tradepartner = null; | |
.if_close; | |
} | |
%tradepartner = null; | |
} | |
// ---- | |
[inv_button1,trade:inv] @removefromtrade(last_slot, 1); | |
[inv_button2,trade:inv] @removefromtrade(last_slot, 5); | |
[inv_button3,trade:inv] @removefromtrade(last_slot, 10); | |
[inv_button4,trade:inv] @removefromtrade(last_slot, ^max_32bit_int); | |
[inv_button5,trade:inv] @removefromtrade(last_slot, null); | |
[label,removefromtrade](int $slot, int $amount) | |
if ($amount <= 0) { | |
p_countdialog; | |
if (last_int <= 0) return; | |
$amount = last_int; | |
} | |
def_obj $obj = inv_getobj(tempinv, $slot); | |
def_int $total = inv_total(tempinv, $obj); | |
if ($amount < $total) $total = $amount; | |
inv_moveitem(tempinv, inv, $obj, $total); | |
%tradestatus = 0; | |
if_settext(trade:status, ""); | |
if (.finduid(%tradepartner) = true) { | |
.%tradestatus = 0; | |
.if_settext(trade:status, ""); | |
} | |
// ---- | |
[inv_button1,trade_offer:inv] @movetotrade(last_slot, 1); | |
[inv_button2,trade_offer:inv] @movetotrade(last_slot, 5); | |
[inv_button3,trade_offer:inv] @movetotrade(last_slot, 10); | |
[inv_button4,trade_offer:inv] @movetotrade(last_slot, ^max_32bit_int); | |
[inv_button5,trade_offer:inv] @movetotrade(last_slot, null); | |
[label,movetotrade](int $slot, int $amount) | |
if ($amount <= 0) { | |
p_countdialog; | |
if (last_int <= 0) return; | |
$amount = last_int; | |
} | |
def_obj $obj = inv_getobj(inv, $slot); | |
if (oc_tradeable($obj) = false) { | |
mes("You can't trade this item."); | |
return; | |
} | |
if (oc_members($obj) = true & map_members = false) { | |
mes("You can't trade this item."); | |
return; | |
} | |
def_int $total = inv_total(inv, $obj); | |
if ($amount < $total) $total = $amount; | |
inv_moveitem(inv, tempinv, $obj, $total); | |
%tradestatus = 0; | |
if_settext(trade:status, ""); | |
if (.finduid(%tradepartner) = true) { | |
.%tradestatus = 0; | |
.if_settext(trade:status, ""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment