Page 1 of 1

New scripts since r5503

PostPosted: 02 Oct 2013, 04:54
by Krom
Here's a list of scripts that got implemented since the last Scripting Demo (r5503). Until the next Demo is released these are subject to change. If you have any ideas or suggestions about THESE scripts (functioning, parametres, etc.) please write them here :)
If you want to suggest new script ideas - discussion is here: viewtopic.php?f=24&t=1495
Full list of script commands can be found at KaM Remake project wiki: https://code.google.com/p/castlesand/wi ... ptsDynamic

Events:
|| Version || Event || Description || Parameters and types ||
|| 5882
|| `OnHouseDamaged`
|| Occurs when a house is damaged by the enemy soldier. If AttackerIndex is -1 the house was damaged some other way, such as from Actions.HouseDamage.
|| aHouseID: Integer; //House that is damaged <br> aAttackerIndex: Integer; //UnitID of attacker
||
|| 5871
|| `OnHousePlanPlaced`
|| Occurs when player has placed a house plan
|| aPlayerIndex: Integer; //Player who placed it <br> X: Integer; //X coordinate of the plan <br> Y: Integer; //Y coordinate of the plan <br> aHouseType: Integer; //Type of house of the plan
||
|| 5884
|| `OnUnitWounded`
|| Happens when unit is wounded. Attacker can be a warrior, recruit in tower or unknown (-1)
|| aUnitID: Integer; //UnitID who was wounded <br> AttackerID who attacked the unit
||

Actions:
|| Version || Action || Description || Parameters (Integer) || Return value ()
||
|| 5778
|| `AIEquipRate`
|| Sets the warriors equipment rate for AI. (type: 0 - leather, 1 - iron)
|| 1 - player index <br> 2 - type <br> 2 - rate
||
|| 5777
|| `FogCoverRect`
|| Covers a rectangular area in fog of war for player
|| 1 - player index <br> 2 - from X <br> 3 - from Y <br> 4 - to X <br> 5 - to Y
||
|| 5777
|| `FogRevealRect`
|| Reveals a rectangular area in fog of war for player
|| 1 - player index <br> 2 - from X <br> 3 - from Y <br> 4 - to X <br> 5 - to Y
||

P.S. Sorry about formatting, this is almost straight c/p from the wiki code.

Re: New scripts since r5503

PostPosted: 02 Oct 2013, 09:04
by sado1
|| 5871
|| `OnHousePlanPlaced`
|| Occurs when player has placed a house plan
|| aPlayerIndex: Integer; //Player who placed it <br> X: Integer; //X coordinate of the plan <br> Y: Integer; //Y coordinate of the plan <br> aHouseType: Integer; //Type of house of the plan
How about a version for at least the road plans? (and maybe fields/wineyards as well?) Pleeeeeeaaase :)

Re: New scripts since r5503

PostPosted: 02 Oct 2013, 10:29
by Krom
@sado1: I think this will be the next script event I'm going to implement :)

Re: New scripts since r5503

PostPosted: 02 Oct 2013, 15:46
by Ben
Yes! OnHousePlanPlaced is implemented :D Time for limiting the number of towers people can build;)

Re: New scripts since r5503

PostPosted: 02 Oct 2013, 16:16
by sado1
To is probably the happiest man on Earth right now

Re: New scripts since r5503

PostPosted: 02 Oct 2013, 16:46
by Ben
And Borris is the saddest :D

Re: New scripts since r5503

PostPosted: 20 Nov 2013, 19:07
by andreus
I just inform that more scripts are implemented:

5924 Actions.AIAutoBuild(aPlayer: Byte, aAuto: Boolean)
5924 Actions.AIAutoDefence(aPlayer: Byte; aAuto: Boolean)
5924 Actions.AIRecruitsDelay(aPlayer: Byte, aDelay: Integer)
5924 Actions.AISerfsFactor(aPlayer, aLimit: Byte)
5924 Actions.AIWorkersLimit(aPlayer, aLimit: Byte)
5927 States.PlayerIsAI(aPlayer: Byte): Boolean - returns true if certain player is AI
5927 Actions.RemoveField(X, Y: Word) - works only for winefields now.
5927 Actions.RemoveRoad(X, Y: Word)
5932 Actions.AIAutoRepair(aPlayer: Byte; aAuto: Boolean)
5932 Actions.AISoldiersLimit(aPlayer: Byte; aLimit: Integer)
5932 Actions.AIDefensePositionAdd(aPlayer: Byte; X: Integer; Y: Integer; aDir: Byte; aGroupType: Byte; aRadius: Word; aDefType: Byte) - adds new AI defence position
5932 States.GroupType(aGroupID: Integer) - returns type of certain group (melee, ranged...)
5934 States.HouseCanReachResources(aHouseID: Integer): Boolean
5934 Actions.AIGroupsFormationSet(aPlayer, aType: Byte; aCount, aColumns: Word)
5934 Actions.GroupHungerSet(aGroupID, aHungerLevel: Integer) - someone was dreaming of it? :P
5934 Actions.GroupKillAll(aGroupID: Integer; aSilent: Boolean) - someone was dreaming of it? :P
5934 Actions.PlayerCenterScreenSet(aPlayer: Byte; X, Y: Integer) - hmmm... it's only beginning I think :P

59** States.ClosestHouse(aPlayer, X, Y: Integer): Integer
59** States.ClosestGroup(aPlayer, X, Y: Integer): Integer
59** States.ClosestUnit(aPlayer, X, Y: Integer): Integer
59** Actions.GroupOrderAttackGroup(aID1, aID2: Integer)
59** States.HouseOccupant(aHouseID: Integer): Integer - returns unit type which works in cretain house. Imagine script like this:
  Code:
H := States.PlayerGetAllHouses(0); for I := 0 to length(H) - 1 do Actions.GiveUnit(0, States.HouseOccupant(H[I]), States.HousepositionX(H[I]), 1 + States.HousepositionY(H[I]), 5); end;
Much easier than placing every unit...

Any comments? :)

Re: New scripts since r5503

PostPosted: 20 Nov 2013, 22:32
by RandomLyrics
OnHouseDamaged - can you add - aDamageTaken: integer ?
andreus - great scripts - it will reduce the length of our codes :)
States.ClosestEnemyHouse , States.ClosestEnemyGroup , States.ClosestEnemyUnit - will be awesome :)

Re: New scripts since r5503

PostPosted: 27 Nov 2013, 08:52
by andreus
States.ClosestEnemyHouse , States.ClosestEnemyGroup , States.ClosestEnemyUnit - will be awesome :)
Implemented in new nightly build ;)

Re: New scripts since r5503

PostPosted: 27 Nov 2013, 14:28
by RandomLyrics
Thanks!! :D its very usefull for AI scripting ;) its already implemted in r5961 ? i dont see it anywhere ;p

Re: New scripts since r5503

PostPosted: 27 Nov 2013, 17:15
by andreus
Yes, it's implemented in r5961.

5938 Actions.CinematicStart(aPlayer: Byte);
5938 Actions.CinematicEnd(aPlayer: Byte);
5938 Actions.CinematicPanTo(aPlayer: Byte; X, Y, Duration: Word);
5943 States.ClosestGroup(aPlayer, X, Y: Integer): Integer
5943 States.ClosestHouse(aPlayer, X, Y: Integer): Integer
5943 States.ClosestUnit(aPlayer, X, Y: Integer): Integer
5943 States.HouseOccupant(aHouseID: Integer): Integer

Re: New scripts since r5503

PostPosted: 27 Nov 2013, 17:23
by RandomLyrics
I need the oposite(not player unit but enemy of player) of ClosestGroup for AI , it gives you closest enemy group it looks kinda like this:
  Code:
//CLOSEST ENEMY GROUP TO ATTACK function ClosestEnemyGroup(aPlayer, X, Y, radius:Integer): Integer; var Groups: array of Integer; i, j, BestDistanceSqr, ThisDistanceSqr, DX, DY, fUnit: Integer; begin Result := -1; for j := 0 to MAX_PLAYERS-1 do begin if (States.PlayerEnabled(j) = true) and (States.PlayerDefeated(j) = false) and (j <> aPlayer) then begin if( States.PlayerAllianceCheck(aPlayer, j) <> true ) then begin Groups := States.PlayerGetAllGroups(j); for i := 0 to Length(Groups) -1 do begin fUnit:=States.GroupMember(Groups[i], 0); DX := X - States.UnitPositionX(fUnit); DY := Y - States.UnitPositionY(fUnit); ThisDistanceSqr := (DX*DX) + (DY*DY); if ((Abs(DX)<radius) and (Abs(DY)<radius)) and ((Result = -1) or (ThisDistanceSqr < BestDistanceSqr)) then begin BestDistanceSqr := ThisDistanceSqr; Result := Groups[i]; end; //end; end; end; end; end; end;

Re: New scripts since r5503

PostPosted: 28 Nov 2013, 02:42
by Lewin
I need the oposite(not player unit but enemy of player) of ClosestGroup for AI , it gives you closest enemy group it looks kinda like this:
I don't think we should add script commands to cover every possible case of getting the closest thing. It was already possible to write your own GetClosestUnit (like you did in your previous post for groups), however that can have performance issues since there can be a lot of units to check and dynamic scripts are slower than native executable code. So it makes sense for us to write GetClosestUnit/House/Group because the code will run much faster when implemented as a command rather than your own function in a dynamic script (and it's a fairly common thing to want to query).

However, I don't think we need to implement GetClosest[Enemy/Ally][Group/Unit/House] because it can be implemented like you did in your "ClosestEnemyGroup" function, but using States.GetClosestGroup instead of States.PlayerGetAllGroups. That way you only need to loop and check at most 7 different groups (if you have 7 enemies) so it won't be slow to run.

Re: New scripts since r5503

PostPosted: 28 Nov 2013, 03:06
by RandomLyrics
I need the oposite(not player unit but enemy of player) of ClosestGroup for AI , it gives you closest enemy group it looks kinda like this:
I don't think we should add script commands to cover every possible case of getting the closest thing. It was already possible to write your own GetClosestUnit (like you did in your previous post for groups), however that can have performance issues since there can be a lot of units to check and dynamic scripts are slower than native executable code. So it makes sense for us to write GetClosestUnit/House/Group because the code will run much faster when implemented as a command rather than your own function in a dynamic script (and it's a fairly common thing to want to query)
yea, i was thinking about that, for 500 groups for exmaple, you have to do a looooot of this things - and for now its realy freeze the game for about 1 sec - and im forced to do my script running every 25 sec or 40 sec than 5 or evan 1 for better precizion. I will check it with the newest CloestUnit function. :)

Re: New scripts since r5503

PostPosted: 28 Nov 2013, 03:58
by Lewin
yea, i was thinking about that, for 500 groups for exmaple, you have to do a looooot of this things - and for now its realy freeze the game for about 1 sec - and im forced to do my script running every 25 sec or 40 sec than 5 or evan 1 for better precizion. I will check it with the newest CloestUnit function. :)
If your script freezes the game for one second then it doesn't matter if you run it every 5 seconds or every 50 seconds, it will still cause the game to freeze for 1 second which is very annoying for the player, even if it is less frequent. You'd want to spread the processing out over multiple ticks (storing partial results in global variables), but that's kind of complicated to implement. That's why these Closest* functions were really needed :)