Page 17 of 26
Re: Dynamic Script Usage
PostPosted: 07 Aug 2013, 17:00
by Strangelove
I wrote an AutoAttack Function to use in my fighting-maps and would like to have some feedback and maybe some help to optimize it. I am sure here are a lot of ppl that are way more familiar with the dynamic script than I am, since I started like 1 weeks ago.
Here the code of the function:
- Code:
function AutoAttack(iGroupID, iSight: Integer): Integer;
var iLoopX, iLoopY, iX, iY, iTargetU: Integer;
var bBreak: Boolean;
begin
iX := States.UnitPositionX(States.GroupMember(iGroupID, 0));
iY := States.UnitPositionY(States.GroupMember(iGroupID, 0));
for iLoopX := (iX - iSight) to (iX + iSight) do
begin
for iLoopY := (iY - iSight) to (iY + iSight) do
begin
iTargetU := States.UnitAt(iLoopX, iLoopY);
if (iTargetU <> -1) and (States.UnitsGroup(iTargetU) <> iGroupID) then
begin
if States.UnitOwner(iTargetU) <> States.GroupOwner(iGroupID) then
begin
iTargetU := States.GroupMember(States.UnitsGroup(iTargetU), 0);
Actions.GroupOrderAttackUnit(iGroupID, iTargetU);
bBreak := true;
Break;
end;
end;
end;
if bBreak then Break;
end;
end;
I excluded the
- Code:
and States.GroupAt(iLoopX, iLoopY) <> iGroupID
from the script since it does not work with it. I couldnt figure out why. I keep getting the Error Message: Type Mismatch.
EDIT: Nevermind, works if I do it like that:
- Code:
if (iTargetU <> -1) and (States.UnitsGroup(iTargetU) <> iGroupID) then
Re: Dynamic Script Usage
PostPosted: 09 Aug 2013, 20:19
by Tef
Is there a way to override the limitation of not being able to move soldiers during peacetime?
"You know Tef, players could then just set the peacetime to 0 in the lobby..."
Well, I have this script that restricts the zones where soldiers may move during peacetime. If they move out of the allowed zone, they will just try to move back into it. Any smart-ass trying to override walk-commands by insanely right-clicking outside of the zone is punished: the soldiers will then quickly die!

The point is, I could set the peacetime to zero and introduce a given peacetime in the script, but then users could not set the peacetime in the lobby anymore

So that's why I need the limitation to be resolved. Is this currently possible?
Re: Dynamic Script Usage
PostPosted: 10 Aug 2013, 05:38
by Krom
Peacetime belongs to some core mechanics of the game. You just have to accept it and ask players to play your map with PT = 0.
Re: Dynamic Script Usage
PostPosted: 10 Aug 2013, 09:07
by sado1
I workarounded it in a very stupid way and it probably won't apply to your map. I needed a very short peacetime with an ability to move your soldiers. It's a map similar in style to Raven's Field: barracks and lots of recruits - I wanted to give people an opportunity to position their troops before the fight. So, I just spawned loads of AI barbarians in the middle, and after certain specified time, I kill them off so the battle can begin.
Re: Dynamic Script Usage
PostPosted: 10 Aug 2013, 22:10
by Islar
Here is a script i am working on, but i need some help.
When you play my map you will find a town with your scout. When you see the castle of that town you scout will die silently and will be replaced by a AI scout that will walk to the castle. But this did not work. The AI scout will not walk. Now i was thinking is it not easier to use PlayerGetsAllUnits. But i have no idea how that works.

Can someone help my?
Here is the script i have:
- Code:
const
CASTLE_LEFT = 119;
CASTLE_RIGHT = 125;
CASTLE_TOP = 25;
CASTLE_BOTTOM = 31;
var
Spy, Spy2: Integer;
SpyDead: Boolean;
Procedure OnMissionStart;
begin
Spy := States.UnitAt (8, 43);
SpyDead := False;
Actions.FogCoverCircle (0, 121, 28, 30);
Actions.PlayerShareFog (2, 0, false);
Actions.PlayerShareFog (3, 0, false);
Actions.ShowMsg (0, 'A chevalier from CITYNAME have arrived and they would like to know where the light and voices came from. The ones you told about yesterday.');
end;
Procedure OnTick;
var
X, Y: Integer;
begin
for X := CASTLE_LEFT to CASTLE_RIGHT do
for Y := CASTLE_TOP to CASTLE_BOTTOM do
begin
If States.FogRevealed (0, X, Y) then
begin
Actions.UnitKill (Spy, true);
end;
end;
If SpyDead then
Begin
SpyDead := False
Actions.GroupOrderWalk (Spy2, 121, 28, 2);
end;
end;
Procedure OnUnitDied (aUnitID, aKillerIndex: Integer);
var
X, Y, D: Integer;
begin
D := States.UnitDirection (Spy)
X := States.UnitPositionX (Spy)
Y := States.UnitPositionY (Spy)
Begin
If aUnitID = Spy then
begin
SpyDead := True
Actions.GiveGroup (1, 21, X, Y, D, 1, 1);
Spy2 := States.UnitAt (X, Y);
Actions.ShowMsg (0, 'The chevalier have found a town from our neighbour kingdom and is now on his way to the general of this town to ask the reason why he is building in our kingdom.');
end;
end;
end;
Re: Dynamic Script Usage
PostPosted: 10 Aug 2013, 22:13
by Shadaoe
Try replacing
Actions.GiveGroup (1, 21, X, Y, D, 1, 1);
Spy2 := States.UnitAt (X, Y);
with
Spy2 := Actions.GiveGroup (1, 21, X, Y, D, 1, 1);
Re: Dynamic Script Usage
PostPosted: 11 Aug 2013, 02:58
by Lewin
Try replacing
Actions.GiveGroup (1, 21, X, Y, D, 1, 1);
Spy2 := States.UnitAt (X, Y);
with
Spy2 := Actions.GiveGroup (1, 21, X, Y, D, 1, 1);
Yes that should fix your problem. UnitKill does not remove the unit instantly, it can take 1 tick to remove it due to the way the code works (removing it instantly can cause crashes if it's being used or in the middle of something). So the new unit won't be able to be placed on the exact same tile as where the old unit was because the old unit is still there (pending death). So the new unit is placed on the closest available tile and UnitAt gives you a pointer to the old unit.
You need to delay placing the new unit by 1-2 ticks if you want to place it on the same tile as the old one was. This does make the script quite a bit more complicated (Vas had this problem in his campaign) so maybe one day we'll refactor the code in such a way that allows instant killing of units.
Re: Dynamic Script Usage
PostPosted: 11 Aug 2013, 08:32
by Islar
I didn't knew you could do that. But now it workes, thank you.

Re: Dynamic Script Usage
PostPosted: 11 Aug 2013, 12:06
by Islar
When i load my map in kam remake this appeared.
It might be something to do with the script.
This is the script i have. I hope the reason can be found in this script.
Never mind. the problem is solved
Re: Dynamic Script Usage
PostPosted: 12 Aug 2013, 18:58
by Tef
Can you remove or kill a wolf? I spawn wolves with GiveAnimal(wolf, x, y). It gives me a UnitID, but when I use UnitKill, I cannot kill it. Switching between silent or non-silent kill doesn't work either.
Re: Dynamic Script Usage
PostPosted: 14 Aug 2013, 12:10
by Bence791
Well, I am working on a new script idea for the Remake, and I came across with it:
I tried to make it not dependant on the place of action so that I dont have to make each spawning by hand, rather determined where they should go from their spawnpoint.
I made 4 variables, 1 stores the UnitID, 2 store the X and Y coordinate and the last one stores the X+18 value (where they should walk to). The Script Validator says "Invalid number of parametres", at the row of "Actions.GroupOrderWalk". It looks like this (without the exact names of variables).
- Code:
...
begin
UnitID := States.GroupAt(blabla);
begin
X := States.UnitPositionX(UnitID);
Y := States.UnitPositionY(UnitID);
X+18 = X + 18
begin
Actions.GroupOrderWalk(UnitID, X+18, Y);
end;
end;
end;
...
What can be the problem?
EDIT: Oh omg how can I be sooooooo foool x_x I forgot the facing direction parameter xD Didnt ask anything

Re: Dynamic Script Usage
PostPosted: 16 Aug 2013, 10:39
by Tef
Another example what dynamic scipting can do! The GIF below shows an accelerated minimap (about 15 minutes). Does anyone notice anything unusual?

Re: Dynamic Script Usage
PostPosted: 16 Aug 2013, 11:08
by Lewin
That's quite impressive

I look forward to seeing it in-game, it could work well for a battle mission.
Re: Dynamic Script Usage
PostPosted: 16 Aug 2013, 12:13
by Skypper
looks nice

Re: Dynamic Script Usage
PostPosted: 16 Aug 2013, 12:36
by Tef
QUESTION 1
I'm experimenting with custom sounds now, specifically the PlayWAVAtLocation. It says that only mono sounds are supported. However, stereo works just fine, although it is not projected on the left or right channel. Mono sounds are projected left or right, but they are extremely low in volume. I've tried if the volume parameter (0.0 - 1.0) was maybe to 100 but that doesn't work either. Setting different sample rates (22.500 or 44.100 hertz) or bit depths (8 or 16 bit) has no influence as well.
How can I increase the volume of these mono sounds? Currently they are just not loud enough, so I am forced to use a stereo sound. But then I loose the left-right projection. The sound I have is normalized to about 0.0 dB (maximum volume before clipping).
QUESTION 2
Suppose a multiplayer setting of team 1 = player 1-4, and team 2 = player 5-8. If I use FogCoverCircle or FogRevealCircle to change the fog for player 1, and PlayerShareFog(player1, player 2-4) = true (which is the default setting I believe), is the fog for player 2, 3 and 4 automatically updated?
QUESTION 3
Posed earlier: is there a way to remove or kill animals?