need help!

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
Slava
Posts: 5
Joined: Sun Aug 30, 2015 2:10 pm

need help!

Post by Slava »

Hello. This is my first post. My knowledge of English is poor, but I will try to explain the problem. My knowledge in the Lua script is bad, too.
I did a werewolf and I need party hook for custom trait remove with bearform remove. that is only switched off during the attack.

Code: Select all

defineRace{
	name = "shapeshifter",
	uiName = "Shapeshifter",
	inventoryBackground = "assets/textures/gui/inventory_backgrounds/human_$sex.tga",
}

defineTrait{
	name = "shapeshifter",
	uiName = "Shapeshifter",
	icon = 37,
	description = "Shapeshifter can transform into a bear, it consumes more food.",
	onRecomputeStats = function(champion, level)
		if level > 0 then
			champion:addStatModifier("strength", 1)
			champion:addStatModifier("vitality", 1)
			champion:addStatModifier("food_rate", 25)
		end
	end,
}

defineCharClass{
	name = "werebear",
	uiName = "Werebear",
	icon = 37,
	traits = { "werebear", "hand_caster" },
	skillPoints = 1,
	description = "This class for shapeshifters.",
}

defineTrait{
	name = "werebear",
	uiName = "Werebear",
	icon = 37,
	description = "...",
	gameEffect = [[
	- Health 40 (+6 per level), Energy 40 (+6 per level).]],
	onRecomputeStats = function(champion, level)
		if level > 0 then
			level = champion:getLevel()
			champion:addStatModifier("max_health", 40 + (level-1) * 6)
			champion:addStatModifier("max_energy", 40 + (level-1) * 6)
		end
	end,
}

defineTrait{
	name = "bear_strength",
	uiName = "Bear Strength",
	icon = 46,
	charGen = true,
	requiredRace = "shapeshifter",
	description = "Strength +2",
	onRecomputeStats = function(champion, level)
		if level > 0 then
			champion:addStatModifier("strength", 2)
		end
	end,
}

defineTrait{
	name = "bearskin",
	uiName = "Bearskin",
	icon = 91,
	charGen = true,
	requiredRace = "shapeshifter",
	description = "Immune cold, protection +10",
	onRecomputeStats = function(champion, level)
		if level > 0 then
			champion:addStatModifier("resist_cold", 100)
			champion:addStatModifier("protection", 10)
		end
	end,
}

defineSkill{
	name = "shapeshifting",
	uiName = "Shapeshifting",
	priority = 32,
	icon = 52,
	description = "Skill needs to turn into a bear.Max energy +15 per level. At 3 level energy regeneration rate +20. At 5 cooldown decreased by 10%.",
	onRecomputeStats = function(champion, level)
	local level = champion:getSkillLevel("shapeshifting")
		champion:addStatModifier("max_energy", level*15)
	end,
}

defineTrait{
	name = "natural_affinity",
	uiName = "Natural Affinity",
	icon = 80,
	description = "Your Energy regeneration rate is increased by 20% while resting.",
	onRecomputeStats = function(champion, level)
		if level > 0 then
			if party.party:isResting() then
				champion:addStatModifier("energy_regeneration_rate", 20)
			end
		end
	end,
}

defineTrait{
	name = "acceleration",
	uiName = "Acceleration",
	icon = 27,
	description = "The cooldown period for all actions you perform is decreased by 10%.",
	onComputeCooldown = function(champion, weapon, attack, attackType, level)
	local cooldown = champion:getLevel() / 10
		if level > 0 then return 1 - cooldown end
	end,
}

defineSpell{
   name = "bear_form",
   uiName = "Bear Form",
   skill = "life_magic",
   requirements = {"shapeshifting", 1},
   gesture = 321456987,
   manaCost = 0,
   icon = 72,
   spellIcon = 13,
   description = "Turn into a bear.",
	onCast = function(champion, x, y, direction, elevation, skillLevel, level)
		local energy = champion:getEnergy()
		if champion:hasTrait("shapeshifter") and champion:hasTrait("werebear") and champion:getSkillLevel("shapeshifting") == 1 then
			playSound("polymorph_bear")
			for i = 1,1 do
			champion:addTrait("bear_power")
			champion:setCondition("bear_form", 1)
			champion:setEnergy(1)
			champion:regainEnergy(energy-1)
		end
		else
		end
		if champion:hasTrait("shapeshifter") and champion:hasTrait("werebear") and champion:getSkillLevel("shapeshifting") == 2 then
			playSound("polymorph_bear")
			for i = 1,1 do
			champion:removeTrait("bear_power")
			champion:addTrait("bear_power2")
			champion:setCondition("bear_form", 1)
			champion:setEnergy(1)
			champion:regainEnergy(energy-1)
		end
		else
		end
		if champion:hasTrait("shapeshifter") and champion:hasTrait("werebear") and champion:getSkillLevel("shapeshifting") == 3 then
			playSound("polymorph_bear")
			for i = 1,1 do
			champion:removeTrait("bear_power")
			champion:removeTrait("bear_power2")
			champion:addTrait("bear_power3")
			champion:setCondition("bear_form", 1)
			champion:setEnergy(1)
			champion:regainEnergy(energy-1)
		end
		else
		end
		if champion:hasTrait("shapeshifter") and champion:hasTrait("werebear") and champion:getSkillLevel("shapeshifting") == 4 then
			playSound("polymorph_bear")
			for i = 1,1 do
			champion:removeTrait("bear_power")
			champion:removeTrait("bear_power2")
			champion:removeTrait("bear_power3")
			champion:addTrait("bear_power4")
			champion:setCondition("bear_form", 1)
			champion:setEnergy(1)
			champion:regainEnergy(energy-1)
		end
		else
		end
		if champion:hasTrait("shapeshifter") and champion:hasTrait("werebear") and champion:getSkillLevel("shapeshifting") == 5 then
			playSound("polymorph_bear")
			for i = 1,1 do
			champion:removeTrait("bear_power")
			champion:removeTrait("bear_power2")
			champion:removeTrait("bear_power3")
			champion:removeTrait("bear_power4")
			champion:addTrait("bear_power5")
			champion:setCondition("bear_form", 1)
			champion:setEnergy(1)
			champion:regainEnergy(energy-1)
		end
		else
			hudPrint("You are not shapeshifter and not werebear")
			playSound("spell_fizzle")
		end
  end,
}

defineTrait{
	name = "bear_power",
	uiName = "Bear Power",
	icon = 46,
	charGen = false,
	hidden = false,
	gameEffect = "Your bearform power is increased per character level.",	
	description = "If you're not a bear, then your next attack will you the norm.",
	onRecomputeStats = function(champion, level)
		if level > 0  then
			level = champion:getLevel()
			champion:addStatModifier("strength", - 50)
			champion:addStatModifier("strength", level * 12)
			champion:addStatModifier("max_load", 150)
		end
	end,
}

defineTrait{
	name = "bear_power2",
	uiName = "Bear Power",
	icon = 46,
	charGen = false,
	hidden = false,
	gameEffect = "Your bearform power is increased per character level.",	
	description = "If you're not a bear, then your next attack will you the norm.",
	onRecomputeStats = function(champion, level)
		if level > 0  then
			level = champion:getLevel()
			champion:addStatModifier("strength", - 50)
			champion:addStatModifier("strength", level * 12)
			champion:addStatModifier("max_load", 150)
		end
	end,
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and attackType == "melee" then return champion:getLevel() end
	end,
}

defineTrait{
	name = "bear_power3",
	uiName = "Bear Power",
	icon = 46,
	charGen = false,
	hidden = false,
	gameEffect = "Your bearform power is increased per character level.",	
	description = "If you're not a bear, then your next attack will you the norm.",
	onRecomputeStats = function(champion, level)
		if level > 0  then
			level = champion:getLevel()
			champion:addStatModifier("strength", - 50)
			champion:addStatModifier("strength", level * 12)
			champion:addStatModifier("max_load", 150)
		end
	end,
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and attackType == "melee" then return champion:getLevel() end
	end,
	onComputeCritChance = function(champion, weapon, attack, attackType, level)
		if level > 0 and (attackType == "melee") then return champion:getLevel() end
	end,
}

defineTrait{
	name = "bear_power4",
	uiName = "Bear Power",
	icon = 46,
	charGen = false,
	hidden = false,
	gameEffect = "Your bearform power is increased per character level.",	
	description = "If you're not a bear, then your next attack will you the norm.",
	onRecomputeStats = function(champion, level)
		if level > 0  then
			level = champion:getLevel()
			champion:addStatModifier("strength", - 50)
			champion:addStatModifier("strength", level * 12)
			champion:addStatModifier("max_load", 150)
		end
	end,
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and attackType == "melee" then return champion:getLevel() end
	end,
	onComputeCritChance = function(champion, weapon, attack, attackType, level)
		if level > 0 and (attackType == "melee") then return champion:getLevel() end
	end,
	onComputeCooldown = function(champion, weapon, attack, attackType, level)
	local cooldown = champion:getLevel() / 10
		if level > 0 then return 1 - cooldown end
	end,
}

defineTrait{
	name = "bear_power5",
	uiName = "Bear Power",
	icon = 46,
	charGen = false,
	hidden = false,
	gameEffect = "Your bearform power is increased per character level.",	
	description = "If you're not a bear, then your next attack will you the norm.",
	onRecomputeStats = function(champion, level)
		if level > 0  then
			level = champion:getLevel()
			champion:addStatModifier("strength", - 50)
			champion:addStatModifier("strength", level * 12)
			champion:addStatModifier("max_load", 150)
			champion:addStatModifier("protection", level)
		end
	end,
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and attackType == "melee" then return champion:getLevel() end
	end,
	onComputeCritChance = function(champion, weapon, attack, attackType, level)
		if level > 0 and (attackType == "melee") then return champion:getLevel() end
	end,
	onComputeCooldown = function(champion, weapon, attack, attackType, level)
	local cooldown = champion:getLevel() / 10
		if level > 0 then return 1 - cooldown end
	end,
}

defineObject{
   name = "book_shapeshifter",
   baseObject = "scroll_light",
   components = {
		{
			class = "Model",
			model = "mod_assets/runebooks/models/journal.fbx",
		},
      {
         class = "Item",
         uiName = "Book Of Shapesifting",
         
         gfxAtlas = "mod_assets/runebooks/books_icons.tga",
         gfxIndex = 0,
         weight = 0.5,
      },
      {
         class = "SpellScrollItem",
         spell = "bear_form",
      }
   },
   tags = { "My_scroll" },
}

--debug item
defineObject{
	name = "tome_debug",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/tome.fbx",
		},
		{
			class = "Item",
			uiName = "debug",
			description = "debug.",
			gfxIndex = 30,
			weight = 1.0,
			traits = { "tome" },
		},
		{
			class = "UsableItem",
			sound = "level_up",
			onUseItem = function(self, champion)
				hudPrint(champion:getName().." you now shapeshifter.")
				champion:addTrait("shapeshifter")
				return true
			end,
		},
	},
	tags = { "My_scroll" },
}

defineObject{
	name = "tome_debug2",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/tome.fbx",
		},
		{
			class = "Item",
			uiName = "debug2",
			description = "debug2.",
			gfxIndex = 30,
			weight = 1.0,
			traits = { "tome" },
		},
		{
			class = "UsableItem",
			sound = "level_up",
			onUseItem = function(self, champion)
				hudPrint(champion:getName().." you now werebear.")
				champion:addTrait("werebear")
				return true
			end,
		},
	},
	tags = { "My_scroll" },
}

--remove potion bearform
defineRecipe{
	potion = "water_flask",
	level = 4,
	ingredients = 34,
}

defineSound{
	name = "damage_shapeshifter_male",
	filename = "assets/samples/characters/damage_male_01.wav",
	loop = true,
	volume = 0.1,
	minDistance = 1,
	maxDistance = 10,
}

defineSound{
	name = "damage_shapeshifter_female",
	filename = "assets/samples/characters/damage_female_01.wav",
	loop = true,
	volume = 0.1,
	minDistance = 1,
	maxDistance = 10,
}

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
   components = {
      {
         class = "Party",  
		onAttack = function(self, champion, action, slot)
		local setFalse = false
		-- Auto Check For Item Specific Triggers below	
			for i = 1, 10 do
				local checkItem = champion:getItem(i)
				if checkItem ~= nil then
					if checkItem.go:getComponent("triggerOnAttack") then
					checkItem.go.triggerOnAttack.performAction(self, champion, action, slot)
					end
				end
			end
		-- General Triggers Below (Skill/Trait triggers, etc)	
				if champion:hasTrait("bear_power") and not champion:hasCondition("bear_form") then champion:removeTrait("bear_power")
				end
				if champion:hasTrait("bear_power2") and not champion:hasCondition("bear_form") then champion:removeTrait("bear_power2")
				end
				if champion:hasTrait("bear_power3") and not champion:hasCondition("bear_form") then champion:removeTrait("bear_power3")
				end
				if champion:hasTrait("bear_power4") and not champion:hasCondition("bear_form") then champion:removeTrait("bear_power4")
				end
				if champion:hasTrait("bear_power5") and not champion:hasCondition("bear_form") then champion:removeTrait("bear_power5")
				end
				setFalse = true
			end,
		},
   },
}
Post Reply