• 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.

[JASS] Help With Copying Item

Status
Not open for further replies.
Level 3
Joined
Jan 31, 2008
Messages
66
hi how can i do a trigger in jass which is like this: when a player types -copyitem 1, the itemcode of the item in slot 1 of the hero that the player is selecting will be copied and whenever the player click other heros and type -pasteitem 5 for example, 5 of the type of item copied will be created and given to the unit that the player is currently selecting? can anyone help mi with this? :grin:
 
Level 5
Joined
Aug 16, 2007
Messages
149
Good to see you've decide to learn JASS! Here's some code I knocked up for you, most lines commented so you should learn from it if you read the comments. Dunno if some of the comments sound a little patronizing though, don't know how good you are at JASS...
JASS:
globals//declare global variables
    integer array clipboard//the clipboard, where copied items are stored
    integer temp_int//temp_int is used to pass integers to filters. won't ruin MUI since there are no waits
endglobals

//the filters for GroupEnumUnitsSelected()
function Enum_Selected_Filter_Copy takes nothing returns boolean
    return UnitInventorySize(GetEnumUnit()) >= temp_int and UnitItemInSlot(GetEnumUnit(),temp_int) != null
endfunction

function Enum_Selected_Filter_Paste takes nothing returns boolean
    return UnitInventorySize(GetEnumUnit()) >= temp_int and not UnitItemInSlot(GetEnumUnit(),temp_int) != null
endfunction
//end filters, following is actions

function Trig_Items_Actions takes nothing returns nothing
  local string s = GetEventPlayerChatString()//set as variable to improve speed
  local player p = GetTriggerPlayer()//"   "
  local group g = CreateGroup()//"   "
  local boolexpr e//need to set boolexpr to a variable so it can be destroyed later, preventing leaks
    //do following if player wants to copy
    if SubString(s,0,9) == "-copyitem" then
        set temp_int = S2I(SubString(s,10,11))//set temp_int to slot player wants to copy from
        set e = Condition(function Enum_Selected_Filter_Copy)//set filter as the copy filter
        call GroupEnumUnitsSelected(g,p,e)//get units selected, checking if valid using filters
        if FirstOfGroup(g) != null then//first of group is the unit to copy from
            set clipboard[GetPlayerId(p)] = GetItemTypeId(UnitItemInSlot(FirstOfGroup(g), temp_int))
            //save itemid of item to player's clipboard
        else
            call DisplayTextToPlayer(p,0.,0.,"No item to copy in that slot.")//no item to copy, tell player
        endif
    //do following if player wants to paste
    elseif SubString(s,0,10) == "-pasteitem" then
        set temp_int = S2I(SubString(s,11,12))//set temp_int to slot player wants to paste in
        set e = Condition(function Enum_Selected_Filter_Paste)//set filter as the paste filter
        call GroupEnumUnitsSelected(g,p,e)//get units selected, checking if valid using filters
        if FirstOfGroup(g) != null then//first of group is the unit to paste to
            call UnitAddItemToSlotById(FirstOfGroup(g),clipboard[GetPlayerId(p)],temp_int)
            //add item from clipboard to inventory
        else
            call DisplayTextToPlayer(p,0.,0.,"Could not paste. Please check if that slot is empty, or if you even have a slot "+I2S(temp_int)+".")
            //paste slot unavailable, tell player
        endif
    endif
    //cleaning leaks
    call DestroyBoolExpr(e)//destroy the boolexpr, boolexprs leak
    set g = null//must set all handles to null
    set p = null
    set e = null
endfunction

//===========================================================================
function InitTrig_Items takes nothing returns nothing
  local integer i = 0
    set gg_trg_Items = CreateTrigger(  )//initialize the trigger
    loop//used a loop for events
        exitwhen i == bj_MAX_PLAYERS//exits the loop when i is equal to max players
        call TriggerRegisterPlayerChatEvent( gg_trg_Items, Player(i), "-copyitem", false )
        //'false' indicates it doesn't have to be an exact match to trigger the trigger
        call TriggerRegisterPlayerChatEvent( gg_trg_Items, Player(i), "-pasteitem", false )
        set i = i+1//setting i = i+1, moving the loop on to the next player
    endloop
    call TriggerAddAction( gg_trg_Items, function Trig_Items_Actions )//must add actions
endfunction
 
Level 3
Joined
Jan 31, 2008
Messages
66
thanks a lot for ur post bubba, but it's a little bit complicated.... but i know that this function checks if the selected unit has any slots in the inventory left rite? can u use the unitadditembyidswapped? because for this trigger i don't mind whether the unit has an empty slot or not... :grin:
 
Level 5
Joined
Aug 16, 2007
Messages
149
I'm sure you can modify it to what you want as it's not that complicated and all lines are commented.
 
Level 3
Joined
Jan 31, 2008
Messages
66
yup i have managed to modified it to what i want... but i have another question to ask... how do u use the function: UnitDamageTarget? i dun understand what are the boolean attack and boolean ranged stands for.... can u teach mi? :grin:
 
Level 5
Joined
Aug 16, 2007
Messages
149
ranged is if it is a ranged attack or not. I don't actually know what attack is for (when you're damaging something, of course you're attacking it) but just set it to true and it works fine.
 
Level 3
Joined
Jan 31, 2008
Messages
66
oooh ok tnks ya :wink: jasscraft is a very good jass editor for noobs learning how to use jassscript, it's very noob friendly and they have the list of native functions so that u can learn from there.... i will post again if i have anymore problem but thanks anyway! :grin:
 
Level 3
Joined
Jan 31, 2008
Messages
66
ooh what's that? by the way after i edited the dota 6.51 map and added an autokill banned globals skills for wtf mode only, but it seems that when ever someone spams skills, when it gets too lag, all the other players will see mi leave the game and because i'm the host, when i leave the game, all the other players all left the game... anyone know how to solve this problem? :cry:
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
ooh what's that?

JNGP (Jass New Gen Pack) is a hacked version of the WE (World Editor) that is way better then the normal WE in every aspect.
Jass in JNGP is especialy powerfull (no random crashes, text highlighting, functions list, vJass).

If you do not use Jass, it is better then the normal WE.
If you use Jass... its WAY WAY WAY WAY WAY better then the normal WE.

by the way after i edited the dota 6.51 map and added an autokill banned globals skills for wtf mode only, but it seems that when ever someone spams skills, when it gets too lag, all the other players will see mi leave the game and because i'm the host, when i leave the game, all the other players all left the game... anyone know how to solve this problem? :cry:

Didn't get what you're trying to make.
 
Level 5
Joined
Aug 16, 2007
Messages
149
He got a server split I think when someone spammed skills. You need to post your code for us to be able to sort that out.
 
Level 3
Joined
Jan 31, 2008
Messages
66
ok i made it wtf mode only, which means only for wtf mode, where u can autokill someone when he casts a banned skill like thundergod's wrath (in wtf mode u can spam all u want, which means u will be owning!) but it will lag mi out whenever a time is reached, can anyone tell mi why? :cry:
 
Status
Not open for further replies.
Top