Page 1 of 1

OnHouseAfterDestroyed

PostPosted: 02 Aug 2014, 20:29
by gold1
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'.

Re: OnHouseAfterDestroyed

PostPosted: 02 Aug 2014, 21:22
by The Dark Lord
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;

Re: OnHouseAfterDestroyed

PostPosted: 03 Aug 2014, 08:37
by Duke Valennius
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.

Re: OnHouseAfterDestroyed

PostPosted: 03 Aug 2014, 08:58
by The Dark Lord
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. :)

Re: OnHouseAfterDestroyed

PostPosted: 30 Aug 2014, 11:59
by gold1
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

Re: OnHouseAfterDestroyed

PostPosted: 30 Aug 2014, 16:17
by Duke Valennius
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)

Re: OnHouseAfterDestroyed

PostPosted: 30 Aug 2014, 21:02
by Guest
oke got i now. and thx for the fast response.
but how can i find what the houseId is?

Re: OnHouseAfterDestroyed

PostPosted: 31 Aug 2014, 03:04
by Lewin
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.

Re: OnHouseAfterDestroyed

PostPosted: 31 Aug 2014, 11:32
by gold1
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).

Re: OnHouseAfterDestroyed

PostPosted: 31 Aug 2014, 13:47
by Lewin
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?