HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help! Custom weapons as Items

06-09-2004, 06:05 PM#1
sillydragon12
o_O Ive been trying to get a custom weapon to attach to a unit if the unit is carrying an item and if hero drops the item it will destroy the special effect but it just crashs the game Can anyone help!

My Attept

Events
Unit - A unit Acquires an item
Conditions
(Item-type of (Item being manipulated)) Equal to Flame sword
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Hero manipulating item) is A Hero) Equal to True
Then - Actions
Special Effect - Create a special effect attached to the hand of (Hero manipulating item) using Objects\InventoryItems\angelsword.mdx
Trigger - Add to (This trigger) the event (Unit - A unit Loses an item)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Last dropped item) Equal to (Item being manipulated)
Then - Actions
Special Effect - Destroy (Last created special effect)
Else - Actions
Trigger - Run (This trigger) (checking conditions)
Else - Actions
Trigger - Run (This trigger) (checking conditions)
06-09-2004, 07:15 PM#2
LegolasArcher
Quote:
Originally Posted by sillydragon12
o_O Ive been trying to get a custom weapon to attach to a unit if the unit is carrying an item and if hero drops the item it will destroy the special effect but it just crashs the game Can anyone help!

My Attept

Events
Unit - A unit Acquires an item
Conditions
(Item-type of (Item being manipulated)) Equal to Flame sword
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Hero manipulating item) is A Hero) Equal to True
Then - Actions
Special Effect - Create a special effect attached to the hand of (Hero manipulating item) using Objects\InventoryItems\angelsword.mdx
Trigger - Add to (This trigger) the event (Unit - A unit Loses an item)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Last dropped item) Equal to (Item being manipulated)
Then - Actions
Special Effect - Destroy (Last created special effect)
Else - Actions
Trigger - Run (This trigger) (checking conditions)
Else - Actions
Trigger - Run (This trigger) (checking conditions)
http://www.wc3campaigns.com/showthread.php?t=48616
Infinate loop. You dont even need triggers for this. Add a modified battle standard ability with the correct attachment to your item.
06-09-2004, 07:44 PM#3
weaaddar
Quote:
Code:
Events
    Unit - A unit Acquires an item
Conditions
    (Item-type of (Item being manipulated)) Equal to Flame sword
Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        If - Conditions
            ((Hero manipulating item) is A Hero) Equal to True
        Then - Actions
            Special Effect - Create a special effect attached to the hand of (Hero manipulating item) using Objects\InventoryItems\angelsword.mdx
            Trigger - Add to (This trigger) the event (Unit - A unit Loses an item)
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Last dropped item) Equal to (Item being manipulated)
                Then - Actions
                    Special Effect - Destroy (Last created special effect)
                Else - Actions
                    Trigger - Run (This trigger) (checking conditions)
        Else - Actions
            Trigger - Run (This trigger) (checking conditions)

your causing infinite recursion because your code once run constantly keeps calling itself once the trigger forgets the event related function values, which happens as soon as you call it in a new thread.

As far as solutions, I'd suggest downloading DT4a as it works perfectly for this situation and will allow you to do modelling for all weapons without having to create a new trigger for each.

However, to fix your bugged code you may think of doing this create a bunch of parralel arrays:
Items -an item type array which defines all the items that have effects to them
SFX- an array of special effects
SFXpath-an array of strings containing the path of the effects your using
SFXattach-an array of strings containing paths of the place to attach to

finally you'll need another integer variable called ArrayLimit, which has the value of the last element you defined plus one. (e.g. if you defined Items[0] as your last one then you would put 1 here)

This code here assumes you only will have one weapon at a time to attach to the unit and ONLY one. This will also drop the new item if the unit already has an item that adds a special effect.

So first you would set up your items:
Code:
Sample Init
    Events
        Map initialization
    Conditions
    Actions
        -------- Claws Of attack + 15 --------
        Set Items[0] = Claws of Attack +15
        Set SFXAttach[0] = hand left
        Set SFXPath[0] = Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
        -------- Mask o Death --------
        Set Items[1] = Mask of Death
        Set SFXAttach[1] = overhead
        Set SFXPath[1] = units\human\WarWagon\WarWagon.mdl
Then you would create a trigger that fires when its aquired and does something along these lines
Code:
Item Aquired
    Events
        Unit - A unit Acquires an item
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Custom value of (Hero manipulating item)) Not equal to 0
            Then - Actions
                Game - Display to (Player group((Owner of (Hero manipulating item)))) the text: (You are currently holding a weapon, you must drop it before you can equip  + (Name of (Item being manipulated)))
                Custom script:   call CreateItem(GetItemTypeId(GetManipulatedItem()),GetUnitX(GetManipulatingUnit()),GetUnitY(GetManipulatingUnit()))
                Item - Remove (Item being manipulated)
            Else - Actions
                For each (Integer A) from 0 to ArrayLimit, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-type of (Item being manipulated)) Equal to Items[(Integer A)]
                            Then - Actions
                                Special Effect - Create a special effect attached to the SFXAttach[(Integer A)] of (Hero manipulating item) using SFXPath[(Integer A)]
                                For each (Integer B) from 1 to 100, do (Actions)
                                    Loop - Actions
                                        Custom script:   if(udg_SFX[bj_forLoopBIndex]==null)then
                                        Set SFX[(Integer B)] = (Last created special effect)
                                        Unit - Set the custom value of (Hero manipulating item) to (Integer B)
                                        Skip remaining actions
                                        Custom script:   endif
                            Else - Actions
I had to use some jass as theres no comparision to see if a special effect slot isn't being used. But Other then that, you really don't need it. I also had to use it to make sure it didn't leak memory on the location usage. Its rather retarded that you can't get it to not use location.

Finally a trigger to fire when the unit drops the item:
Code:
Item Dropped
    Events
        Unit - A unit Loses an item
    Conditions
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Custom value of (Hero manipulating item)) Not equal to 0
                (Current life of (Item being manipulated)) Greater than or equal to 1.00
            Then - Actions
                For each (Integer A) from 0 to ArrayLimit, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-type of (Item being manipulated)) Equal to Items[(Integer A)]
                            Then - Actions
                                Special Effect - Destroy SFX[(Custom value of (Hero manipulating item))]
                                Unit - Set the custom value of (Hero manipulating item) to 0
                                Custom script:   set udg_SFX[GetUnitUserData(GetManipulatingUnit())]=null
                            Else - Actions
            Else - Actions
OFcourse this is very simple and isn't a very good idea if you want more then one special effect on the unit from weapons. You would then need an integer array and some sort of classification system and it would get messy fast. I would suggest using DT4a if you plan on using something with more then one inventory item type. DT4a is in sweet optimized jass so it should be much more powerful then this and much easier to use.
06-10-2004, 06:43 AM#4
sillydragon12
Wow thanks ^_^