Page 194 of 396

Re: Ask a simple question, get a simple answer

Posted: Sun Feb 19, 2017 12:36 pm
by Badgert
Isaac!
Many thanks!
Everything happened as planned!

Re: Ask a simple question, get a simple answer

Posted: Sun Feb 19, 2017 4:00 pm
by zimberzimber
Liam.Ducray wrote:1. Isn´t it possible to create a character-level requirement for weapons in the LUA file? Like i.e. Character must be at least level 4 to hold a Sabre.
I tried the command "requiredLevel = X," as written on the official page, but it does not work.
This didn't work for me either.
You can prevent the player from using an item if certain requirements are not met in the 'onAttack' hook.

Code: Select all

onAttack = function(self,champion,slot)
	if champion:getLevel < 3 then
		champion:showAttackResult("Can't Use", "AccuracySymbol")
		return false
	end
end,
2. Isn´t it possible to give the parameters "knockback" and "pierce" to ranged weapons? As I tried, the editor spelled error messages upon testplay.
Only melee and firearm attacks have pierce.
There is no "knockback" parameter. Did you mean powerAttackTemplate = "knockback" ?
3. Isn´t it possible to give Ammunition a "damageType" like i.e. fire ? I created my own Flaming Crossbow Bolts, and of course they are supposed to deal fire damage.
But again, the editor gave me the "invalid component property"-error messages upon testplay.
You can use the 'onAttack' and 'onPostAttack' hooks to modify the item based on the ammunition item currently held by the champion.

onAttack to modify the item with extra stats for the attack, and increase the stack by one if current stack count is 1 so you can still access it from the onPostAttack

onPostAttack to revert the item back to its original state based on the ammo item, and then reduce the stack count of the ammo item by one.

Re: Ask a simple question, get a simple answer

Posted: Mon Feb 20, 2017 2:13 pm
by Liam.Ducray
Okay, I tried the onAttack command on a test object within the items.lua, but then I was unable to open my project. The editor says:
items.lua:96: function arguments expected near '<'
the full code is:

Code: Select all

defineObject{
	name = "sling",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/sling.fbx",
		},
		{
			class = "Item",
			uiName = "Sling",
			description = "A primitive sling to accelerate rocks",
			gfxIndex = 44,
			impactSound = "impact_blunt",
			weight = 0.5,
			traits = { "missile_weapon" },
		},
		{
			class = "RangedAttack",
			attackPower = 7,
			cooldown = 4,
			damageType = "physical",
			attackSound = "swipe",
			ammo = "rock",
    onAttack = function(self, champion, slot)
       if champion:getLevel < 2 then
          champion:showAttackResult("Can't Use", "AccuracySymbol")
          return false
       end
    end,
		},
	},
	tags = { "weapon", "weapon_missile" },
}
something´s missing?


Yes, I meant the powerAttackTemplate "knockback". I assume it works with melee only?

And point 3 I totally don´t understand :D No clue where to put the code and how to define the onAttack and onPostAttack commands correctly :?

Re: Ask a simple question, get a simple answer

Posted: Mon Feb 20, 2017 3:03 pm
by zimberzimber
You forgot the brackets after getLevel in this line:

Code: Select all

if champion:getLevel < 2 then
powerAttackTemplate gives the item a pre-defined secondary attack.
"knockback" is a melee attack that knocks monsters it hits back.
Take a look at this for some more info - https://www.youtube.com/watch?v=7L8Epms ... e=youtu.be

onAttack and onPostAttack are two functions that can be defined for every component that adds an attack to an item. (MeleeAttack, RangedAttack, ThrowAttack, FirearmAttack)
You defined them exactly like the way you defined the code that didn't work for you. (You were just missing brackets)
Here's an example:

Code: Select all

onAttack = function(self, champion, slot, chainIndex)
	if champion:getHealth() < champion:getMaxHealth() then
		hudPrint("User is wounded, cannot use this weapon")
		return false
	end
end,

onPostAttack = function(self, champion, slot)
	champion:damage(20,"pure")
end
onAttack happens before the attack executes, so with it you can cancel an attack or have it modify the item.
onPostAttack happens after the attack was made, so you can use it to revert changes done to the item, or apply certain effects.

Re: Ask a simple question, get a simple answer

Posted: Tue Feb 21, 2017 12:43 am
by Liam.Ducray
Thanks for the explanation. Most of it works for now.

Another quick question that came up: Isn´t the command "causeCondition" working on weapons? I tried the following:

Code: Select all

		{
			class = "FirearmAttack",
			name = "hellfire",
			uiName = "Hellfire",
			gameEffect = "Fires rapidly 4 concussive bullets filled with pure magma.",
			energyCost = 25,
			attackPower = 16,
			cooldown = 6,
			attackSound = "gun_shot_large",
			ammo = "pellet",
			knockback = true,
			repeatCount = 4,
			repeatDelay = 0.2,
			damageType = "fire",
			causeCondition = "burning",
			conditionChance = 40,
		},
but the result is an error message upon testplay.

Anyone knows how to bypass this?

cheers

Re: Ask a simple question, get a simple answer

Posted: Tue Feb 21, 2017 1:16 am
by zimberzimber
Here is the scripting reference - http://www.grimrock.net/modding/scripting-reference/
And another page containing some more up-to-date functions - https://github.com/JKos/log2doc/wiki/Class-list
If a component doesn't have something like setPierce but has setCauseCondition,then it can't accept accuracy but can accept caused conditions.
In your case, firearms can't accept causedCondition, because thats how the component works.

If you still want a firearm to cause a condition, you can have the onPostAttack function shoot an invisible high velocity projectile that on hit causes a condition, but it will get applied even if you miss.

Re: Ask a simple question, get a simple answer

Posted: Tue Feb 21, 2017 7:55 pm
by Zo Kath Ra
Liam.Ducray wrote:1. Isn´t it possible to create a character-level requirement for weapons in the LUA file? Like i.e. Character must be at least level 4 to hold a Sabre.
I tried the command "requiredLevel = X," as written on the official page, but it does not work.
Put a script entity called script_entity_1 in your dungeon.
Put this code in 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

		-- 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
		party.party:getChampionByOrdinal(champion):insertItem(slot, item_mouse)
	end
end
Put this code in mod_assets/scripts/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 replace
if (champion:getClass() ~= "fighter") then
with
if (champion:getLevel() < 4) then

Re: Ask a simple question, get a simple answer

Posted: Wed Feb 22, 2017 6:53 pm
by zimberzimber
I got two questions:

1) Is there a way to create a 'distortion' effect similar to this:
Image

2) How do I make projectiles travel in a horizontal (or any other 1-89 degree angle from one of the main directions) path?

Re: Ask a simple question, get a simple answer

Posted: Fri Feb 24, 2017 8:44 pm
by Zo Kath Ra
zimberzimber wrote: 2) How do I make projectiles travel in a horizontal (or any other 1-89 degree angle from one of the main directions) path?
Artifacts of Might
level: The Crypt
in the center, there's a room with a blob that moves the way you want
it's implemented with a timer that runs every frame and changes the blob's position
(the blob's velocity is 0)
if you wanted to do this with something that isn't a particle system, e.g. an arrow, you'd also have to change the arrow's rotation

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 01, 2017 10:50 am
by Badgert
Good afternoon!
Please tell me how to do:

1) Because the wall (daemon_head_1) flies spell (any) with an interval of every 5 seconds
2) Because the wall (daemon_head_1) flies spell (any) upon activation of the trigger