Page 1 of 1

Dynamic Script Share Thread

PostPosted: 04 May 2013, 01:32
by Philymaster
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;

Re: Dynamic Script Share Thread

PostPosted: 04 May 2013, 09:17
by Lewin
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.

Re: Dynamic Script Share Thread

PostPosted: 04 May 2013, 14:58
by Philymaster
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?

Re: Dynamic Script Share Thread

PostPosted: 04 May 2013, 15:13
by Lewin
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.

Re: Dynamic Script Share Thread

PostPosted: 05 May 2013, 01:21
by Guest
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. :)

Re: Dynamic Script Share Thread

PostPosted: 05 May 2013, 01:36
by Lewin
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.

Re: Dynamic Script Share Thread

PostPosted: 05 May 2013, 10:33
by Ben
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.

Re: Dynamic Script Share Thread

PostPosted: 05 May 2013, 11:22
by sado1
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.