Scripting suggestions (Lua, (V)ERM)

It is time to start collecting scripting features actually needed by mod authors. Small (but complete) script examples would be ideal.

Very enigmatic topic:) Is it topic rather for modders oraz rather for people who can write anything using Lua or ERM?

This topic is mostly for modders, I`d like to see a list of features they want to be implemented first.

WoG script 69: Market of Time - building that let player forget secondary skill for a fee.
(still I don’t know if I understand topic correctly -sorry)

Are special buildings bonuses can be implemented? Like primary skill for visiting hero or bonus during siege?

1 Like

Looks like a good example at first glance - not to many different receivers and no dirty hacks (like UN:C).

You understand it correctly, just try to give more simple examples.

Custom buildings as a solid feature is next goal after scripts. But it might be possible to with standalone scripts earlier.

‘Enhanced’ Cartographer reveals only terrain on which cartograph stands. So if cartograph is placed on grass, reveals only grass terrains, not whole map.

ZVSE
ERMS_PoweredBy=ERM Scripter v. 2004.10.5.945
_WARNING_#1=IMPORTANT! This file is not in a plain text format. NEVER use any editor except ERM_S for making any kind of changes!
ERMS_ScriptName=Ulepszony Kartograf
ERMS_ScriptAuthor=Altair
ERMS_ScriptVersion=1.0.0
ERMS_ScriptDate=13.11(November).2006
ERMS_ScriptERMVersion=2.70



!?OB13;
!!TRv998/v999/v1000:T?v62/?y1/?y1/?y1/?y1/?y1/?y1/?y1;
!!UN:X?v60/?v61;
!!VRv61:+1;
!!OW:C?y8;
!!OW:R-1/6/?y70;
!!VRy71:Sy8+1;

!!VRy71&y8=2:S4;
!!VRy71&y8=3:S8;
!!VRy71&y8=4:S16;
!!VRy71&y8=5:S32;
!!VRy71&y8=6:S64;
!!VRy71&y8=7:S128;


!!POv998/v999/v1000:V1/?y6;

!!VRy7:Sy6;
!!VRy7:&y71;

!!IF&1000/y7<1/y70>=1000:Q3^You meet a Cartographer selling maps for 1000 gold. Do you want to buy a map?^;
!!IF&1000/y7>0:M^I showed you all my maps and now go away.^;
!!IF&1000/y7=0/y70<1000:M^My maps cost 1000 gold. However, it looks like you can't afford it, so don't waste my time.^;

!!OW&1000/3/y70>=1000/y7<1:R-1/6/d-1000;
!!OW&-1000/y70>=1000/y7<1:R-1/6/d-1000;

!!VRy6:|y71;

!!POv998/v999/v1000&1000/3/y70>=1000/y7<1:V1/y6;
!!POv998/v999/v1000&-1000/y70>=1000/y7<1:V1/y6;

!!DO699/0/v61/1&1000/3/y70>=1000/y7<1:P;
!!DO699/0/v61/1&-1000/y70>=1000/y7<1:P;


!!OB998:S;
!?FU699;
!!DO700/0/v60/1:Px16;



!?FU700;
!!OW:C?y8;
!!DO701/0/v60/1:Px16/x1/y8;

!?FU701;

!!TRx16/x1/x2:T?y7/?y1/?y1/?y1/?y1/?y1/?y1/?y1;
!!UN&y7=v62:Sx16/x1/x2/x3/0;

Heroes with peasants in army get 2 gold per day for every peasant.

ZVSE
!#VRz842:S^Pays taxes.^; 
!#UN:G1/139/2/z842;

!#TM15:S1/999/1/255; 
 
!?TM15; 
!!DO150/0/155/1:P; 
 
!?FU150; 
!!OW:C?y1; ** check current player 
!!HEx16:O?y2; ** check owner 
!!DO151/0/6/1&y1=y2:Px16/y2; 
 
!?FU151; 
!!HEx1:C0/x16/?y1/?y2; 
!!VRy3&y1=139:Sy2*2; 
!!VRy3&y1<>139:S0; 
!!OW:Rx2/6/dy3;

Last two examples are not sugestions, just simple and complete erm scripts.

This is kind of evil for VCMI, reveal tiles one by one may be too slow.

This is where I have questions. How object visit receiver should look in VCMI?

!?OBxxx; !?OBxxx/xxx; - like ERM (but it will work for modded objects if you resolve numeric id)
!?OB^handlerName^; - by handler name
!?OB^objectGroup^; !?OB^objectGroup^/^objectType^; - by json keys for type/subtype 

This looks promising, I`ll start with this one.

This will take … some time, but I can show how it it should look as a mod.

There are some (simple I think) lua scripts written for wog 3.59 by GrayFace.

ERM scripts in 3.59 are not simpler than 3.58, Lua API from WoG is completely irrelevant for VCMI.

Another simple script from [quote=“AVS, post:11, topic:5207”]
This is where I have questions. How object visit receiver should look in VCMI?

!?OBxxx; !?OBxxx/xxx; - like ERM (but it will work for modded objects if you resolve numeric id)
!?OB^handlerName^; - by handler name
!?OB^objectGroup^; !?OB^objectGroup^/^objectType^; - by json keys for type/subtype 

I think by json keys for type/subtype.

Another smaller script from ERA.
Conflux rebalacing.

Growth Pixie/Sprite: 15,
Growth of all Elementals: 5,
Firebirds/Phoenixes are treated as ‘elementals’.

ZVSE
ERMS_ScriptDate=2.10(October).2012
_WARNING_#1=IMPORTANT! This file is not in a plain text format. NEVER use any editor except ERM_S for making any kind of changes!
ERMS_PoweredBy=ERM Scripter v. 2004.10.5.945
** Author orig.  : Algor
** Name          : Conflux balancing
** Name rus.     : Áŕëŕíńčđîâęŕ Ńîďđ˙ćĺíč˙
** Options       : 781
** Dialogs       : -
** Variables     : -
** Tmp variables : -
** Timers        : -
** Functions     : -
** PO-values     : -

!?PI;                         [ďîńň-číńňđóęöč˙]
!!UN:P781/?y1;                [ďđîâĺđ˙ĺě âęëţ÷ĺíŕ ëč îďöč˙ 781 â y1]
!!FU&y1=0:E;                  [âűőîä ĺńëč îďöč˙ íĺ âęëţ÷ĺíŕ]
!!MA:G118/?y11 G119/?y12 G112/?y13 G127/?y14 G115/?y15 G123/?y16 G113/?y17 G125/?y18; [y11-y18 ďđčđîńňű Ôĺé,AWE-Ýëĺěĺíňŕëĺé]
!!VRy11:-5;                   [čçěĺí˙ĺě ďđčđîńňű äî íóćíűő çíŕ÷ĺíčé]
!!VRy12:-5;                   [...]
!!VRy13:-1;                   [...]
!!VRy14:-1;                   [...]
!!VRy15:-1;                   [...]
!!VRy16:-1;                   [...]
!!VRy17:+1;                   [...]
!!VRy18:+1;                   [...]
!!VRy11&y11<1:S1;             [íĺ äŕĺě čě îďóńęŕňüń˙ íčćĺ 1]
!!VRy12&y12<1:S1;             [...]
!!VRy13&y13<1:S1;             [...]
!!VRy14&y14<1:S1;             [...]
!!VRy15&y15<1:S1;             [...]
!!VRy16&y16<1:S1;             [...]
!!MA:G118/y11 G119/y12 G112/y13 G127/y14 G115/y15 G123/y16 G113/y17 G125/y18; [Îáíîâëĺíčĺ ďđčđîńňîâ: Ôĺč-15, AWFE-Ýëĺěĺíňŕëč-5]
!!MA:X130/?y1;                [y1 - ôëŕăč îăí. ďňčö]
!!VRy2:Sy1 &16;               [ďîëó÷ŕĺě ôëŕă "ćčâîĺ ńóůĺńňâî"]
!!VRy1:-y2;                   [óáčđŕĺě ôëŕă "ćčâîĺ ńóůĺńňâî"]
!!VRy1:|131072;               [óńňŕíŕâëčâŕĺě ôëŕă "ýëĺěĺíňŕëü"]
!!MA:X130/y1;                 [îáíîâë˙ĺě ôëŕă îăí. ďňčö]
!!MA:X131/?y1;                [y1 - ôëŕăč ôĺíčęńîâ]
!!VRy2:Sy1 &16;               [ďîëó÷ŕĺě ôëŕă "ćčâîĺ ńóůĺńňâî"]
!!VRy1:-y2;                   [óáčđŕĺě ôëŕă "ćčâîĺ ńóůĺńňâî"]
!!VRy1:|131072;               [óńňŕíŕâëčâŕĺě ôëŕă "ýëĺěĺíňŕëü"]
!!MA:X131/y1;                 [îáíîâë˙ĺě ôëŕă ôĺíčęńîâ]

** end

Not that useful for VCMI, if you just changing particular entities in !?PI it is better to use JSON. However it should work with a few exceptions:

  • !!UN:P - not planned for now, may be in feature.
  • !!MA:X/16 - aka Living trait is not present in VCMI, I`ve ignored it for now. Could be done as “not NON_LIVING”

Another examples:

Creatures placed in town garrisons grow their count by 2% every day
Map dwellings have 25% chance to offer upgraded creatures
Neutral armies are supplied with neutral heroes with some of stats and spells for the time of battle
Speed reverse - slow creatures get huge speed while fast such as archangels / phoenixes etc. get very slow (speed 3 or similar)
Neutral creatures in battle get +10% boost to all statistics every month (fighting pikemen in 2nd month results in them having 11 hitpoitns instead of 10 etc.)

I do not try to give wanted/practical scripts, but “various different kinds” ones.

If these scripts are not wanted/practical, then they should be simple enough to be used as tests (like that one with !!MA, you sent me some time ago).

Magog Fireball-Attack does not damage own troops - script by PerryR

ZVSE

!?MF1;                                  [Magogs Fireball-Attack doesnt damage own troops]
!!SN:W^Magog_Fireball_Enable^/?y1;
!!FU&y1=0:E;
!!BG:N?y1;                              [Get attacking stack number]
!!MF:N?y4;                              [Get defending stack number]
!!BMy1:I?y5;                            [Get attacking stack side]
!!BMy4:I?y6;                            [Get defending stack side]
!!UN:C42149568/4/?y10;                  [Judgement basis (028326c0)]
!!MF&y10=4454752/y5=y6:E0;              [Disable taking damage if Magog Fireball and own team]

!?MR2;                                  [Magogs Fireball-Cast that comes with Stack Expierence doesnt damage own troops]

!!SN:W^Magog_Fireball_Enable^/?y1;
!!FU&y1=0:E;
!!BG:A?y1;                              [Aktion in y1]
!!MR:S?y2 F?y3;
!!if&y1=7/y2=21/y3<=105:;               [Fireball always does 105 damage]
!!MR:N?y10;
!!BMy10:I?y11;
!!MR&y11=0:F100;                        [Disable Magic damage for attacker side from Fireball]
!!en;


!?FU(OnBattleRegeneratePhase);
!!SN:W^Magog_Fireball_Switch^/-1;
!!BA:Q?y1;
!!FU&y1=1:E;                            [Exit in Quick Combat]

!!SN:X?y1;                              [Event parameter]
!!BMy1:T?y2;                            [Acting Monster Type]
!!SN&y2=45:W^Magog_Fireball_Switch^/y1;

!?CM4;
*Show choice in Battle when right clicking defend icon
!!CM:F?y1 I?y2;
!!FU|y1<>512/y2<>2010:E;                [Exit if not rightclick on defend Icon]
!!SN:W^Magog_Fireball_Switch^/?y3;
!!FU&y3=-1:E;
!!BMy3:T?y4;                            [Acting Monster Type]
!!if&y4=45:;

!!VRz1:S^Should the Magog Fireball attack damage own troops^;
!!VRz2:S^Yes^;
!!VRz3:S^No^;

!!VRv3:S0;
!!IF:G1/3/0/1/2/3/0/0/0/0/0/0/0/0/0/;
!!SN&v3=1:W^Magog_Fireball_Enable^/0;
!!SN&v3=2:W^Magog_Fireball_Enable^/1;
!!en:;

!?BA0;
!!SN:W^Magog_Fireball_Enable^/1;

Yes, I know - UN:C :frowning: