Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Share Thread

<<

Philymaster

Peasant

Posts: 4

Joined: 02 Dec 2012, 00:43

KaM Skill Level: Skilled

Post 04 May 2013, 01:32

Dynamic Script Share Thread

Hey, scripter out there :)
I have decide to share my current and future scripts with the community. I have used a common name for the thread so all people can share scripts here. :D

GetGroups
Return all Group IDs from any player.

Parameter:
PlayerID (Integer) = The player you want to get all groups from.
SizeX (Word) = Map Size X.
SizeY (Word) = Map Size Y.

Since we can't access the map data while run-time, my function needs the size to know the size of your map.

Code:
  Code:
Function ElementExist(Integers: Array Of Integer; Element: Integer) : Boolean; Var I: Integer; Begin Result := False; For I := 0 To High(Integers) Do Begin If (Integers[I] = Element) Then Begin Result := True; Exit; End; End; End; Function GetGroups(PlayerID: Integer; SizeX, SizeY: Word) : Array Of Integer; Var X, Y: Byte; GroupID: Integer; Begin For X := 0 To SizeX Do Begin For Y := 0 To SizeY Do Begin GroupID := States.GroupAt(X, Y); If (GroupID <> -1) Then Begin If (States.GroupOwner(GroupID) = PlayerID) Then Begin If (ElementExist(Result, GroupID)) Then Begin Continue; End; SetLength(Result, Length(Result) + 1); Result[High(Result)] := GroupID; End; End; End; End; End;
Usage:
  Code:
Procedure OnMissionStart(); Var Groups: Array Of Integer; I: Integer; Begin // Get all group IDs from player 2 and save it in the local array Groups. Groups := GetGroups(2, 144, 144); // Loop through all groups and order them to attack. Here the players house at 59, 131 will be attacked. For I := 0 to High(Groups) Do Begin Actions.GroupOrderAttackHouse(Groups[I], States.HouseAt(59, 131)); End; End;
Warning: Don't call this method every tick, but rather call it every second. This you can easily achieve with following code.

Usage + Call it every second:
  Code:
Procedure OnTick(); Var Groups: Array Of Integer; I: Integer; Begin If (States.GameTime mod 10 = 0) Then Begin // Get all group IDs from player 2 and save it in the local array Groups. Groups := GetGroups(2, 144, 144); // Loop through all groups and order them to attack. Here the players house at 59, 131 will be attacked. For I := 0 to High(Groups) Do Begin Actions.GroupOrderAttackHouse(Groups[I], States.HouseAt(59, 131)); End; End; End;
<<

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 04 May 2013, 09:17

Re: Dynamic Script Share Thread

This thread is a good idea. But scanning the entire map like that is not a good idea :P

Since the last RC we've added: States.PlayerGetAllUnits, States.PlayerGetAllHouses and States.PlayerGetAllGroups. They work similarly to your function but MUCH more efficiently.
<<

Philymaster

Peasant

Posts: 4

Joined: 02 Dec 2012, 00:43

KaM Skill Level: Skilled

Post 04 May 2013, 14:58

Re: Dynamic Script Share Thread

This thread is a good idea. But scanning the entire map like that is not a good idea :P

Since the last RC we've added: States.PlayerGetAllUnits, States.PlayerGetAllHouses and States.PlayerGetAllGroups. They work similarly to your function but MUCH more efficiently.
Yeah, the script is more intended for replacement until the newest RC is out. :)

But i'm still need functions and procedures i can't script myself. Somewhat like:
  Code:
Procedure ChangeMapTile(NewTexture: TileEnum; NewHeigth: Byte);
Do you think you and Krom could implement this in Actions namespace?
<<

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 04 May 2013, 15:13

Re: Dynamic Script Share Thread

But i'm still need functions and procedures i can't script myself. Somewhat like:
  Code:
Procedure ChangeMapTile(NewTexture: TileEnum; NewHeigth: Byte);
Do you think you and Krom could implement this in Actions namespace?
We're open to suggestions, I added that idea to our proposals list. But there are some issues with it, it will make it very easy to crash the game if you can change a tile underneath a unit causing them to become stuck (which can cause crashes, especially if they are in the middle of doing something). We could make the function not work if there is a unit that would become stuck, but then it becomes less useful because you can't tell where the player might place his units when you use that command.
<<

Guest

Post 05 May 2013, 01:21

Re: Dynamic Script Share Thread

But i'm still need functions and procedures i can't script myself. Somewhat like:
  Code:
Procedure ChangeMapTile(NewTexture: TileEnum; NewHeigth: Byte);
Do you think you and Krom could implement this in Actions namespace?
We're open to suggestions, I added that idea to our proposals list. But there are some issues with it, it will make it very easy to crash the game if you can change a tile underneath a unit causing them to become stuck (which can cause crashes, especially if they are in the middle of doing something). We could make the function not work if there is a unit that would become stuck, but then it becomes less useful because you can't tell where the player might place his units when you use that command.
I see what you mean, but for my uses i would only need to change mountains so secret ways will be revealed.
Also the function would be really useful for repairing broken bridges after some time, destroy a wall or just open a closed door so groups can go and teleport somewhere else.

For security purposes scripter who use this function can make a function and check if there are units and react on it.

In the end its your and Kroms choice, but i would appreciate it if you implement it. :)
<<

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 05 May 2013, 01:36

Re: Dynamic Script Share Thread

Stuff like repairing bridges/destroying walls would be cool. We can make the command automatically not work if there's a unit/house/field/road on that tile which should prevent it from crashing the game.

See, we don't want to make script commands which can crash the game because then people will think it's a bug in the engine, not the script. Especially if it works most of the time and only crashes under rare circumstances, for example if you place units at the place where the script tries to create a wall. That's why we check that all the parameters of commands are valid and write errors to the log if something is invalid, rather than just letting the game crash. So hopefully we can do the same for commands like changing terrain.
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 05 May 2013, 10:33

Re: Dynamic Script Share Thread

I thought that changing tiles would be neat to give everlasting supplies of resources on a map. Personally, I'd like to see some maps with everlasting resources outside of the locations in effort to discourage camping.
I used to spam this forum so much...
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 05 May 2013, 11:22

Re: Dynamic Script Share Thread

I dunno, would be a pain to script it anyway... Although I'm pretty sure there are some other ideas for dynamic tile management, that I will like more. Maybe a scriptable "do not walk"/"do walk" for a tile would be easier to implement, for at least a bit of the functionality?

And I doubt the idea about making the players to go out of their bases for extra resources would work. Expanding while fighting rarely is a good idea when playing against good and active players.

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 15 guests