Items working together.

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Items working together.

Post by Emera Nova »

I'm working on some special bracelets that are needed to be used with certain items to work. The types I'm attempting to get to work are listed below.

A bracelet to check to see if you have a bow equiped if you do then make it so when u attack with the bow it has a chance to decrease the enemies defense.

A bracelet that will check to see if you have a shield on if you do it'll make it so the shield will give you a (x)% decrease in damage taken.

A bracelet that if you use a magic spell to attack something it will give it an (x)% to get the burning status effect.

And maybe a bracelet that when worn will increase health given back by healing potions, or other items that I make that can heal.

Any help on creating these items will be appreciated
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Items working together.

Post by Emera Nova »

:o Does anyone know of a way to make an item class restricted? I'd like to make each of those bracelets only work with repected classes. Like the condition burning one only work with the wizard, and the shield one only work with the fighter.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Items working together.

Post by Emera Nova »

I saw part of a script minmay had put together for LOG1 that has to do with checking on an item to see if its equiped and if it is reduce damage of incoming attacks. Trying to figure out how to make that script play nice with LOG2 since some stuff has changed..

The original script is

Code: Select all

recursing = false
onDamage = function(champion,dmg,type)
               if recursing then recursing = false return true end
               if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
                  if type == "physical" then
                     recursing = true
                     champion:damage(dmg*.75,type)
                     return false
                  end
               end
            end
And my hashed version that I'm working on is this

Code: Select all

function tankring()
local c = party.party:getChampion(1)
   if c:getItem(10) and c:getItem(10).name == "rs_ring_tank_t1_1" then
      if onDamage == "physical" then
         c:damage(math.ceil(dmg*.5),type)
         return false
      end
   end
   return true
end
Log 2 didn't seem to understand what champion was so I went and replaced it with the party.party:getChampion(1) and then set that to a local value (least thats what I think I did xD). Anyone have any ideas on where to move on from here? The recursing thing didnt seem to do anything that I noticed so I just removed it. As you can see I'm totes a programing god here x]...



I've also attempted to make the burn enemies ring but that hasn't gone anywhere of much. I got a healing ring of some sorts going, it only has increased recovery. Still trying to figure out how to make it make healing potions heal more while the ring is on.
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Items working together.

Post by Zo Kath Ra »

Emera Nova wrote::o Does anyone know of a way to make an item class restricted? I'd like to make each of those bracelets only work with repected classes. Like the condition burning one only work with the wizard, and the shield one only work with the fighter.
What kind of restriction do you want?
a) the item can only be equipped by one class
b) the item can be equipped by any class, but the PC only gets the bonus(es) if he has the right class
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Items working together.

Post by Emera Nova »

Id Like to have it so you have to be a certain class to equip it.
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Items working together.

Post by Zo Kath Ra »

Emera Nova wrote:Id Like to have it so you have to be a certain class to equip it.
Put his code in your mod's "items.lua":

Code: Select all

defineObject{
    name = "fighters_long_sword",
    baseObject = "base_item",
    components = {
        {
            class = "Model",
            model = "assets/models/items/long_sword.fbx",
        },
        {
            class = "Item",
            uiName = "Fighter's Longsword",
            gfxIndex = 84,
            gfxIndexPowerAttack = 430,
            impactSound = "impact_blade",
            weight = 3.2,
            description = "This longsword is only for fighters.",
            traits = { "light_weapon", "sword" },
            
            onEquipItem = function(self, champion, slot)
                if (slot == ItemSlot.Weapon) or (slot == ItemSlot.OffHand) then
                    if (champion:getClass() ~= "fighter") then
                        hudPrint("This longsword can only be equipped by fighters!")
                        delayedCall("script_entity_1", 0, "removeItem", champion:getOrdinal(), slot)
                    end
                end
            end
        },
        {
            class = "MeleeAttack",
            attackPower = 16,
            accuracy = 0,
            cooldown = 3.7,
            swipe = "horizontal",
            requirements = { "light_weapons", 1 },
            powerAttackTemplate = "thrust",
        },
    },
    tags = { "weapon" },
}
And this code in a script entity called "script_entity_1":

Code: Select all

function removeItem(champion, slot)
	local item_slot = party.party:getChampionByOrdinal(champion):getItem(slot)
	local item_mouse = getMouseItem()
	
	if (item_mouse == nil) then
		-- there was no item in the slot when we equipped the sword
		-- item_slot = sword
		setMouseItem(item_slot)
		party.party:getChampionByOrdinal(champion):removeItemFromSlot(slot)
	else
		-- there already was an item in the slot
		-- item_slot = sword
		-- item_mouse = old item
		
		-- spawn an altar and put the old item on it
		local altar = spawn("altar", party.level, party.x, party.y, party.facing, party.elevation)
		altar.surface:addItem(item_mouse)
		setMouseItem(nil)
		
		-- put the sword in the mouse cursor
		setMouseItem(item_slot)
		party.party:getChampionByOrdinal(champion):removeItemFromSlot(slot)
		
		-- put the old item back in the champion's inventory and destroy the altar
		party.party:getChampionByOrdinal(champion):insertItem(slot, item_mouse)
		altar:destroy()
	end
end
I've done a little testing and it seems to work w/o crashing, but please go ahead and test it some more.
Post Reply