Jump to content


Photo

Small code problem


  • Please log in to reply
9 replies to this topic

#1 @vGur

@vGur
  • Member
  • 121 posts

Posted 08 October 2009 - 11:14 AM

For this component to work, I need this code to be done, but can't fix it myself, maeby U can tell me what's wrong.
EDITED:Previous problem (code not patched needed files) was solved, but strange thing occur after, read my next posts if you want help :)
Summary: when armored character take hit, spell (with very low chance) creates a copy of his armor in armor slot (that copy alredy has penalty, so not exect copy, but created from original)

BUT

It's creates small amount of gp (1-3) instead, even when editor (dltcp) says that all references fine :(

p.s. Don't let it end like this

Edited by @vGur, 08 October 2009 - 02:02 PM.


#2 Taimon

Taimon
  • Member
  • 387 posts

Posted 08 October 2009 - 11:36 AM

Maybe you should provide more info, i. e. what is the error message that you are getting and what you are trying to do in general.

#3 Wisp

Wisp
  • Modder
  • 1353 posts

Posted 08 October 2009 - 11:55 AM

I can see four things that are wrong with your code.

1. You are not updating abil_fx_idx (assuming you need to).
2. STRING_COMPARE_CASE does not do regexps.
3. You probably mean "1%item%.spl" for the second STRING_COMPARE_CASE, rather than "%item%.spl".
4. DEST_RES will never have any file extensions (i.e. no .spl). You can either use DEST_RES and "%item%", "1%item%" etc or change DEST_RES into DEST_FILE.

#4 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 08 October 2009 - 01:27 PM

Stay away from STRING_COMPARE(_CASE) anyhow, unless you really know what you're doing - it actually does comparisons (see here). Use the reverse of STRING_EQUAL_CASE instead (=1 instead of =0).

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#5 @vGur

@vGur
  • Member
  • 121 posts

Posted 08 October 2009 - 01:30 PM

Thanks, it was 4 (dest res extensoins issue)
Now all installed and patched. All spells and items looks perfect in dltcp

BUT

when i hit armored char & spell suposed to create damaged version of used armor in arnor slot, it's no an armor creted, but 1gp (for 1st level of damage) or 2gp (for 2nd level) or 3gp (for 3rd level - almost ruined armor), what's this???
Look in dltcp after install (don't worry of you bwp, just uninstall my mod after)

when i manually change refference in spell, to create not damaged version, all works, when i look on items, their fine, but when i create them via console, there still 1-3gp, :WTF:

Attached Files



#6 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 08 October 2009 - 01:38 PM

Use a RequiredSize after your WRITE_(EVALUATED_)ASCIIs. So WRITE_ASCII offset %item% #8 or whatever - you're missing those.

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#7 @vGur

@vGur
  • Member
  • 121 posts

Posted 08 October 2009 - 01:46 PM

Miloch, I can't understand Your last post, what's not wright?

BEGIN ~Gradually melting  heavy armor~

ACTION_FOR_EACH ~item~ IN
//splint
//  ~C2VALY01~
  ~CHAN17~
  ~CHAN20~
  ~PLAT18~
  ~CHAN04~
  ~CHAN05~
  ~CHAN18~
  ~ICHAN04~
//  ~VISCHAN2~
  ~BAND01~
  ~BAND02~
  ~BAND03~
  ~BAND04~
//plates
//  ~C2PLAT01~
//  ~DeITM088~
  ~IPLAT01~
  ~PLAT01~
  ~PLAT02~
  ~PLAT06~
  ~PLAT07~
  ~PLAT08~
  ~PLAT10~
  ~PLAT11~
  ~PLAT12~
  ~PLAT13~
  ~PLAT17~
  ~PLAT98~
  ~PLAT99~
//  ~VISPLAT1~
//field plates
  ~FLAT01~
  ~FLAT02~
  ~FLAT03~
  ~FLAT04~
//full plates
//  ~BRUENPLA~
//  ~C2KELD01~
  ~CHALARM~
//  ~DeITM086~
//  ~DeITM090~
//  ~DeITM096~
//  ~DWPLAT01~
  ~NPPLAT~
  ~PALPLAT~
  ~PLAT04~
  ~PLAT05~
  ~PLAT09~
  ~PLAT14~
  ~PLAT15~
  ~PLAT16~
  ~PLAT19~
  ~PLAT20~
  ~PLAT21~
  ~PLAT22~
  ~PLAT23~
//  ~SECRET05~
//  ~VISPLAT2~
  ~WA2PLAT~
//  ~CBBDARMR~
BEGIN
  ACTION_IF FILE_EXISTS_IN_GAME ~%item%.itm~ THEN BEGIN

	COPY_EXISTING ~%item%.itm~ ~override/3%item%.itm~
								   ~%item%.itm~ ~override/1%item%.itm~
								   ~%item%.itm~ ~override/2%item%.itm~
								   ~%item%.itm~ ~override/%item%.itm~
	  PATCH_IF (SOURCE_SIZE > 0x71) BEGIN
		READ_ASCII 0x22 ~anim~ (2)
//		PATCH_IF (~%anim%~ STRING_COMPARE_CASE ~[cC][0-1]~ = 0) BEGIN // armor anims
//		END
		PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "%item%" = 0) BEGIN // if original
		  READ_LONG  0x6A "fx_offset"
		  READ_SHORT 0x70 "fx_number"
//for testing, if U don't like  it, comment
		  INSERT_BYTES  ("%fx_offset%" + ("%fx_number%" * 0x30)) 0x30
			WRITE_SHORT ("%fx_offset%" + ("%fx_number%" * 0x30)) 232   //  cast on condition
			WRITE_BYTE  ("%fx_offset%" + 0x02 + ("%fx_number%" * 0x30)) 1   // target self
			WRITE_LONG  ("%fx_offset%" + 0x04 + ("%fx_number%" * 0x30)) 0   // on caster
			WRITE_LONG  ("%fx_offset%" + 0x08 + ("%fx_number%" * 0x30)) 0  // when hited
			WRITE_BYTE  ("%fx_offset%" + 0x0c + ("%fx_number%" * 0x30)) 2   // instant-while equipped
			WRITE_BYTE  ("%fx_offset%" + 0x12 + ("%fx_number%" * 0x30)) 100 // probability (as 1 on d20), it's not a final chance, the spell has only 50%
			WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~%item%~ //spell, that create damaged version of this item
			WRITE_SHORT 0x70 ("%fx_number%" +1)
		END //patch if "item"
		PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "1%item%" = 0) BEGIN // creates lightly damaged version of armor
		  SAY NAME1 ~Lightly damaged armor penalty1~
		  READ_LONG  0x6A "fx_offset1"
		  READ_SHORT 0x70 "fx_number1"
		  SET "loops1" = "%fx_number1%"
		  SET "found_ac" = 0 // false
		  WHILE (("%loops1%" > 0) AND ("%found_ac%" = 0)) BEGIN // this major WHILE loop examines existing effects and adjusts them accordingly
			READ_SHORT ("%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "opcode"
			READ_LONG (0x08 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "type"
			PATCH_IF (("%opcode%" = 0) AND ("%type%" = 16)) BEGIN // looking for existante base ac
			  READ_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "ex_ac"
			  WRITE_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) ("%ex_ac%" + 1) //+1 in this case means penalty, coz for base ac lower is better
			  SET "found_ac" = 1 // true
			END
			SET "loops1" = ("%loops1%" - 1)
		  END //while
		  READ_LONG  0x6A "fx_offset"
		  READ_SHORT 0x70 "fx_number"
//for testing, if U don't like  it, comment
		  INSERT_BYTES  ("%fx_offset%" + ("%fx_number%" * 0x30)) 0x30
			WRITE_SHORT ("%fx_offset%" + ("%fx_number%" * 0x30)) 232   //  cast on condition
			WRITE_BYTE  ("%fx_offset%" + 0x02 + ("%fx_number%" * 0x30)) 1   // target self
			WRITE_LONG  ("%fx_offset%" + 0x04 + ("%fx_number%" * 0x30)) 0   // on caster
			WRITE_LONG  ("%fx_offset%" + 0x08 + ("%fx_number%" * 0x30)) 0  // when hited
			WRITE_BYTE  ("%fx_offset%" + 0x0c + ("%fx_number%" * 0x30)) 2   // instant-while equipped
			WRITE_BYTE  ("%fx_offset%" + 0x12 + ("%fx_number%" * 0x30)) 5 // probability (as 1 on d20), it's not a final chance, the spell has only 50%
			WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~1%item%~
			WRITE_SHORT 0x70 ("%fx_number%" +1)
		END //patch if "item"
		PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "2%item%" = 0) BEGIN // if seriously damaged
		  SAY NAME1 ~Seriously damaged armor penalty3~
		  READ_LONG  0x6A "fx_offset1"
		  READ_SHORT 0x70 "fx_number1"
		  SET "loops1" = "%fx_number1%"
		  WHILE ("%loops1%" > 0) BEGIN // this major WHILE loop examines existing effects and adjusts them accordingly
			READ_SHORT ("%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "opcode"
			READ_LONG (0x08 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "type"
			PATCH_IF (("%opcode%" = 0) AND ("%type%" = 16)) BEGIN // looking for existante base ac
			  READ_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "ex_ac"
			  WRITE_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) ("%ex_ac%" + 3) //+3 in this case means penalty, coz for base ac lower is better
//			SET "found_ac" = 1 // true
			END
			SET "loops1" = ("%loops1%" - 1)
		  END //while
		  READ_LONG  0x6A "fx_offset"
		  READ_SHORT 0x70 "fx_number"
//for testing, if U don't like  it, comment
		  INSERT_BYTES  ("%fx_offset%" + ("%fx_number%" * 0x30)) 0x30
			WRITE_SHORT ("%fx_offset%" + ("%fx_number%" * 0x30)) 232   //  cast on condition
			WRITE_BYTE  ("%fx_offset%" + 0x02 + ("%fx_number%" * 0x30)) 1   // target self
			WRITE_LONG  ("%fx_offset%" + 0x04 + ("%fx_number%" * 0x30)) 0   // on caster
			WRITE_LONG  ("%fx_offset%" + 0x08 + ("%fx_number%" * 0x30)) 0  // when hited
			WRITE_BYTE  ("%fx_offset%" + 0x0c + ("%fx_number%" * 0x30)) 2   // instant-while equipped
			WRITE_BYTE  ("%fx_offset%" + 0x12 + ("%fx_number%" * 0x30)) 5 // probability (as 1 on d20), it's not a final chance, the spell has only 50%, yeah, armor cost lives
			WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~2%item%~
			WRITE_SHORT 0x70 ("%fx_number%" +1)
		END //patch if "item"
		PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "3%item%.itm" = 0) BEGIN // if critically damaged, means, next step is crap, not armor
		  SAY NAME1 ~Critically damaged armor penalty6~
		  READ_LONG  0x6A "fx_offset1"
		  READ_SHORT 0x70 "fx_number1"
		  SET "loops1" = "%fx_number1%"
		  WHILE ("%loops1%" > 0) BEGIN // this major WHILE loop examines existing effects and adjusts them accordingly
			READ_SHORT ("%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "opcode"
			READ_LONG (0x08 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "type"
			PATCH_IF (("%opcode%" = 0) AND ("%type%" = 16)) BEGIN // looking for existante base ac
			  READ_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) "ex_ac"
			  WRITE_LONG (0x04 + "%fx_offset1%" + (("%loops1%" - 1) * 0x30)) ("%ex_ac%" + 6) //+6 in this case means penalty, coz for base ac lower is better
//			SET "found_ac" = 1 // true
			END
			SET "loops1" = ("%loops1%" - 1)
		  END //while
		  READ_LONG  0x6A "fx_offset"
		  READ_SHORT 0x70 "fx_number"
//for testing, if U don't like  it, comment
		  INSERT_BYTES  ("%fx_offset%" + ("%fx_number%" * 0x30)) 0x30
			WRITE_SHORT ("%fx_offset%" + ("%fx_number%" * 0x30)) 232   //  cast on condition
			WRITE_BYTE  ("%fx_offset%" + 0x02 + ("%fx_number%" * 0x30)) 1   // target self
			WRITE_LONG  ("%fx_offset%" + 0x04 + ("%fx_number%" * 0x30)) 0   // on caster
			WRITE_LONG  ("%fx_offset%" + 0x08 + ("%fx_number%" * 0x30)) 0  // when hited
			WRITE_BYTE  ("%fx_offset%" + 0x0c + ("%fx_number%" * 0x30)) 2   // instant-while equipped
			WRITE_BYTE  ("%fx_offset%" + 0x12 + ("%fx_number%" * 0x30)) 5 // probability (as 1 on d20), it's not a final chance, the spell has only 50%
			WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~3%item%~
			WRITE_SHORT 0x70 ("%fx_number%" +1)
		END //patch if "item"
	  END //if size
//	  INNER_ACTION BEGIN
	  COPY_EXISTING ~_part1/_D3/_@source.spl~ ~override/%item%.spl~
		~_part1/_D3/_@source.spl~ ~override/1%item%.spl~
		~_part1/_D3/_@source.spl~ ~override/2%item%.spl~
		~_part1/_D3/_@source.spl~ ~override/3%item%.spl~
		READ_LONG  0x64 "abil_off"
		READ_SHORT 0x68 "abil_num"
		READ_LONG  0x6a "fx_off"
		SET "fx_delta" = 0
		FOR (index2 = 0; index2 < abil_num; index2 = index2 + 1) BEGIN
		  READ_SHORT  ("%abil_off%" + 0x10 + (0x28 * "%index2%")) "min_lev"
		  READ_SHORT  ("%abil_off%" + 0x1e + (0x28 * "%index2%")) "abil_fx_num"
		  READ_SHORT  ("%abil_off%" + 0x20 + (0x28 * "%index2%")) "abil_fx_idx"
		  SET "abil_fx_idx" = "%abil_fx_idx%" + "%fx_delta%"
//		  WRITE_SHORT ("%abil_off%" + 0x20 + (0x28 * "%index%")) "%abil_fx_idx%"
		  INSERT_BYTES   ("%fx_off%" +		(0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 0x30
			WRITE_SHORT  ("%fx_off%" +		(0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 143			  // create item in slot
			WRITE_BYTE   ("%fx_off%" + 0x02 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 1				// target self
			WRITE_LONG   ("%fx_off%" + 0x04 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 1	  // slot:armor
//			WRITE_LONG   ("%fx_off%" + 0x08 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 0				// unused
			WRITE_BYTE   ("%fx_off%" + 0x0c + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%")))  9   // duration type - perm after death
//			WRITE_LONG   ("%fx_off%" + 0x0e + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 0			  // duration
			WRITE_BYTE   ("%fx_off%" + 0x12 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) 50			  // probability, as coin, 50/50
			PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "%item%" = 0) BEGIN
			  WRITE_EVALUATED_ASCII ("%fx_off%" + 0x14 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) ~1%item%~ // item
			END
			PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "1%item%" = 0) BEGIN
			  WRITE_EVALUATED_ASCII ("%fx_off%" + 0x14 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) ~2%item%~ // item
			END
			PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "2%item%" = 0) BEGIN
			  WRITE_EVALUATED_ASCII ("%fx_off%" + 0x14 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) ~3%item%~ // item
			END
			PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "3%item%" = 0) BEGIN
			  WRITE_ASCII ("%fx_off%" + 0x14 + (0x30 * ("%abil_fx_idx%" + "%abil_fx_num%"))) ~MISC58~ // crap, that's all folks
			END
		  SET "abil_fx_num" = "%abil_fx_num%" + 1
//		  SET "fx_delta" = "%fx_delta%" + 1
		  WRITE_SHORT ("%abil_off%" + 0x1e + (0x28 * "%index2%")) "%abil_fx_num%"
		END
//	  END //inner action
  END //action if
END // Action for each


#8 -Guest-

-Guest-
  • Guest

Posted 08 October 2009 - 02:55 PM

Don't begin your item names with a number.

#9 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 08 October 2009 - 03:08 PM

Miloch, I can't understand Your last post, what's not wright?

Don't do this:
WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~1%item%~
Do this instead, otherwise you may well have issues with junked slots:
WRITE_EVALUATED_ASCII ("%fx_offset%" + 0x14 + ("%fx_number%" * 0x30)) ~%item%1~ #8
Also, as Guest says, it's not a great idea to prefix with a number - put it at the end instead.

Don't do this either:
PATCH_IF (~%DEST_RES%~ STRING_COMPARE_CASE "%item%" = 0) BEGIN
Do this instead, or you may well have issues such as I mentioned in the above link:
PATCH_IF (~%DEST_RES%~ STRING_EQUAL_CASE "%item%" = 1) BEGIN

Infinity Engine Contributions
Aurora * BG1 NPC * BG1 Fixpack * Haiass * Infinity Animations * Level 1 NPCs * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * BG:EE * BGII:EE * IWD:EE
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * Creature Checker * Creature Fixer * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Infinity turns out to be the opposite of what people say it is. It is not 'that which has nothing beyond itself' that is infinite, but 'that which always has something beyond itself'." -Aristotle


#10 @vGur

@vGur
  • Member
  • 121 posts

Posted 08 October 2009 - 03:39 PM

Rewrited code using 2da for all used filenames and, it helps

Miloch, Guest, Thanx, really

I did it not the way U say, BUT now I understand what You talking about and will use your advises in future

p.s. Thanx again, STARTING NAME WITH A NUMBER IS A REALLY BAD IDEA!

p.p.s Now i need a dialog for cespenat to fix all this melted armor, or just let it crash eventually? Crisis, You know

Edited by @vGur, 09 October 2009 - 07:07 AM.