Map Database  •  FAQ  •  RSS  •  Login

OnHouseAfterDestroyed

<<

gold1

Blacksmith

Posts: 26

Joined: 05 Jan 2014, 20:24

KaM Skill Level: Average

Post 02 Aug 2014, 20:29

OnHouseAfterDestroyed

hey i'm stil making the script for volcano vally coop(yet not sure to publish it).

but i found out that when i wanted to give player 1 units after a watchtower was destroyed. the script works fine except it keep giveing the units over and over again since the building is still destroyed.

How can i make sure they get the units only once?
  Code:
procedure ontick; begin begin if states.gametime = 10 then actions.showmsg(2,'Orginal map by hell raccer.|Edited and scripted for coop by Gold1') end; if States.OnHouseDestroyed(States.HouseAt(95,37)) = true then begin actions.givegroup(9,14,56,21,4,12,4) end; end;
edit: thx for the fast response and the good answer. however if i start the game i get the message: unkown identifier 'ONHOUSEDESTROYED'.
Last edited by gold1 on 02 Aug 2014, 21:50, edited 1 time in total.
<<

The Dark Lord

User avatar

King Karolus Servant

Posts: 2154

Joined: 29 Aug 2007, 22:00

KaM Skill Level: Veteran

Location: In his dark thunderstormy castle

Post 02 Aug 2014, 21:22

Re: OnHouseAfterDestroyed

You could use a boolean. For example:
  Code:
procedure OnTick; begin if States.GameTime = 10 then begin Actions.Showmsg(2, 'Orginal map by Hellracer.|Edited and scripted for coop by Gold1'); end; if (States.OnHouseDestroyed(States.HouseAt(95, 37)) = true) and (TroopsGiven = false) then begin Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4); TroopsGiven := true; end; end;
<<

Duke Valennius

User avatar

Militia

Posts: 44

Joined: 10 Jul 2013, 11:01

KaM Skill Level: Average

Post 03 Aug 2014, 08:37

Re: OnHouseAfterDestroyed

OnHouseDestroyed and others beginning with "On..." are events (https://code.google.com/p/castlesand/wi ... ptsDynamic)
You use it like this:
  Code:
procedure OnHouseDestroyed(aHouseID : Integer; aDestroyerIndex : Integer); begin // do what you want when this house with ID "aHouseID" is destroyed end;
This procedure gets called when some house is destroyed. You can ask if that "aHouseID" is a house you are looking for and if it is, give units (or whatever you like). This will happen only once, since the same house won't be destroyed more then once.
Last edited by Duke Valennius on 30 Aug 2014, 16:06, edited 1 time in total.
<<

The Dark Lord

User avatar

King Karolus Servant

Posts: 2154

Joined: 29 Aug 2007, 22:00

KaM Skill Level: Veteran

Location: In his dark thunderstormy castle

Post 03 Aug 2014, 08:58

Re: OnHouseAfterDestroyed

Ow oops, I assumed you were using OnHouseAfterDestroyed correctly but seeing 'On-' before it I should have known better. :P Sorry for my false help. However, it might still be useful whenever you want something else on OnTick only happen once. :)
<<

gold1

Blacksmith

Posts: 26

Joined: 05 Jan 2014, 20:24

KaM Skill Level: Average

Post 30 Aug 2014, 11:59

Re: OnHouseAfterDestroyed

i treid using the script from Duke Valennius. but somehow i can't seems to get it working.
  Code:
procedure ontick; begin begin if states.gametime = 10 then actions.showmsg(2,'Orginal map by hell raccer.|Edited and scripted for coop by Gold1') end; procedure OnHouseDestroyed(17,0) begin Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4 end; end;
tbh i don't really know what to put in for
  Code:
(aHouseID : Integer; aDestroyerIndex : Integer
<<

Duke Valennius

User avatar

Militia

Posts: 44

Joined: 10 Jul 2013, 11:01

KaM Skill Level: Average

Post 30 Aug 2014, 16:17

Re: OnHouseAfterDestroyed

i treid using the script from Duke Valennius. but somehow i can't seems to get it working.
  Code:
procedure ontick; begin begin if states.gametime = 10 then actions.showmsg(2,'Orginal map by hell raccer.|Edited and scripted for coop by Gold1') end; procedure OnHouseDestroyed(17,0) begin Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4 end; end;
tbh i don't really know what to put in for
  Code:
(aHouseID : Integer; aDestroyerIndex : Integer
Apart from some missing semicolons (I edited my post as it had it missing too). Try it like this:
  Code:
// this procedure gets called every tick procedure OnTick; begin if states.gametime = 10 then actions.showmsg(2,'Orginal map by hell raccer.|Edited and scripted for coop by Gold1') end; // this procedure gets called when house is destroyed // aHouseID is variable, which contains ID of house that has been destroyed, aDestroyerIndex index of player who destroyed it // you do not call this procedure by yourself, it gets called automatically, just like "OnTick procedure OnHouseDestroyed(aHouseID : Integer; aDestroyerIndex : Integer); begin Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4); end;
(Disclaimer: there might be some typos, use at your own peril)
<<

Guest

Post 30 Aug 2014, 21:02

Re: OnHouseAfterDestroyed

oke got i now. and thx for the fast response.
but how can i find what the houseId is?
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 31 Aug 2014, 03:04

Re: OnHouseAfterDestroyed

oke got i now. and thx for the fast response.
but how can i find what the houseId is?
HouseID is a variable so you can compare/use it within the procedure. I think you want something like this:
  Code:
procedure OnHouseDestroyed(aHouseID : Integer; aDestroyerIndex : Integer); begin if (States.HouseType(aHouseID) = 17) and (States.HouseOwner(aHouseID) = 1) then Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4); end;
That means the group will be given whenever a watchtower belonging to player 1 is destroyed.
<<

gold1

Blacksmith

Posts: 26

Joined: 05 Jan 2014, 20:24

KaM Skill Level: Average

Post 31 Aug 2014, 11:32

Re: OnHouseAfterDestroyed

oke got i now. and thx for the fast response.
but how can i find what the houseId is?
HouseID is a variable so you can compare/use it within the procedure. I think you want something like this:
  Code:
procedure OnHouseDestroyed(aHouseID : Integer; aDestroyerIndex : Integer); begin if (States.HouseType(aHouseID) = 17) and (States.HouseOwner(aHouseID) = 1) then Actions.GiveGroup(9, 14, 56, 21, 4, 12, 4); end;
That means the group will be given whenever a watchtower belonging to player 1 is destroyed.

you made a mistake in your script Lewin. but i after modifing your script it finally works:)
  Code:
procedure OnHouseDestroyed(aHouseID : Integer; aHouseOwnerIndex : Integer); begin if (States.HouseType(aHouseID) = 17) and (States.HouseOwner(aHouseID) = 0) then begin Actions.GiveGroup(1, 14, 56, 21, 4, 12, 4); end; end;
in the procedure line you had OnHouseDestroyed and aDestroyerIndex.
while in the if states line you had OnHouseDestroyed and HouseOwner. wich was wrong. i changed aDestroyerIndex for Houseowner and now it works.

thanks for the help so far.

and if i want this only to happen when a building in certain postion in destoyed i must change (states.houseowner(ahouseid) for (states.houseat(10,16).
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 31 Aug 2014, 13:47

Re: OnHouseAfterDestroyed

you made a mistake in your script Lewin. but i after modifing your script it finally works:)
  Code:
procedure OnHouseDestroyed(aHouseID : Integer; aHouseOwnerIndex : Integer); begin if (States.HouseType(aHouseID) = 17) and (States.HouseOwner(aHouseID) = 0) then begin Actions.GiveGroup(1, 14, 56, 21, 4, 12, 4); end; end;
in the procedure line you had OnHouseDestroyed and aDestroyerIndex.
while in the if states line you had OnHouseDestroyed and HouseOwner. wich was wrong. i changed aDestroyerIndex for Houseowner and now it works.

thanks for the help so far.

and if i want this only to happen when a building in certain postion in destoyed i must change (states.houseowner(ahouseid) for (states.houseat(10,16).
No, that is not a mistake. It is correct for OnHouseDestroyed to have aDestroyerIndex as a parameter, check the definition of OnHouseDestroyed here. The function States.HouseOwner is completely unrelated to the procedure parameter aDestroyerIndex. Of course, it doesn't matter what you name those parameters (aHouseID and aDestroyerIndex), the script will run the same if you rename parameters or variables everywhere that they are used. But it's best to give them their correct names otherwise it is confusing.

Do you know any other programming languages? Maybe I can explain these concepts to you in a way which you are more familiar with?

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 11 guests