• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Help with a trigger

Status
Not open for further replies.
Level 2
Joined
Nov 30, 2011
Messages
9
I need help with a trigger... i want to :

If a player types: "-buy sword"
then: create a sword object at position of "Unit" owned by typped player and substract X gold
if a player types "-buy shield"
then: create a shield object at position of "Unit" owned by typped player and substract X gold
if....(the same thing but another item typped)
then...(the same thing creating the specific object) and substract X gold

whats the best way to do this?
 
Level 6
Joined
Jun 16, 2007
Messages
235
Wow a fresh cookie.
1 post and does not even know to register a chat event.

And people say wc3 is dead.
 
Level 2
Joined
Nov 30, 2011
Messages
9
you really didnt understand me ....
try do this with only 1 trigger ( 2 max ) if you can post here how :p
 
Level 6
Joined
Jun 16, 2007
Messages
235
You need two arrays, one for item names, one for item types:

"Sword", "Sheild", "Boots"
I001, I002, I003

Than when someone types -buy something
you search for something in array of names, and if you find the name at array index 7 for example, you give him item 7

Probably need one more array for gold if your prices are not the same for all items.
 
Level 6
Joined
Jun 16, 2007
Messages
235
Consider using a hashtable to map with better efficiency using the hash of the strings.

Not really a problem if you only doing it for like 5 items but does start to count with 30+.
Omg are you serious?
A hashtable for user typing trigger that does a simple array search?
Even if he had 8192 items it would not matter.

Another imaginary optimization junkie....
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
A hashtable for user typing trigger that does a simple array search?
Even if he had 8192 items it would not matter.
8192 items will cause a linear search routine to hit the op limit unless you start new threads.

A single hashtable lookup would likly evaluate faster for 8192 items than checking a 1-2 elements via linear search of the 8192 items. Even if the hashtable is poorly configured so ends up with a high collision density it will still perform better than a linear search due to it running native code instead of JASS interpreted instructions.
 
Level 6
Joined
Jun 16, 2007
Messages
235
OP limit is 300000. (five zeros)

Besides if op limit was just 200 it would still all be imaginary optimization talk because no one will ever make even 100 items for this.
(Because people would have to remember 100 item names to type)

Now stop arguing and just admit to yourself that you suffer from BJism.
 
Level 2
Joined
Nov 30, 2011
Messages
9
i tried to do it ... and no... i didnt got it xD

someone can upload a photo showing how to do it please?


edit: i'm using 18 items
 
Level 9
Joined
Oct 17, 2009
Messages
370
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -buy as A substring
      • Player - Player 2 (Blue) types a chat message containing -buy as A substring
      • Player - Player 3 (Teal) types a chat message containing -buy as A substring
      • Player - Player 4 (Purple) types a chat message containing -buy as A substring
      • ----- Add as many players that you need here -----
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to sword
          • ((Triggering player) Current gold) Greater than or equal to 500
        • Then - Actions
          • Hero - Create Sword and give it to ("The hero that should have the item")
          • Player - Add -500 to (Triggering player) Current gold
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to bow
              • ((Triggering player) Current gold) Greater than or equal to 500
            • Then - Actions
              • Hero - Create Bow and give it to ("The hero that should have the item")
              • Player - Add -500 to (Triggering player) Current gold
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to shield
                  • ((Triggering player) Current gold) Greater than or equal to 500
                • Then - Actions
                  • Hero - Create Shield and give it to ("The hero that should have the item")
                  • Player - Add -500 to (Triggering player) Current gold
                • Else - Actions
Use this if you dont have that many items, cus making like 20 items in this is NOT FUNNY...

Edit: Hmm, i posted this just before you edited your last post LOL, well 18 items in this is possible but i dont recommend it xD
 
Are you sure you want to create that, it will be pain in the ass to remember 22 items and to actually write that each time when you want to buy something.

Better create custom interface and when player write -buy show it to him with all items presented, when he click on icon, item can be sold to him, if he has enough gold/lumber or even some other custom resource.
 

Attachments

  • 2.JPG
    2.JPG
    181.3 KB · Views: 63
  • Capture.JPG
    Capture.JPG
    189.5 KB · Views: 83
Level 11
Joined
Nov 15, 2007
Messages
800
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -buy as A substring
      • Player - Player 2 (Blue) types a chat message containing -buy as A substring
      • Player - Player 3 (Teal) types a chat message containing -buy as A substring
      • Player - Player 4 (Purple) types a chat message containing -buy as A substring
      • ----- Add as many players that you need here -----
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to sword
          • ((Triggering player) Current gold) Greater than or equal to 500
        • Then - Actions
          • Hero - Create Sword and give it to ("The hero that should have the item")
          • Player - Add -500 to (Triggering player) Current gold
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to bow
              • ((Triggering player) Current gold) Greater than or equal to 500
            • Then - Actions
              • Hero - Create Bow and give it to ("The hero that should have the item")
              • Player - Add -500 to (Triggering player) Current gold
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to shield
                  • ((Triggering player) Current gold) Greater than or equal to 500
                • Then - Actions
                  • Hero - Create Shield and give it to ("The hero that should have the item")
                  • Player - Add -500 to (Triggering player) Current gold
                • Else - Actions
Use this if you dont have that many items, cus making like 20 items in this is NOT FUNNY...

Edit: Hmm, i posted this just before you edited your last post LOL, well 18 items in this is possible but i dont recommend it xD

oh god my brain...


  • Hashtable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set items = (Last created hashtable)
      • Item - Create Cheese at (Player 1 (Red) start location)
      • Hashtable - Save Handle Of(Last created item) as (Key cheese) of 0 in items
      • Item - Hide (Last created item)
      • Hashtable - Save 25 as (Key cheese) of 1 in items

  • Buy
    • Events
      • Player - Player 1 (Red) types a chat message containing -buy as A substring
    • Conditions
      • (Load (Key (Substring((Entered chat string), 6, (Length of (Entered chat string))))) of 1 from items) Less than or equal to ((Triggering player) Current gold)
    • Actions
      • Item - Create (Item-type of (Load (Key (Substring((Entered chat string), 6, (Length of (Entered chat string))))) of 0 in items)) at (Player 1 (Red) start location)
      • Player - Set (Triggering player) Current gold to (((Triggering player) Current gold) - (Load (Key (Substring((Entered chat string), 6, (Length of (Entered chat string))))) of 1 from items))
P.S. obviously you need to alter a lot of that :wink:

There's probably a more eloquent way to set the items, but this way is at least functional if not stylish. You have to hide the items rather than removing them or else the handle won't work.
 
Level 6
Joined
Jun 16, 2007
Messages
235
...lots of crazy triggers...
oh spagetti monster my brain...

Look people just stop inventing crazy alternatives and someone make it to him with two arrays as I explained early in the thread.
I would do it but I coded GUI so long ago I probably would not know how any more...

@-Kobas-
When you post advice like that, include a link.
 
Level 11
Joined
Nov 15, 2007
Messages
800
oh spagetti monster my brain...

Look people just stop inventing crazy alternatives and someone make it to him with two arrays as I explained early in the thread.
I would do it but I coded GUI so long ago I probably would not know how any more...

I notice you're very good at criticizing and not very good at offering any real help. I'll give you the benefit of the doubt and say you coded GUI "so long ago" that it was before hash tables were added, which are actually a lot easier to use, more versatile, and more efficient than arrays.
 
Level 2
Joined
Nov 30, 2011
Messages
9
its solved. thanks to haxel96, cohadar, meticulous and -kobas- for your help :)
 
Level 2
Joined
Nov 30, 2011
Messages
9
no lol, i used your way to do this XD
i dont know how to use hash tables so i had no choice XD
 
Status
Not open for further replies.
Top