• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Giving items with a chat command.

Status
Not open for further replies.
Level 2
Joined
Jul 6, 2013
Messages
6
Hello, I'm making a RPG map and I'm trying to make a Trigger that when you say "Give (Item Name)". That item appears in the inventory of a random unit of type hero owned by random player in group ADM (There is only 1 ADM and 1 hero per player).
Well I need your help to make the "Give (item name)" command. I would really apreciate it.

Thanks, and sorry for my English. Inusenshi.
 
There is an event trigger for chat, use it as event

then use as conditions a substring check, check if it includes "give"

then on the actions track down the substring for the item name... then maybe you search for the ID of that item using a hashtable you set up or something... you need to do it since you cannot give items via name directly, since names are well, arbitrary...
 
Level 6
Joined
Nov 5, 2013
Messages
132
Look the chat message event, and put there the comand string.
Add actions to give the item to the hero when the player writes determinated ID (ever with the command preffix)

Save the avaliables items in some variable, ex:

Set Item[12] = Sword

When the player writes -give 12:

Create 1Item[Here the ID] ..... Give this item to the hero.

In this case the ID is 12, so the item to give is the sword.
Everytime you need set where start to detect the suffix (number), use determinate the determinate string lenght to make it.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Since some people don't seem to be reading what you want (gj this time Adiktuz)

JASS:
set itemTypeId = LoadInteger(myHashtable, StringHash(itemName), 0)

//given an array of all heroes
set hero = allHeroes[GetRandomInt(0, allHeroesCount)]

call UnitAddItemById(hero, itemTypeId)

JASS:
call TriggerRegisterPlayerChatEvent(myTrigger, whichPlayer, "Give", false)
call TriggerAddCondition(myTrigger, Condition(function OnGive))

JASS:
local boolean isGiveCommand = //make sure string starts with Give
local string itemName = //getItemName

//load item type id

if (itemExists) then
    //do rest
endif

Now that people see what the OP wants, someone can translate the above to GUI
 
something like this...

  • Events
    • Player - Player 1 types in "Give" as a substring
  • Conditions
  • Actions
    • Set item_name = Substring(Entered ChatString, 5,Length of entered chat string)
    • Set item = Load Key(item_name) of Key(ITEMS) from Hash
    • Unit - Give item to unit
as for saving things in the hash, something like this

  • Events
    • Map Initialization
  • Actions
    • Hashtable - create a new hashtable
    • Set Hash = Last created hashtable
    • Save Sword of Power as Key("Sword of Power") in Key(ITEMS) in Hash
 
Level 2
Joined
Jul 6, 2013
Messages
6
Thanks you all!
But Nestharus, I really suck with JASS (I don't know anything about it ._.). Can you make me a "ctl+c" "ctrl+v" version please? xd
I know that I a sound like a noob, and yes, Yes I am. I would really appreciate it. If you can't or just don't want to do it, I'll use the giving an ID to the items method, so don't worry.
Again, thanks you for your time.

EDIT: I'll try it Adiktuz. You posted before I send this reply xd
 
well, as I said, only something like that... XD...

  • Player - Player 1 types in "" as a substring
  • Conditions
    • Substring(Entered chat string,0,4) is equal to "Give"
  • Actions
  • Set item_name = Substring(Entered ChatString, 5,Length of entered chat string)
  • Set item = Load Key(item_name) of Key(ITEMS) from Hash
  • Unit - Give item to unit
w8, wouldn't loading be null anyways if the item does not exist in the hash?
 
Status
Not open for further replies.
Top