Map Database  •  FAQ  •  RSS  •  Login

Problem with script

<<

XxXTheProMatiXxX

Serf

Posts: 5

Joined: 05 Aug 2013, 13:19

KaM Skill Level: Skilled

Post 31 Mar 2018, 13:08

Problem with script

Hey

I tried in a lot of ways to add a building but script didn't work.I don't know why. Can someone help me with it?
I used to do it with procedure onHouseDamaged,onUnitDied,onUnitAfterdied but result was the same.At least with this one i don't have any errors but after destroying storehouse(by soldiers,not script),nothing happens.
  Code:
procedure OnHouseDestroyed(aHouse : Integer; aHouseOwnerIndex : Integer); begin If (States.HousePositionX(aHouse) = 103) AND (States.HousePositionY(aHouse) = 26) then begin Actions.GiveHouse (1,11,84,42) end; end;
At start wanted to give player after killing enemy troops(procedure onUnitDied,onUnitAfterdied) his storehouse but errors forced me to try do it in other way...
What is important i'm just starting to write scripts. This is my third attempt to understand this, so every tip is welcome.To be honest i'm not a native speaker of English so I apologize for all the mistakes.
<<

Strangelove

User avatar

Crossbowman

Posts: 230

Joined: 30 Jul 2013, 06:32

KaM Skill Level: Fair

Post 31 Mar 2018, 15:22

Re: Problem with script

Hi,

I do not quite understand what you wanna do, but if you want to debug a script you might want to check out IF a Logfile was created in your Mapfolder and what it contains. It usually gives you a good idea on what you did wrong.
As far as I can see, you are missing a semicolon at the end of "Actions.GiveHouse". Like i said, I am not quite sure what you want to do, but it should prolly work with the semicolon.

Best regards,
Strange
<<

XxXTheProMatiXxX

Serf

Posts: 5

Joined: 05 Aug 2013, 13:19

KaM Skill Level: Skilled

Post 31 Mar 2018, 17:03

Re: Problem with script

Thanks for a reply!
Semicolon doesn't change the result. The main idea was that after killing enemy units we capture enemy storehouse. As i'm bad at scripts i can't use correctly procedure onUnitAfterdied or onUnitDied to destroy enemy storage and replace it with new after killing enemy troops. So i tried to use procedure OnHouseDestroyed.After destroying house at X,Y there should appear new one but it didn't.
<<

Strangelove

User avatar

Crossbowman

Posts: 230

Joined: 30 Jul 2013, 06:32

KaM Skill Level: Fair

Post 01 Apr 2018, 09:40

Re: Problem with script

Do you get any errors, or does the game create a *.log -file in the mapfolder?
I assume that you already noticed that there was no Actions to replace or transfer control of houses or troops from one player to another, so you tryed adding it again after its destroyed. Is that correct?
Usually i'd say it's not possible to "replace" a house like that, because the old house has to be removed, before you can put a new house on the old houses locations. However, the coordinates for the houses you've used a different from each other. I can't really see the problem with the lines of codes you've presented here.

Make sure you check the fallowing:
1. Are all those players active? Player 1 in the MapEditor is Player 0 in script f.e.
2. Are the coordinates correct? For old and new house.
3. Maybe there is an unbuildable object at the spot of the storehouse you wanna place
4. Does the procedure even trigger? Maybe try giving out a message with "Actions.ShowMsg(-1, 'House should have been placed...');", like so:
  Code:
procedure OnHouseDestroyed(aHouse : Integer; aHouseOwnerIndex : Integer); begin Actions.ShowMsg(-1, 'A House was destroyed!'); If (States.HousePositionX(aHouse) = 103) AND (States.HousePositionY(aHouse) = 26) then begin Actions.GiveHouse(1,11,84,42); Actions.ShowMsg(-1, 'House should have been placed...'); end; end;
5. I'd modify the script to something like that: (It's a neater way of doing it; dont have to check for each Coordinate seperatly)
  Code:
procedure OnHouseDestroyed(aHouse: Integer; aHouseOwnerIndex: Integer); begin if States.HouseAt(103, 26) = aHouse then Actions.GiveHouse(1, 11, 84, 42); end;
Hope that helps! And btw, please join us on discord (https://discord.gg/erSvW5G). Troubleshooting scripts here is quite difficult^^

Best regards,
Strange
<<

memerion2

User avatar

Blacksmith

Posts: 28

Joined: 07 Aug 2017, 16:22

KaM Skill Level: Skilled

Location: Poland

Post 07 Apr 2018, 06:54

Re: Problem with script

I Think IT will be easier with
If States.GroupDead(group id) = true then begin
Actions.HouseDestroy((house id),true);
Actions.GiveHouse(aplayer,ahousetype,ax,ay);
end;


I think I wrote well

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 7 guests