Map Database  •  FAQ  •  RSS  •  Register  •  Login

Help with script.

<<

Kannietanders

Post 12 Aug 2016, 11:23

Help with script.

Hi to everyone who is reading this,

I am sort of new to this and unfamiliar to the art of scripting, yet I would like a script like the "Bonus", "School house", "Caravan", "Tower limit" (let's try the tower limit first because it seemed the shortest + I don't want to waiste your time ;) ).

I read some of the toturials that where posted here on the forum, but as I mentioned above I am unknown to the art of scripting. Therefor is it possible that anyone could explain to me in little tiny babysteps how to start a script, or even provide me with a small script with meanings to it?
I like to play with the "Bonus" but the maps are always the same and getting quite boring, so I made a few maps myself and thought why not change the script a bit aswell..

So I've tried to changes a few things that didn't work the way I thought it would and suddenly I broke the whole script. This ofcourse doesn't need a rocket scientist to once again notice that I am unskilled in the art of scripting..

For everyone who is willing to help me out, Thanks alot! :3

Sincerly,

Kannietanders.
<<

Esthlos

User avatar

Knight

Posts: 672

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 12 Aug 2016, 19:53

Re: Help with script.

Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

Tiank

User avatar

Knight

Posts: 592

Joined: 15 Sep 2013, 13:11

Location: Poland

KaM Skill Level: Skilled

Post 13 Aug 2016, 08:24

Re: Help with script.

Here's script for tower limit, taken from Valley of Equilibrum (so, script was probably made by andreus).

  Code:
var
  I, K: Integer;
  Counter: array[0..7] of Integer;


procedure OnMissionStart;
begin
  for I := 0 to 7 do
    Counter[I] := 0;
end;


procedure OnHousePlanPlaced(aPlayerIndex, X, Y, aHouseType: Integer);
begin
  if aHouseType = 17 then
    Counter[aPlayerIndex] := Counter[aPlayerIndex] + 1;
  if Counter[aPlayerIndex] > 7 then
  begin
    Actions.PlanRemove(aPlayerIndex, X, Y);
    Counter[aPlayerIndex] := Counter[aPlayerIndex] - 1;
  end;
end;


procedure OnHouseDestroyed(aHouseID, aDestroyerIndex: Integer);
begin
  if States.HouseType(aHouseID) = 17 then
    begin
      K := States.HouseOwner(aHouseID);
      Counter[K] := Counter[K] - 1;
    end;
end;


procedure OnHousePlanRemoved(aPlayerIndex, aX, aY, aHouseType: Integer);
begin
  if aHouseType = 17 then
    begin
      K := aPlayerIndex;
      Counter[K] := Counter[K] - 1;
    end;
end;



Now, you have this part:
  Code:
var
  I, K: Integer;
  Counter: array[0..7] of Integer;


procedure OnMissionStart;
begin
  for I := 0 to 7 do
    Counter[I] := 0;
end;


Now script is set for 8 players' map. You can change that, by changing "7" into something else. If you want it to work for 6 players' map - change it into "5", for 2 players' map - change it into "1".

Example for 6 players' map, that part should be:
  Code:
var
  I, K: Integer;
  Counter: array[0..5] of Integer;


procedure OnMissionStart;
begin
  for I := 0 to 5 do
    Counter[I] := 0;
end;



Now, there's this part:
  Code:
procedure OnHousePlanPlaced(aPlayerIndex, X, Y, aHouseType: Integer);
begin
  if aHouseType = 17 then
    Counter[aPlayerIndex] := Counter[aPlayerIndex] + 1;
  if Counter[aPlayerIndex] > 7 then
  begin
    Actions.PlanRemove(aPlayerIndex, X, Y);
    Counter[aPlayerIndex] := Counter[aPlayerIndex] - 1;
  end;
end;


In line "if Counter[aPlayerIndex] > 7 then", 7 is number of tower limit. To change tower limit, simply change it for something you want.

I'm not a scripter, I just figured it out by trying to apply this script into different maps :) Hope it works!
Without honour, victory is hollow.
<<

Esthlos

User avatar

Knight

Posts: 672

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 13 Aug 2016, 08:52

Re: Help with script.

Wouldn't it be much simplier like this?

  Code:
const
  cTOWER_LIMIT = 8; //Edit this to change the limit

procedure OnHousePlanPlaced(aPlayerIndex, X, Y, aHouseType: Integer);
begin
  if (aHouseType = 17) AND ((States.StatHouseTypeCount(aPlayerIndex, 17)+States.StatHouseTypePlansCount(aPlayerIndex, 17)) > cTOWER_LIMIT) then Actions.PlanRemove(aPlayerIndex, X, Y);
end;


P.S. States.LocationCount returns the max number of players in the map, and SetLength allows you to use that function to set a dynamic array's length :P

  Code:
var
  I, K: Integer;
  Counter: array of Integer;


procedure OnMissionStart;
begin
  SetLength(Counter, States.LocationCount);
  for I := 0 to States.LocationCount-1 do
    Counter[I] := 0;
end;
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

Kannietanders

Post 13 Aug 2016, 09:19

Re: Help with script.

Massive thanks for your help! Deffinitly gonna try this ;)

Return to Dynamic Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron