Drop Item Macro

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
User avatar
TyeJae
Cave Troll
Posts: 77
Joined: Thu Nov 05, 2009 2:19 pm

Drop Item Macro

Post by TyeJae »

I just thought I would share this if anyone wanted to see it... I made a macro that allows you to drop an item from your inventory to the map, and allow another player to pick it up.

It's helpful in my campaign so players can give another player a potion of healing, or sunrod, or any other item they please. I have other macros that consume such items, so my players run out of stuff alot.

Button:

Code: Select all

/emote [h: macroName = getMacroName()]

[if(macroName == "<b>Pick Item to Drop"),CODE:
{
	[macro("dropItem@Lib:4e"):""]
	[h:setMacroProps("<b>Pick Item to Drop", "label=<b>Drop "+LastDroppedItem+";")]
	finds the [r: LastDroppedItem] from his belongings and holds it in his hand.
	[h: qtyDroppedItem = json.get(Items, LastDroppedItem)-1]
	[if(qtyDroppedItem == 0),CODE:
	{
		[h:Items = json.remove(Items, LastDroppedItem)]
	};
	{
		[h: Items = json.set(Items, LastDroppedItem, qtyDroppedItem)]
	};]
};
{
	[macro("setDroppedLoot@Lib:4e"):""]
	[macro("moveItem@Lib:4e"):""]
	[h:setMacroProps("<b>Drop "+LastDroppedItem, "label=<b>Pick Item to Drop;")]
	drops the [r: LastDroppedItem] on the ground.
};]
dropItem (at Lib:4e):

Code: Select all

[h:imgList = json.fields(Items)]
[h:status=input(
    "Target|"+imgList+"|Select Target|LIST|SELECT=0"
)]
[h:abort(status)]

[h:tokenName=listGet(imgList,Target)]
[h:LastDroppedItem = tokenName]
[h: updates = "{
name:'[r: tokenName]'
}"
]
[h:copyToken("Item", 1, "Tokens", updates)]
moveItem (at Lib:4e), moves the item to your current position:

Code: Select all

[h: CurrentX = getTokenX(0)]
[h: CurrentY = getTokenY(0)]
[h: moveToken(CurrentX, CurrentY, 0, LastDroppedItem)]

lootTarget (at Lib:4e):

Code: Select all

<!--Get Basic Info and initialize variables-->
[h:debugmode = getLibProperty("DEBUGMODE")]
[h:me=getName()]
[h:calledByPC=isPC(me)]
[h:maxRange=1]
[h:pName = "Loot"]
[h:pTargets = 0]
[h:attType = json.get(currentPowerInfo, "attackType")]
[h,if(json.get(currentPowerInfo,"requirements")!="" && json.get(currentPowerInfo,"requirements")!="--none--"): pReqs = json.get(currentPowerInfo,"requirements"); pReqs=""]
[h,if(json.get(currentPowerInfo,"hitEffect")!="" && json.get(currentPowerInfo,"hitEffect")!="--none--"): phEff = json.get(currentPowerInfo,"hitEffect"); phEff=""]
[h,if(json.get(currentPowerInfo,"missEffect")!="" && json.get(currentPowerInfo,"missEffect")!="--none--"): pmEff = json.get(currentPowerInfo,"missEffect"); pmEff=""]
[h,if(json.get(currentPowerInfo,"alwaysEffect")!="" && json.get(currentPowerInfo,"alwaysEffect")!="--none--"): paEff = json.get(currentPowerInfo,"alwaysEffect"); paEff=""]
[h:caInfo = json.set("{}", "key", "0")]
[h:coverInfo = json.set("{}", "key", "0")]
[h:targList = ""]
[h:oath = 0]
[h:rangeFilter = json.set("{}", "from", if(attType=="area", 0, 1), "upto", maxRange, "distancePerCell", "false", "metric", "ONE_ONE_ONE")]
[h:reticle = me+"BurstCenter"]

<!--Determine which targeting dialog is needed-->
[h:targetDialog = 0]
[h:targetFilter = json.set("{}", "pc", if(calledByPC, 0, 1), "npc", if(calledByPC, 1, 0), "unsetStates", json.append("[]", "Alive", "Reticle"), "visible", 1, "range", rangeFilter)]

[h:exp = getTokenNames("json", targetFilter)]
[h:expList = listSort(json.toList(exp),"N+")]

<!--Powers that target yourself-->
[h,if(pTargets == "personal"):expList=me]

[h,if(expList == ""):assert(0, rangeError(), 0)]

<!--Create Image List of Targets-->
[H: imgList = expList]
[h:nameList = expList]
[H: Num = listCount(imgList)]
[h,COUNT(Num),CODE:
   {
     [h:targetName=listGet(imgList,roll.count)]
     [h,token(targetName): image=getTokenImage()]
     [h:imgList=listReplace(imgList,roll.count,targetName+" "+image)]
     [h:nameList=listReplace(nameList,roll.count,targetName)]
   }]
   
<!--Build the first line of the targeting dialog-->

[h:inputParams = json.append("[]", "basicStuff|Attack Basics||TAB|SELECT=1","junk|<html><b>Use Power: "+pName+"</b></html>||LABEL|SPAN=TRUE")]


<!--Switch through the targeting options to build the proper dialog contents for different target lists-->
[h:inputParams = json.append(inputParams, "targetNum|"+imgList+"|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30")]

[h:newInputParams = json.toList(inputParams, "##")]
[h:status=input(newInputParams)]
[h:abort(status)]

[h:targetName=listGet(nameList,targetNum)]
[h:switchToken(targetName)]
[h,if(CurrHP <= 0):targetDialog = 1; targetDialog = 0)]
[h:switchToken(me)]
[r,if(targetDialog),CODE:
{
	is looting [r:targetName] and finds...<br>
	[h:switchToken(targetName)]
	[if(AD != 0),code:{------>[r:AD]ad<br>[h:lootAD = AD]};{[h:lootAD = 0]};]
	[if(PP != 0),code:{------>[r:PP]pp<br>[h:lootPP = PP]};{[h:lootPP = 0]};]
	[if(GP != 0),code:{------>[r:GP]gp<br>[h:lootGP = GP]};{[h:lootGP = 0]};]
	[if(SP != 0),code:{------>[r:SP]sp<br>[h:lootSP = SP]};{[h:lootSP = 0]};]
	[if(CP != 0),code:{------>[r:CP]cp<br>[h:lootCP = CP]};{[h:lootCP = 0]};]
	[if(Items != ""),code:{------>[r:Items]<br>[h:lootItems = Items]};{[h:lootItems = 0]};]
	[h:noLoot = AD+PP+GP+SP+CP+Items]
	[if(noLoot == 0),code:{------><b>NOTHING!</b>};{};]
	[h:switchToken(me)]
	[h:AD = AD + lootAD]
	[h:PP = PP + lootPP]
	[h:GP = GP + lootGP]
	[h:SP = SP + lootSP]
	[h:CP = CP + lootCP]
	[FOREACH(loot, lootItems, ""),CODE:
	{
		[h:qtyItemLooted = json.get(Items, loot)]
		[h,if(loot != 0): Items = json.set(Items, loot, qtyItemLooted + 1),""]
	}]
	[h:removeToken(targetName)]
};
{
	[dialog("Dialog Test", "width=300; height=85; temporary=1; input=0; noframe=0"): {
	<html>
	<head>
	<title>Cannot Loot</table>
	</head>
	<body>
	<DIV ALIGN=CENTER>
	<b>Your target is still alive. Kill your target before you try to loot it!
	</b>
	</DIV>
	</body>
	</html>
	}]
};]
P.S. I'm not the greatest coder, so I'm sure a lot of this can be reduced. Plus I am terrible at notes.
My Creations:

Post Reply

Return to “Macros”