• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help creating a Trigger ?

Status
Not open for further replies.
Level 6
Joined
Feb 16, 2014
Messages
193
How do i do this:
When a player enters a chat string like -reload then it will set the number of charges remaining on an item the player's unit has to 20.How do i do that?:vw_wtf:
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
  • reload
    • Events
      • Player - Player 1 (Red) types a chat message containing -reload as An exact match
    • Conditions
    • Actions
      • Item - Set charges remaining in <your item variable> to 20
 
Level 6
Joined
Feb 16, 2014
Messages
193
Here's the trigger i did(it didnt work)

  • Reload Gun
    • Events
      • Player - Player 1 (Red) types a chat message containing reload as An exact match
    • Conditions
    • Actions
      • Set Unit = (Triggering unit)
      • Item - Set charges remaining in (Item carried by Unit of type Railgun) to 0
      • Wait 3.00 seconds
      • Item - Set charges remaining in (Item carried by Unit of type Railgun) to 15
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
You are setting Unit = (Triggering Unit). There is no triggering unit in this trigger. Also mind that setting charges to 0 will mean unlimited charges.
 
Level 6
Joined
Feb 16, 2014
Messages
193
Um maybe this...
  • Reload Railgun
    • Events
      • Player - Player 1 (Red) types a chat message containing -reload as An exact match
    • Conditions
    • Actions
      • Item - Set charges remaining in (Item being manipulated) to 16
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
The following is not meant rude but it seems to me you don't know too much about triggers :)?

The easiest way to achieve what you want should be

-if you create the item by triggers:
create an item variable by pressing "Ctrl + B" in the trigger editor and then when you create the item by trigger assign the variable to it and in your Reload Railgun trigger select "(Item being manipulated)" and choose your variable in the window.


-if you placed the item in the editor by hand:
click on "(Item being manipulated)" in the last trigger you posted and then in the new window click on "Select an Item" and select it directly in the editor.


If you have further questions go ahead and ask.
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
Here's the trigger i did(it didnt work)

  • Reload Gun
    • Events
      • Player - Player 1 (Red) types a chat message containing reload as An exact match
    • Conditions
    • Actions
      • Set Unit = (Triggering unit)
      • Item - Set charges remaining in (Item carried by Unit of type Railgun) to 0
      • Wait 3.00 seconds
      • Item - Set charges remaining in (Item carried by Unit of type Railgun) to 15

Set variable Unit to your unit, not (Triggering Unit). It should work. ^)^

@NestahHolic
 
Level 6
Joined
Feb 16, 2014
Messages
193
I FINALLY figured it out(And it worked :D )
Heres what i did:
  • Reload PGM I
    • Events
      • Player - Player 1 (Red) types a chat message containing reloadpgm1 as An exact match
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by (Triggering player)) and do (Actions)
        • Loop - Actions
          • Game - Display to (All players matching ((Owner of (Triggering unit)) Equal to (Triggering player))) the text: PG Mark I reloaded....
          • Item - Set charges remaining in (Item carried by (Picked unit) of type PG Mark I) to 16
But also thx,u guys also helped me figure it out.THX guys :D
 
  • Game - Display to (All players matching ((Owner of (Triggering unit)) Equal to (Triggering player))) the text: PG Mark I reloaded....
^It's only a message, but it has to be "Owner of (PickedUnit)" not "(Owner of (Triggering unit)".

If you put your heroes/units into unit[array] variable, you would not need any group creation at all, as you directly could do this:
  • Item - Set charges remaining in (Item carried by Hero[PlayerNumber Of TriggeringPlayer] of type PG Mark I) to 16
(Or can a player have multiple units of this unit type?)

You have a group leak at the moment. Leaks should be removed: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
(Anyway you probably don't really need this group creation as mentioned above)
 
Level 6
Joined
Feb 16, 2014
Messages
193
  • Game - Display to (All players matching ((Owner of (Triggering unit)) Equal to (Triggering player))) the text: PG Mark I reloaded....
^It's only a message, but it has to be "Owner of (PickedUnit)" not "(Owner of (Triggering unit)".

If you put your heroes/units into unit[array] variable, you would not need any group creation at all, as you directly could do this:
  • Item - Set charges remaining in (Item carried by Hero[PlayerNumber Of TriggeringPlayer] of type PG Mark I) to 16
(Or can a player have multiple units of this unit type?)

You have a group leak at the moment. Leaks should be removed: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/
(Anyway you probably don't really need this group creation as mentioned above)

Oh ok :D Thx.And,why are leaks bad anyway? will my map become bad if there is a leak?
 
It will increase the memory size if you don't remove leaks.

In general, yes leaks are bad. That's why it's always good practice to code in a clean way and always to remove them.

Seeing it practical, only if you leak very much, you will notice it in game after a while. So it's very important to keep periodic triggers leakfree, which are fired very often.
In contrast to that, triggers that are not fired too often (and don't have 10000 leaks in it^^) are not really a problem.

But anyway it's still always good practicse to keep your code clean, and for example also a requirement for spells/systems on hive. :)
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
And,why are leaks bad anyway? will my map become bad if there is a leak?
Wc3 objects (i.e. handles) use memory and only will deallocate it when being destroyed by the map maker. Look at Things That Leak for a very good overview.
Only a limited amount of memory is available and performance will suffer with an increasing amount. Mind though that only thousands of leaks will really affect performance.

Having a leak means having memory allocated which

a) should no longer be allocated because it will not be used again
b) can't be deallocated because there is no reference to it left


Lets look at an easy example:
  • Unit - Move (Triggering unit) instantly to (Point(0.00, 0.00))
translates to following JASS
JASS:
call SetUnitPositionLoc( GetTriggerUnit(), Location(0, 0) )
The function Location(real x, real y) will return a location, which is a handle occupying memory. It will still be in memory, unaccessible, after the execution of the trigger and therefore be a leak. On the next execution a new location will be created and again sit in memory.
Now imagine this trigger executed once every 0.01 seconds. Thats 100 more leaks per second. After some minutes, you would certainly notice a difference in a frames per second drop resulting in stuttering.

To not let the leak happen, a solution in GUI would be to assign the location to a variable, use it, and then remove it with the correct custom script JASS function, like this:
  • Set myLocation = (Point(0.00, 0.00))
  • Unit - Move (Triggering unit) instantly to myLocation
  • Custom script: call RemoveLocation(udg_myLocation)
 
Last edited:
Level 6
Joined
Feb 16, 2014
Messages
193
Now i understand :)
Will my trigger not leak now?
  • Reload PGM I
    • Events
      • Player - Player 1 (Red) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 2 (Blue) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 3 (Teal) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 4 (Purple) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 5 (Yellow) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 6 (Orange) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 7 (Green) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 8 (Pink) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 9 (Gray) types a chat message containing reloadpgm1 as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing reloadpgm1 as An exact match
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units owned by (Triggering player)) and do (Actions)
        • Loop - Actions
          • Game - Display to (All players matching ((Owner of (Picked unit)) Equal to (Triggering player))) the text: PG Mark I reloaded....
          • Item - Set charges remaining in (Item carried by (Picked unit) of type PG Mark I) to 16
 
Level 6
Joined
Feb 16, 2014
Messages
193
In your Game - Display message you leak a player group. But as this was only for test I guess (if you remove it), you don't leak anymore.
Um its not a test,I'm using that on my map right now :ogre_haosis: so, now i have a player group leak? how to fix it?
 
Oops, then we have to change it. :D

We could solve this problem with creating a tmpPlayerForce each time, show our text to this Force, and then destroy the Force afterwerds.

But I would prefer another way here, as you might see already, the tmpForce will always be the exactly same for one player. So I would create a global force variable and never destroy them:

Init - trigger:
  • Set Force[1] = PlayerGroup - Player 1
  • Set Force[2] = PlayerGroup - Player 2
  • Set Force[3] = PlayerGroup - Player 3
  • ...
  • Set Force[12] = PlayerGroup - Player 12
Force[array] is a player group variabled with array ticked.
In this trigger you only initialisize the variables.

Usage - Example:
  • Events
    • Player - Player 1 (Red) types a chat message containing reloadpgm1 as An exact match
    • Player - Player 2 (Blue) types a chat message containing reloadpgm1 as An exact match
    • Player - Player 3 (Teal) types a chat message containing reloadpgm1 as An exact match
    • ...
    • Player - Player 10 (Light Blue) types a chat message containing reloadpgm1 as An exact match
  • Conditions
  • Actions
    • Game - Display to Force[PlayerNumberOfTriggeringPlayer] the text: PG Mark I reloaded....
So you can see here, with just use the "Player Number Of Triggering Player" as index to show the text to the correct Force. No need to create/destroy tmp player forces anymore.
And no leak as you can use these forces over and over again in any trigger.
 
Level 6
Joined
Feb 16, 2014
Messages
193
But i have another question though,how to do this:
When a player presses the "A" button in there keyboard then it will make there unit walk left.How do i do that?
 
Status
Not open for further replies.
Top