Map Database  •  FAQ  •  RSS  •  Register  •  Login

Dynamic script problem

<<

lolslayer

Woodcutter

Posts: 16

Joined: 19 Jul 2016, 18:01

KaM Skill Level: Average

Post 18 Aug 2016, 12:11

Dynamic script problem

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!
<<

lolslayer

Woodcutter

Posts: 16

Joined: 19 Jul 2016, 18:01

KaM Skill Level: Average

Post 18 Aug 2016, 15:55

Re: Dynamic script problem

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;
<<

Esthlos

User avatar

Knight

Posts: 648

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 18 Aug 2016, 18:14

Re: Dynamic script problem

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:
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

lolslayer

Woodcutter

Posts: 16

Joined: 19 Jul 2016, 18:01

KaM Skill Level: Average

Post 18 Aug 2016, 19:31

Re: Dynamic script problem

Esthlos wrote: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
<<

Esthlos

User avatar

Knight

Posts: 648

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 18 Aug 2016, 19:48

Re: Dynamic script problem

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). :(

lolslayer wrote: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
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

lolslayer

Woodcutter

Posts: 16

Joined: 19 Jul 2016, 18:01

KaM Skill Level: Average

Post 18 Aug 2016, 20:28

Re: Dynamic script problem

Esthlos wrote: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). :(

lolslayer wrote: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 ;)
<<

T*AnTi-V!RuZz

User avatar

Site Admin

Posts: 1813

Joined: 03 Jan 2007, 23:00

Location: The Netherlands

KaM Skill Level: Beginner

Post 19 Aug 2016, 15:24

Re: Dynamic script problem

Moved topic to the right forum.. :)
Missing a feature on the forum? Please let me know by sending me a PM :)

<<

lolslayer

Woodcutter

Posts: 16

Joined: 19 Jul 2016, 18:01

KaM Skill Level: Average

Post 19 Aug 2016, 22:48

Re: Dynamic script problem

T*AnTi-V!RuZz wrote:Moved topic to the right forum.. :)


thanks :)
<<

grayter

Axe Fighter

Posts: 77

Joined: 18 Aug 2014, 12:06

Location: Poland

KaM Skill Level: Skilled

Post 25 Jun 2017, 18:40

Re: Dynamic script problem

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=YBlyoaPJq54&feature=youtu.be.
<<

HellFriend

Recruit

Posts: 35

Joined: 20 Jul 2017, 10:32

KaM Skill Level: Average

Post 27 Jan 2018, 21:11

Re: Dynamic script problem

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 :/
<<

HellFriend

Recruit

Posts: 35

Joined: 20 Jul 2017, 10:32

KaM Skill Level: Average

Post 27 Jan 2018, 21:34

Re: Dynamic script problem

Okey i got it :D :) thanks to read this post

Return to Dynamic Scripting

Who is online

Users browsing this forum: No registered users and 8 guests