Page 1 of 1

Dynamic script problem

PostPosted: 18 Aug 2016, 12:11
by lolslayer
Hey everybody, I started to learn dynamic scripting, I'm having a problem.

I'm trying to create a militia who kills on one hit, but somehow it doesn't work, with archers it seems to work sometimes though.

This is my code:
  Code:
procedure OnUnitWounded(aUnit: Integer; aAttacker: Integer); begin if States.UnitType(aAttacker) = 14 then begin Actions.UnitKill(aUnit,false); end; end;
It just seems like OnUnitWounded doesn't really work, because it does with OnUnitAttacked

Is it maybe because of that wounding an enemy is random, and if so, is there a way to check every time a unit is hit by another unit, wounded or not?

Many thanks in advace!

Re: Dynamic script problem

PostPosted: 18 Aug 2016, 15:55
by lolslayer
Just want to add here, I'm really glad that I learned scripting, I made a script in the first day already where every (here 2) player can place their warehouse where they want in the beginning of the round with the help of beacons, I'll also give the code for you guys if you're interested. :)
  Code:
var CX: Integer; var CY: Integer; var PlayerTurn: Integer; var WX: array[1..2] of integer; var WY: array[1..2] of integer; var WI: array[1..2] of integer; procedure OnMissionStart; begin PlayerTurn := 0; WI[1] := Actions.GiveHouse(0,11,3,55); WI[2] := Actions.GiveHouse(1,11,7,55); Actions.ShowMsg(0,'It is your turn to place a warehouse with the help of a beacon, press B on the keyboard to place one.'); end; procedure OnBeacon(aPlayer: Integer; aX: Word; aY: Word); begin if PlayerTurn = aPlayer then begin if Actions.GiveHouse(aPlayer,11,aX,aY) >= 0 then begin Actions.HouseDestroy(WI[aPlayer+1],false); Actions.GiveWares(aPlayer,1,10000); Actions.GiveWares(aPlayer,7,10000); Actions.GiveWares(aPlayer,2,80); Actions.GiveWares(aPlayer,8,100); Actions.GiveWares(aPlayer,10,80); Actions.GiveWares(aPlayer,13,40); Actions.GiveWares(aPlayer,27,60); for CX:=0 to 2 do begin for CY:=0 to 1 do begin Actions.GiveRoad(aPlayer,aX-1+CX,aY+1+Cy); end; end; WX[aPlayer+1] := aX; WY[aPlayer+1] := aY; PlayerTurn := PlayerTurn + 1; Actions.ShowMsg(PlayerTurn,'It is your turn to place a warehouse with the help of a beacon, press B on the keyboard to place one.'); if PlayerTurn = 2 then begin for CX:=0 to 1 do begin Actions.GiveUnit(CX,9,WX[CX+1]-2,WY[CX+1]+1,4); Actions.GiveUnit(CX,9,WX[CX+1]-2,WY[CX+1]+2,4); Actions.GiveUnit(CX,9,WX[CX+1]+2,WY[CX+1]+1,4); Actions.GiveUnit(CX,9,WX[CX+1]+2,WY[CX+1]+2,4); Actions.GiveUnit(CX,0,WX[CX+1]-1,WY[CX+1]+1,4); Actions.GiveUnit(CX,0,WX[CX+1]-1,WY[CX+1]+2,4); Actions.GiveUnit(CX,0,WX[CX+1] ,WY[CX+1]+1,4); Actions.GiveUnit(CX,0,WX[CX+1] ,WY[CX+1]+2,4); Actions.GiveUnit(CX,0,WX[CX+1]+1,WY[CX+1]+1,4); Actions.GiveUnit(CX,0,WX[CX+1]+1,WY[CX+1]+2,4); Actions.FogCoverAll(CX); end; end; end; end; end;

Re: Dynamic script problem

PostPosted: 18 Aug 2016, 18:14
by Esthlos
Every time a warrior attacks another one, there is indeed a certain chance that the hit connects and actually does damage; OnUnitWounded only runs when this happens.

OnUnitAttacked, instead, runs regardless of this (not always in sync with the graphics, though).

Also, there's no need to use player turns in your script... :wink:

Re: Dynamic script problem

PostPosted: 18 Aug 2016, 19:31
by lolslayer
Every time a warrior attacks another one, there is indeed a certain chance that the hit connects and actually does damage; OnUnitWounded only runs when this happens.

OnUnitAttacked, instead, runs regardless of this (not always in sync with the graphics, though).

Also, there's no need to use player turns in your script... :wink:
Too bad, because I wanted to create one hit kill archers, but this way they would kill the enemy already when shooting the arrow, not when hitting :/

Is there a way to edit unit settings, like how fast archers can shoot and how much damage they do?

And I know that you don't have to use turns, but it's a little bit coherent, before you know it 2 guys create a warehouse just next to eachother, well, that isn't something you want to happen xD

Re: Dynamic script problem

PostPosted: 18 Aug 2016, 19:48
by Esthlos
Unit settings can be edited, but not through dynamic scripting (which means that such edits only affect single player and make it impossible to play multiplayer unless reverted). :(
And I know that you don't have to use turns, but it's a little bit coherent, before you know it 2 guys create a warehouse just next to eachother, well, that isn't something you want to happen xD
You could forbid that by using a distance check or limiting the available zones for each player. :P

Re: Dynamic script problem

PostPosted: 18 Aug 2016, 20:28
by lolslayer
Unit settings can be edited, but not through dynamic scripting (which means that such edits only affect single player and make it impossible to play multiplayer unless reverted). :(
And I know that you don't have to use turns, but it's a little bit coherent, before you know it 2 guys create a warehouse just next to eachother, well, that isn't something you want to happen xD
You could forbid that by using a distance check or limiting the available zones for each player. :P
True, but I think I found a way to balance the turns ;)

Re: Dynamic script problem

PostPosted: 19 Aug 2016, 15:24
by T*AnTi-V!RuZz
Moved topic to the right forum.. :)

Re: Dynamic script problem

PostPosted: 19 Aug 2016, 22:48
by lolslayer
Moved topic to the right forum.. :)
thanks :)

Re: Dynamic script problem

PostPosted: 25 Jun 2017, 18:40
by grayter
This can be achieved by dynamic scripts only. I wrote this and tested entire week. SuperUnits will be included in new "On Foreign Lands 2" campaign.There's no need to interfere into game mechanics. Unit behavior is presented on youtube https://www.youtube.com/watch?v=YBlyoaP ... e=youtu.be.

Re: Dynamic script problem

PostPosted: 27 Jan 2018, 21:11
by HellFriend
Hello can i ask in script too ?

if ((States.UnitPositionX(KnightID) = X1)
AND (States.UnitPositionY(KnightID) = Y1)) then
begin
Actions.ShowMsg(1, '<$2>');
Actions.PlayerAllianceChange(1, 4, true, true);
end;

I have problem in this its in precedure OnTick
and i want if unit came on X1:Y1 Show Msg and change ally but its problem message show again and again if unit is on same coordinates. I tried few var, while, for but nothing work :/

Re: Dynamic script problem

PostPosted: 27 Jan 2018, 21:34
by HellFriend
Okey i got it :D :) thanks to read this post