Jump to content


Photo

what does (ACTION_)PHP_EACH do?


  • Please log in to reply
4 replies to this topic

#1 Turambar

Turambar
  • Modder
  • 935 posts

Posted 06 February 2011 - 10:29 AM

From what I've understood, those actions should, given an array string1, for each of its values (string1_0 , string1_1,...) do something (which might concern other arrays?).
I have been using some arrays, so I'd like to know how I can use this, what are string 2 and 3, what is its 'result',...?
For example, if I have an associative array such as that in the sample above, which, I believe, is a case when it could be applied (combining A_P_E with associative arrays):
ACTION_DEFINE_ASSOCIATIVE_ARRAY mix_with_blue BEGIN
  red => purple
  yellow => green
END
What can I do with ACTION_PHP_EACH mix_with_blue AS ..., and what could/should I use as par 2 and 3, and what would happen with them?

Edited by Turambar, 06 February 2011 - 10:30 AM.

Turambar

Currently supporting: DSotSC for BGT, NTotSC - forum

Turambar's fixes and tweaks for BG2, BGT, DSotSC, NTotSC, SoBH and more!

 

Before posting questions (even regarding posts written by myself), please look at Jarno Mikkola's FAQs for the Megamods!
(how to correctly report CTDs)

 


vipersig.jpg


#2 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 06 February 2011 - 10:34 AM

ACTION_PHP_EACH mix_with_blue AS color1 => color2 BEGIN
PRINT ~%color1_0% %color2%~
END

yields:

red purple
yellow green

it's color1_0 and not plain color1 because the first part can have multiple indices:

DEFINE_ASSOCIATIVE_ARRAY colors BEGIN
red, blue => purple
red, yellow => orange
red, green => yellow
END

ACTION_PHP_EACH colors AS color1 => color2 BEGIN
PRINT ~%color1_0% + %color1_1% = %color2%~
END

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#3 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 07 February 2011 - 03:05 PM

Rebuilding the SPELDESC.2DA to use correct spell descriptions. Also defining the the main array.
DEFINE_ACTION_MACRO spelldesc BEGIN

  ACTION_DEFINE_ASSOCIATIVE_ARRAY temple BEGIN
    cure_light_wounds    => sppr103
 //   slow_poison          => sppr212
    call_lightning       => sppr302
    dispel_magic         => sppr303
    remove_curse         => sppr307
    cure_medium_wounds   => sppr315
    cure_disease         => sppr317
    cure_serious_wounds  => sppr401
    neutralize_poison    => sppr404
    lesser_restoration   => sppr417
    cure_critical_wounds => sppr502
    raise_dead           => sppr504
    heal                 => sppr607
    resurrection         => sppr712
    greater_restoration  => sppr713
  END

  ACTION_IF comp_sr=1 BEGIN
    OUTER_SPRINT $temple("cure_medium_wounds") sppr215
    OUTER_SPRINT $temple("cure_serious_wounds") sppr315
    OUTER_SPRINT $temple("cure_critical_wounds") sppr401
  END

  COPY_EXISTING speldesc.2da override
    PHP_EACH temple AS ind => res BEGIN
      REPLACE_TEXTUALLY CASE_INSENSITIVE ~\(%res% +-?[0-9]+ *\)~ ~~ // deleting old description entries, since they're inaccurate
    END

  ACTION_PHP_EACH temple AS ind => res BEGIN
    OUTER_SET strref=~-1~
    COPY_EXISTING - ~%res%.spl~ override PATCH_IF SOURCE_SIZE>0x71 BEGIN
      READ_LONG 0x50 strref
    END
    APPEND speldesc.2da ~%res% %strref%~ // cheers, and without KEEP_CRLF flag it autodeletes extra newlines <img src='http://www.shsforums.net/public/style_emoticons/<#EMO_DIR#>/smile.gif' class='bbc_emoticon' alt=':)' />
  END

END

Patching FUNC to assign a custom set of spells to temples.
DEFINE_PATCH_FUNCTION temple BEGIN
  READ_LONG 0x70 offset
  READ_LONG 0x74 number
  i=0
  DELETE_BYTES offset number*12
  PHP_EACH temple AS ind => res BEGIN
    PATCH_IF VARIABLE_IS_SET EVAL ~%ind%~ BEGIN
      INSERT_BYTES offset+i*12 12
      WRITE_ASCIIE offset+i*12 ~%res%~
      WRITE_LONG offset+i*12+8 EVAL ~%ind%~
      i+=1
    END
  END
  WRITE_LONG 0x74 i
  PATCH_FOR_EACH off IN 0x2c 0x34 0x4c BEGIN
    PATCH_IF LONG_AT off>=offset BEGIN
      WRITE_LONG off (LONG_AT off - (number - i)*12)
    END
  END
END

The TP2 snippet.
LAM spelldesc

///////////////////////////

// BHELM - Guardian Vottnar
// 
// Bridge District

COPY_EXISTING bhelm.sto override PATCH_IF SOURCE_SIZE>0x9b BEGIN

  LPF temple INT_VAR
    cure_light_wounds=25
    dispel_magic=200
    remove_curse=500
    cure_medium_wounds=50
    cure_serious_wounds=75
    raise_dead=1000
  END

END BUT_ONLY

///////////////////////////

// DOGHMA - Priest of Oghma
// 
// Docks

COPY_EXISTING doghma.sto override PATCH_IF SOURCE_SIZE>0x9b BEGIN

  LPF temple INT_VAR
    cure_light_wounds=25
    dispel_magic=50
    remove_curse=125
    cure_medium_wounds=50
    cure_serious_wounds=75
    raise_dead=1000
  END

END BUT_ONLY

///////////////////////////////

// GOVWAU01 - Priest of Waukeen
// 
// Government District

COPY_EXISTING govwau01.sto override PATCH_IF SOURCE_SIZE>0x9b BEGIN

  LPF temple INT_VAR
    cure_light_wounds=25
    dispel_magic=200
    cure_medium_wounds=50
    cure_serious_wounds=75
    neutralize_poison=300
    cure_critical_wounds=100
    raise_dead=1000
  END

END BUT_ONLY

Edited by GeN1e, 07 February 2011 - 03:10 PM.

Retired from modding.


#4 Miloch

Miloch

    Barbarian

  • Modder
  • 6573 posts

Posted 08 February 2011 - 10:47 AM

I guess not all of my code dumps made it in the WeiDU document :P. The second snippet does an associative array, the third one does an ACTION_PHP_EACH to write the values (which is like an ACTION_FOR_EACH, only for the associative array).

Edit: Meant PHP_EACH in the first case.

Edited by Miloch, 08 February 2011 - 10:53 AM.

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 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 08 February 2011 - 10:52 AM

Whoops.

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.