Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

Strangelove

User avatar

Crossbowman

Posts: 230

Joined: 30 Jul 2013, 06:32

KaM Skill Level: Fair

Post 07 Aug 2013, 17:00

Re: Dynamic Script Usage

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

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 09 Aug 2013, 20:19

Re: Dynamic Script Usage

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

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 10 Aug 2013, 05:38

Re: Dynamic Script Usage

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.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 10 Aug 2013, 09:07

Re: Dynamic Script Usage

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

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 10 Aug 2013, 22:10

Re: Dynamic Script Usage

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

Shadaoe

Knight

Posts: 584

Joined: 28 Jul 2011, 22:00

Website: https://www.youtube.com/user/KaMRemake

Post 10 Aug 2013, 22:13

Re: Dynamic Script Usage

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

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 11 Aug 2013, 02:58

Re: Dynamic Script Usage

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

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 11 Aug 2013, 08:32

Re: Dynamic Script Usage

I didn't knew you could do that. But now it workes, thank you. :D
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 11 Aug 2013, 12:06

Re: Dynamic Script Usage

When i load my map in kam remake this appeared. :(
Error.gif
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
You do not have the required permissions to view the files attached to this post.
<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 12 Aug 2013, 18:58

Re: Dynamic Script Usage

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

Bence791

Knight

Posts: 618

Joined: 20 Jul 2012, 20:25

KaM Skill Level: Beginner

Location: Hungary

Post 14 Aug 2013, 12:10

Re: Dynamic Script Usage

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 :$
The Kamper is always taking my colour!

<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 16 Aug 2013, 10:39

Re: Dynamic Script Usage

Another example what dynamic scipting can do! The GIF below shows an accelerated minimap (about 15 minutes). Does anyone notice anything unusual? ;)

Image
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 16 Aug 2013, 11:08

Re: Dynamic Script Usage

That's quite impressive :) I look forward to seeing it in-game, it could work well for a battle mission.
<<

Skypper

Knight

Posts: 436

Joined: 28 Jun 2013, 09:37

KaM Skill Level: Fair

Location: Dutch :D

Post 16 Aug 2013, 12:13

Re: Dynamic Script Usage

looks nice :)
Greets Skypper (Totally Insane)

- Beginning map maker -
<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 16 Aug 2013, 12:36

Re: Dynamic Script Usage

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?

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 3 guests