Page 2 of 4

Re: Game Effects - LifeLeech weapons sorted....

Posted: Tue Mar 05, 2013 6:49 pm
by Vice Dellos
weapon.name... sometimes the solution is so obvious XD all I needed was ".name"to get it to work XD

(I was trying to have a sword give extra exp when you used it to attack)

tnx XD

Re: Game Effects - LifeLeech weapons sorted....

Posted: Wed Mar 06, 2013 12:18 am
by akroma222
Hehe thanks Komag! A little late but better than never.. ;)

Vice Dellos - this is how I have set up my init.lua (as per Lord Garths instructions):
SpoilerShow
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion, weapon)
if (weapon ~= nil) and (weapon.name == "ice_sabre") then
if party.facing == 0 then
spawn("frostburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("frostburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("frostburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("frostburst", party.level, party.x-1, party.y, party.facing)
end
end
if (weapon ~= nil) and (weapon.name == "vorpal_blade") then
if party.facing == 0 then
spawn("poison_cloud", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("poison_cloud", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("poison_cloud", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("poison_cloud", party.level, party.x-1, party.y, party.facing)
end
end
if (weapon ~= nil) and (weapon.name == "shock_maul") then
if party.facing == 0 then
spawn("shockburst", party.level, party.x, party.y-1, party.facing)
end
if party.facing == 1 then
spawn("shockburst", party.level, party.x+1, party.y, party.facing)
end
if party.facing == 2 then
spawn("shockburst", party.level, party.x, party.y+1, party.facing)
end
if party.facing == 3 then
spawn("shockburst", party.level, party.x-1, party.y, party.facing)
end
end
if (weapon ~= nil) and (weapon.name == "destiny_blade") then
return vampricScript.vampricPartyAttack(champion, weapon)
end
end

}
The first 3 weapons spawn burst attacks when you swing them... for extra EXP gaining weapons...
give me a minute or 3...
EDIT - hmmmm, so I am using the onDie Hook from monsters.lua that considers a table of all monsters... the hook calls a function in a script in the dungeon, but I am having some issues with it freezing up... I'm sure this is simpler than I am making it lol..

Re: Game Effects - LifeLeech weapons sorted....

Posted: Tue Mar 12, 2013 11:49 am
by akroma222
Hey folks,
Leech health axe and drain energy sword scripts have been updated - so they dont do their thing when there is no monster being hit

Vice - just to clarify, you are after a weapon that gains the wielder more EXP when the monster is killed?
...OR... a weapon that gains you a bit of EXP whenever it hits a monster??

Re: Special / Magic Weapon Scripts Thread

Posted: Tue Mar 12, 2013 12:31 pm
by akroma222
This point marks the end of "Game effect - life leech" and the transition to "Special/Magic Weapon Scripts Thread"

Re: Special / Magic Weapon Scripts Thread

Posted: Tue Mar 12, 2013 8:35 pm
by Drakkan
already noted in my topic regarding trait bonus - this is more game desigh flaw then yours, but in case character does not have enough skill to use that weapon (for example axes:10), but that weapon is equiped, bonus from script still counts.
Also not tested case if character already have agresive trait, will he get "double" aggresive or just nothing will happens ?
EDIT: if you will have some time please could you also modify the script that if weapon is removed, that champion nameĀ“s will appear in the hud ?
something like this -
local name1 = party:getChampion(1):getName()
hudPrint(""..name1..": Hey, what are you doing, thats my weapon !")

Re: Special / Magic Weapon Scripts Thread

Posted: Wed Mar 13, 2013 7:23 am
by akroma222
OK, so I got that all working - skill requirement for the effects to take place on Equip and on Unequip, also changed hudPrint.
This is the script for the entity in dungeon
SpoilerShow

Code: Select all

-------------Drakkan Minotaur Mace-------------------------

function drakkanMaceEquip(champion, slot)
	local champ = champion:getOrdinal()
	local skill = champion:getSkillLevel("maces")
	local name1 = champion:getName()
	if champion:getRace() == "Minotaur" then
		if slot == 7 or slot == 8 then
			if skill >= 5 then
				champion:modifyStatCapacity("strength", 5)
    			champion:modifyStat("strength", 5)
				champion:addTrait("tough")
				hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
			end
		end
	end
end

function drakkanMaceUnequip(champion, slot)
	local champ = champion:getOrdinal()
	local skill = champion:getSkillLevel("maces")
	local name1 = champion:getName()
	if champion:getRace() == "Minotaur" then
		if slot == 7 or slot == 8 then
			if skill >= 5 then
				champion:modifyStatCapacity("strength", -5)
    			champion:modifyStat("strength", -5)
				champion:removeTrait("tough")
				hudPrint(""..name1..": Hey, what are you doing? That's my weapon!")
			end
		end
	end
end
However!!! the problem remains... if your guy has the mace in hand, you then bump up your skill in maces to trigger the effects, and then you remove the mace...
Your guy has his strength decremented and if he/she already has the trait (tough or whatever) they will lose the trait.
Need to find a way to stop this. I have tried but to no avail... will keep looking into it... (help welcome hehehe)

EDIT - And a further issue... if your guy already has the trait (say tough)... and has the skill requirements for the effects, you then remove the mace.... they will lose the trait they had before equipping the mace!! :( This is problematic... but I am sure there is a solution, maybe along the lines of creating a table at the beginning of the game that records initial traits and stats... or with the onEquip function, and then comparing that table to another table with the onUnequip function?? This has highlighted a problem with some of my buffing spell scripts as some of them add and remove traits the same way :oops:
At the moment I do not know how to script all this up... so I may just change the original post back to something that works reliably although not exactly what you were after..

Does anyone know of a scripting solution to any of these tricky things??

Just an idea though - perhaps it does not matter about the skill requirment? Perhaps the weapon's bonus is more to do with race (minotaur) than a skill? Even if the champ does receive the bonus and can not attack with the weapon, I do not think people will choose to abuse this... imho the second slot should be for a second weapon, shield, wand or throwing weapon.... not a weapon that grants a small bonus that you can not attack with?? Hmmm, personal preference here... but it would be good to find a solution nonetheless :)

Re: Special / Magic Weapon Scripts Thread

Posted: Thu Mar 14, 2013 2:38 am
by Marble Mouth
Hi akroma222. Here's one idea that solves a couple of your issues:

Code: Select all

function drakkanMaceEquip(champion, slot)
   local skill = champion:getSkillLevel("maces")
   local name1 = champion:getName()
   if slot == 7 or slot == 8 then
      if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
         champion:modifyStatCapacity("strength", 5)
         champion:modifyStat("strength", 5)
         champion:addTrait("tough")
         hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
      else
		champion:removeItem(slot)
		spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
		playSound("item_drop")
	  end
   end
end
This way, if anyone who isn't a Minotaur with 5 or more skill in maces tries to equip it, they simply can't equip it. No bonuses for holding a mace that you can't actually wield. No penalty for unequipping a mace that never gave you a bonus in the first place. I tried to get a little more fancy and set the mace back as the mouse item, but encountered annoying timing issues. When I used setMouseItem() within the onEquip code, the item never appeared. When I tried setting a very short delay before I spawned a new mace as the mouse item, there was the lingering question of what to do with the old mouse item. The player might have had the mace as the mouse item and clicked on an equipment slot that already contained an item, thus switching those items. If I just spawn a new copy of the old mouse item, it will have a different id, so that might mess up other things in the mod. Note that the code above will also create a new mace with a different id. It would be nice if "return false" worked for onEqiup, but it seems that it does not. Has anyone successfully dealt with this problem before?

As for losing traits. I do think any good solution will involve one or more tables. Here's what I came up with first:

Code: Select all

traitsGained = {}
--Keys are item id's. Values are tables of traits gained.

function drakkanMaceEquip(champion, slot)
   local skill = champion:getSkillLevel("maces")
   local name1 = champion:getName()
   if slot == 7 or slot == 8 then
      if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
         champion:modifyStatCapacity("strength", 5)
         champion:modifyStat("strength", 5)
         if not champion:hasTrait("tough") then
			champion:addTrait("tough")
			local itemId = champion:getItem(slot).id
			traitsGained[itemId] = { "tough", }
		end
         hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
      else
		champion:removeItem(slot)
		spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
		playSound("item_drop")
	  end
   end
end

function drakkanMaceUnequip(champion, slot)
	local skill = champion:getSkillLevel("maces")
   local name1 = champion:getName()
   if ( slot == 7 or slot == 8 ) and
	    ( champion:getRace() == "Minotaur" and skill >= 5 ) then
        champion:modifyStatCapacity("strength", -5)
        champion:modifyStat("strength", -5)
		local itemId = champion:getItem(slot).id
        local traitsToRemove = traitsGained[itemId]
		traitsGained[itemId] = nil
		if traitsToRemove then
			for _ , trait in ipairs( traitsToRemove ) do
				champion:removeTrait( trait )
			end
		end
        hudPrint(""..name1..": Hey, what are you doing? That's my weapon!")
    end
end
traitsGained is a table. The keys in this table are item id's. The value associated with each key is a table containing the traits that were gained the last time that item was equipped. By making the value a table instead of just a single string, we retain the option to create weapons that grant multiple traits. This scheme tracks which item gave which trait to which champion, but it still may not be ideal.

For example, if a champion equips two items that each should give "tough" then this scheme will track which item was equipped first and thus actually gave the bonus. If that champion then unequips that first item while keeping the second item equipped, they will lose "tough", which may not be the desired functionality. So now I like your first idea more, track which traits each champion had at the beginning:

Code: Select all

allTraits = { "aggressive" , "agile" , "athletic" , "aura" ,
 "cold_resistant" , "evasive" , "fire_resistant" ,
 "fist_fighter" , "head_hunter" , "healthy" , 
 "lightning_speed" , "natural_armor" , "poison_resistant" ,
 "skilled" , "strong_mind" , "tough" }

traitCounts = {}
--Keys are ordinals. Values are tables where:
	--Keys are trait names. Values are the count of how many
	--times that trait has been applied to that champion.
	
for i = 1,4 do
	local champion = party:getChampion(i)
	local currentTraits = {}
	for _ , trait in ipairs( allTraits ) do
		if champion:hasTrait( trait ) then
			currentTraits[trait] = 1
		end
	end
	traitCounts[champion:getOrdinal()] = currentTraits
end

function drakkanMaceEquip(champion, slot)
   local ordinal = champion:getOrdinal()
   local skill = champion:getSkillLevel("maces")
   local name1 = champion:getName()
   if slot == 7 or slot == 8 then
      if ( champion:getRace() == "Minotaur" and skill >= 5 ) then
         champion:modifyStatCapacity("strength", 5)
         champion:modifyStat("strength", 5)
		 local oldCount = traitCounts[ordinal]["tough"] or 0
		 if oldCount == 0 then
			champion:addTrait("tough")
		 end
		 traitCounts[ordinal]["tough"] = oldCount + 1
         hudPrint(""..name1..":Ahh now... THIS is what I have been looking for!")
      else
		champion:removeItem(slot)
		spawn( "drakkan_minotaur_mace" , party.level , party.x , party.y , party.facing )
		playSound("item_drop")
	  end
   end
end

function drakkanMaceUnequip(champion, slot)
	local ordinal = champion:getOrdinal()
    local skill = champion:getSkillLevel("maces")
    local name1 = champion:getName()
    if champion:getRace() == "Minotaur" then
        if slot == 7 or slot == 8 then
            if skill >= 5 then
                champion:modifyStatCapacity("strength", -5)
                champion:modifyStat("strength", -5)
				traitCounts[ordinal]["tough"] = traitCounts[ordinal]["tough"] - 1
                if traitCounts[ordinal]["tough"] == 0 then
				   champion:removeTrait("tough")
		 		end
                hudPrint(""..name1..": Hey, what are you doing? That's my weapon!")
            end
        end
    end
end
Then every time an item is equipped that should add a trait, it actually just increments a field within a table within traitCounts . If that field was previously valued at 0 or nil, then we add the trait. When an item is unequipped that should remove a trait, it actually just decrements that same field within that table within traitCounts. If that reduces the new total to 0, then we actually remove the trait.

Re: Special / Magic Weapon Scripts Thread

Posted: Thu Mar 14, 2013 6:36 am
by akroma222
:shock: Absolutely marvelous!! Thank you Marble Mouth for taking the time and effort to sort this one out :D
Glad to know I kinda of knew what to do (just not how to script it up hehe)
I tried the return false for the onEquip functionn too, shame it is not an option at present....
I will implement this and if OK with you, update the original post with your (creditted) code..?
Thanks again :-)

Re: Special / Magic Weapon Scripts Thread

Posted: Thu Mar 14, 2013 8:15 pm
by Drakkan
you guys are crazy ! :)
and awesome ! ;)
thanks

Re: Special / Magic Weapon Scripts Thread

Posted: Fri Mar 15, 2013 2:37 am
by Marble Mouth
akroma222 wrote: I will implement this and if OK with you, update the original post with your (creditted) code..?
Oh, absolutely. I share this stuff in the hopes that it'll be useful :)