Map Database  •  FAQ  •  RSS  •  Register  •  Login

Copying script

<<

JulianSnow2

Woodcutter

Posts: 17

Joined: 09 Jan 2018, 11:23

Post 10 Jan 2018, 11:42

Copying script

Good afternoon,

I've had some trouble with copying scripts. Since i'm not the brightest among script-writers I mostly just copy them from existing maps to my own (A).
Yesterday I tried to copy the auto recruit script for the schoolhouse from a map made by 'Toxic' (LLL forgotten kingdoms, something like that) and copied to another map which I made from 'Abrak'.

But the script doesn't seem to catch on, is there something that locks a script to a specific map ?
I couldn't find it in my Notepad++ and as I wrote above I'm not the best scripter so I find reading the code kind of hard.

What i'm trying to achieve is to modify a few standard maps to play with friends that only include the auto-recruit script
<<

grayter

Axe Fighter

Posts: 77

Joined: 18 Aug 2014, 12:06

Location: Poland

KaM Skill Level: Skilled

Post 10 Jan 2018, 15:39

Re: Copying script

please attach map with script I'll check thia
<<

JulianSnow2

Woodcutter

Posts: 17

Joined: 09 Jan 2018, 11:23

Post 11 Jan 2018, 11:19

Re: Copying script

I'll attach the script and map this evening.
<<

JulianSnow2

Woodcutter

Posts: 17

Joined: 09 Jan 2018, 11:23

Post 11 Jan 2018, 18:09

Re: Copying script

The map / script I was using is from this map: A Secret Zone LLL V 3.8_53A52C71

The script says this:


// Toxic's scripts
// DECLARATION:
type aBuildings = record
Schools: array of Integer;
Markets: array of Integer;
end;
type aPLAYER = record
Buildings: aBuildings;
TowersCount: Byte;
end;
var PLAYER: array of aPLAYER;
const TOWERSLIMIT = 5;

// SCHOOLHOUSE
procedure Recruits(var aPlayer: Integer);
var i: Integer;
begin
for i := 0 to Length(PLAYER[aPlayer].Buildings.Schools)-1 do
if States.HouseRepair(PLAYER[aPlayer].Buildings.Schools[i]) and (States.HouseResourceAmount(PLAYER[aPlayer].Buildings.Schools[i], 7) > 0) and (States.HouseSchoolQueue(PLAYER[aPlayer].Buildings.Schools[i], 0) = - 1) then
Actions.HouseSchoolQueueAdd(PLAYER[aPlayer].Buildings.Schools[i], 13, 1);
end;

procedure AddHouse(aHouse: Integer; var Houses: array of Integer);
begin
SetLength(Houses, Length(Houses)+1);
Houses[High(Houses)] := aHouse;
end;

procedure RemoveHouse(aHouse: Integer; var Houses: array of Integer);
var i: Integer;
begin
for i := 0 to Length(Houses)-1 do if (Houses[i] = aHouse) then break;
Houses[i] := Houses[High(Houses)];
SetLength(Houses, Length(Houses)-1);
end;

// CARAVAN


There is more after this, but the caravan script doesn't interest me much. The script I had used in my try with the basic map "Abrak" was this:

type aBuildings = record
Schools: array of Integer;
end;
type aPLAYER = record
Buildings: aBuildings;

end;
var PLAYER: array of aPLAYER;

// SCHOOLHOUSE
procedure Recruits(var aPlayer: Integer);
var i: Integer;
begin
for i := 0 to Length(PLAYER[aPlayer].Buildings.Schools)-1 do
if States.HouseRepair(PLAYER[aPlayer].Buildings.Schools[i]) and (States.HouseResourceAmount(PLAYER[aPlayer].Buildings.Schools[i], 7) > 0) and (States.HouseSchoolQueue(PLAYER[aPlayer].Buildings.Schools[i], 0) = - 1) then
Actions.HouseSchoolQueueAdd(PLAYER[aPlayer].Buildings.Schools[i], 13, 1);
end;

procedure AddHouse(aHouse: Integer; var Houses: array of Integer);
begin
SetLength(Houses, Length(Houses)+1);
Houses[High(Houses)] := aHouse;
end;

procedure RemoveHouse(aHouse: Integer; var Houses: array of Integer);
var i: Integer;
begin
for i := 0 to Length(Houses)-1 do if (Houses[i] = aHouse) then break;
Houses[i] := Houses[High(Houses)];
SetLength(Houses, Length(Houses)-1);
end;


Did delete some of the lines, since I don't think there should be a specific tower limit.

How is it that the script does not work on the Abrak map but does on the "secret zone" map ?
You do not have the required permissions to view the files attached to this post.
<<

grayter

Axe Fighter

Posts: 77

Joined: 18 Aug 2014, 12:06

Location: Poland

KaM Skill Level: Skilled

Post 11 Jan 2018, 19:05

Re: Copying script

You have not declared Events section. You wrote code but this code is unused. If you want to get list of schools for your script you need to register each school when it's build in OnHouseBuild method like this:

procedure OnHouseBuilt(aHouse: Integer);
begin
if not States.PlayerIsAI(States.HouseOwner(aHouse)) then begin
//code below adds school to list you use later in your procedures
if States.HouseType(aHouse) = 13 then AddHouse(aHouse, PLAYER[States.HouseOwner(aHouse)].Buildings.Schools);
end;
end;

You need to handle other events as well.
<<

Rey

User avatar

KaM Remake Developer

Posts: 204

Joined: 12 Oct 2016, 07:41

Location: Moscow

KaM Skill Level: Fair

Post 11 Jan 2018, 19:14

Re: Copying script

Hi.

I tried to adapt Toxic's script (hope he is okay with that...)

Script is not perfect, as its a part of original script with more options (caravan and towers), but its working.

Check it out:
You do not have the required permissions to view the files attached to this post.
<<

thunder

User avatar

Knight

Posts: 983

Joined: 15 Apr 2012, 12:11

Location: In the Market

KaM Skill Level: Fair

Post 11 Jan 2018, 20:08

Re: Copying script

Good map for scripting! Nice Taste :wink:
<<

JulianSnow2

Woodcutter

Posts: 17

Joined: 09 Jan 2018, 11:23

Post 12 Jan 2018, 11:43

Re: Copying script

After reading Rey's script file, I get that I forgot a few scripting commands. Question still stands, why did the same script work on the secret zone map, and not on the abrak map. <-- doesn't matter at this point.

Althought I don't understand some of the scripting commands, or more the build of the command references (i.e. what does 'integer' mean ?, or the line '0 to Lenght(PLAYER[aPlayer].Buildings.Schools)-1'), I like reading the file and recognizing the reference points to the in game locations (or buttons/actions etc.).

Thank you for helping me out. Shall try it this evening after the cinema (gonna watch the new Jumanji with the lady first).
<<

thunder

User avatar

Knight

Posts: 983

Joined: 15 Apr 2012, 12:11

Location: In the Market

KaM Skill Level: Fair

Post 12 Jan 2018, 12:09

Re: Copying script

why did the same script work on the secret zone map, and not on the abrak map.

I'm sorry, I don't want to bagatelle the scripting problems, but maybe don't know but Abrak was originally draw as a smokey, cloudy, foggy map with lots of shadows of monster buildings. That map is legendary, the most mistical place on the Earth, and in mind. So if a script is not working on it, maybe the script is not enough strong or good to be for that map.
Beilive me, that map predicted the future. Anything can happen on it. Trust me. The map maybe manipulate your script or mixing the chars of it. Hard to tell what is happening there.
Check this picture form the past (almost 6years oldone).
Have a good day! :P
I
I
I
V
2013.JPG
You do not have the required permissions to view the files attached to this post.
<<

Toxic

Rogue

Posts: 50

Joined: 22 Feb 2017, 19:04

Post 12 Jan 2018, 15:31

Re: Copying script

Hi
I am not here every day but sometimes I read something so here it is:

JulianSnow2 wrote:But the script doesn't seem to catch on, is there something that locks a script to a specific map ?

No, there is no restriction in script usage. However, some scripts are made for specific map and when you try to copy them they will not work. But this is not case of Caravan / Statistic / Schoolhouse scripts.

Rey wrote:I tried to adapt Toxic's script (hope he is okay with that...)

Nice code ... looks like you has written something before :P :P :P

JulianSnow2 wrote:Question still stands, why did the same script work on the secret zone map, and not on the abrak map.

I copied script from Secret zone into Abrak and everything works. Your uploaded map have modification of my script and maybe that is why it does not work.

JulianSnow2 wrote:i.e. what does 'integer' mean ?

Integer means integer (1; 4; 9; 24342). The second type are floating point numbers (1.234; 3.342; 234.12314).

JulianSnow2 wrote: (or the line '0 to Lenght(PLAYER[aPlayer].Buildings.Schools)-1')

The right question is what does mean the whole line:
  Code:
for Variable := 0 to Lenght(PLAYER[aPlayer].Buildings.Schools) - 1 do

It is cycle. Please read this page.

thunder wrote:... maybe the script is not enough strong or good to be for that map

I am crazy. You dont want start something with me, my family or my code. :mad:

Return to Dynamic Scripting

Who is online

Users browsing this forum: No registered users and 2 guests