| 08-20-2007, 05:47 PM | #1 |
Hello, I am going to show you how to create an item ownership trigger in this tutorial. Basically what we will do is, if an item is picked up we check the custom value of that item. If it's currently set to 0, then the item is fresh & not owned by anyone. So, if the custom value of the item is 0, the user is allowed to pick up the item. After he picks the item up, the custom value of the item is set to the player number of the triggering unit. When the user picks up an item that the custom value is not 0, it will check if the custom value of the item matches the player number of the triggering unit. If it does, it will allow the user to pick the item up. Otherwise, the user can't pick the item up, and a user-friendly message is shown. We'll start with out event: Trigger: Events
![]() Unit - A unit Acquires an itemThis just runs the actions when any unit acquires an item. We will have no conditions, as all the checking will be done by If/Then/Else actions. Trigger: Here is our first If/Then/Else action. Inside the If - Conditions we will put a Trigger: (Custom value of (Item being manipulated)) Equal to 0This checks if the custom value of the item is 0. Now for the actions that execute if it returns true: Trigger: Trigger: Item - Set the custom value of (Item being manipulated) to (Player number of (Triggering player))What this does, is it sets the custom value of the item to the number of the player owning the triggering unit. So that way, this item system will know whether or not the item is currently owned by a player, and if it is, it will know which player owns the item. Now, if the check for the custom value of the item = 0 returns False, our Else actions will be executed. So lets put our second If/Then/Else inside the Else action: Trigger: Inside the If - Conditions for our second If/Then/Else, we will need this: Trigger: (Custom value of (Item being manipulated)) Equal to (Player number of (Triggering player))If the check of the units custom value = 0 returns false, then of course we need to see what the custom value of the item really is. So, that code will be added. And here is where we are at so far: Trigger: Now we just have 2 last triggers. Ignore the Then - Actions inside that second If/Then/Else, because that is what executes when the custom value is the same as the player number of the triggering unit. AKA, that's what executes when the item belongs to that player. So if you have any creative ideas to add there, like a message that says: Item Equipped! : or w/e, then put them there :) Now, in the last Else - Actions, we need to add these 2 triggers: Trigger: Hero - Drop (Item being manipulated) from (Triggering unit)
![]() Game - Display to (Player group((Owner of (Triggering unit)))) the text: This item does not belong to you!These drop the item from the player & displays the user-friendly message, only if the item does not belong to the user trying to pick the item up. And there we have it, your own Item Ownership trigger. I hope you find this useful for your project :) Here is the full trigger: Trigger: ![]() Conditions
![]() Actions
![]() ![]() If (All Conditions are True) then do (Then Actions) else do (Else Actions)
![]() ![]() ![]() Then - Actions
![]() ![]() ![]() ![]() Item - Set the custom value of (Item being manipulated) to (Player number of (Triggering player))
Thanks for reading And of course, if you wish to add a periodic event to remove ownership from ground-items, you could do something like: Trigger: How to Create Unit-Specific Items By Pyrogasm We do this in nearly the same way as for player-specific items except that we must also use a handy-dandy JASS function called the H2I return-bug. It is a very useful (and very safe; unlike I2H) way to get the handle-index of a particular handle (a handle is everything but a real, integer, boolean, or string). The handle-index is basically like a number-slot that can be used to identify the handle (there is more, but that's all that is concerned with this tutorial), which we will be using to check to see if the right unit is picking up the item. In order to use the return-bug, you'll need to add the following to your map's Custom Script header: JASS:function Items_H2I takes handle h returns integer return h return 0 endfunction Not so hard, is it? Just C 'n P it into the header. Then, we'll see how this is applied to the previous trigger. First, we'll have to get the custom value of the item like usual and then compare that to the handle index of the manipulating unit. Here's how we'd do that (this requires a variable of type "integer", which I called UnitIndex): Trigger: Quite simply put, that is all there is to it. However, you can also combine both sets of ownership triggers as seen below. In the following example, I have made it so that if a unit picks up an unowned item it will be useable by that owning player only; however, if it is a Boots of Speed, only that specifc unit may use it. This works because player indexes range from 1 to 16 (0-15 in JASS) and handle indexes are > 820000. Trigger: ![]() Conditions
![]() Actions
![]() ![]() Custom script: set udg_UnitIndex = Items_H2I(GetTriggerUnit())
![]() ![]() If (All Conditions are True) then do (Then Actions) else do (Else Actions)
![]() ![]() ![]() Else - Actions
![]() ![]() ![]() ![]() If (All conditions are True) then do (Then Actions) else do (Else Actions)
|
| 08-21-2007, 06:15 AM | #3 |
There's a way to expand on this, I believe, to make unit-specific items. If you instead set the custom value to the handle index of the owning unit and then compare that when the item is picked up you can make unit-specific items (like soulbound items in WoW). I could write a short extension to this tutorial explaining this if you want (since you don't appear to know JASS, which is slightly required for this) and then Pitzermike could just tack that on to your tutorial if it gets approved. |
| 08-21-2007, 04:48 PM | #4 |
That's a very good idea, Pyro. |
| 08-21-2007, 05:49 PM | #5 |
Well then; what's the likely fate of this tutorial? Shall I write the addition? |
| 08-21-2007, 06:04 PM | #6 |
Yea that would make a great extension, go ahead and write it :) Once finished I can just edit my post & throw it in. |
| 08-21-2007, 10:33 PM | #7 |
With the Clean items trigger you use the periodic event every 300 seconds, that doesnt meen that if i drop an item it wil dissapear after 300 seconds, i could drop an item after playing for 299 seconds and it would dissapear 1 second later. Try to fix that |
| 08-22-2007, 01:57 AM | #8 | |
Quote:
True, that is one of the problems I faced after showing that example. But it's just an example :) You gotta use your own imagination to create these kind of triggers to work with this Item Ownership Trigger. But I will try to think up an algorithm to get that fixed, since you asked ![]() Edit: I came up with this, but it smells a bit leaky. Would anyone like to fill me in on the leak part? Thanks! |
| 08-22-2007, 07:31 AM | #9 |
Not leaky, but inefficient. Oh, and it won't work because (Item being manipulated) won't return an item after a wait. The best solution would be through timers and JASS (attachables/structs) |
| 08-22-2007, 03:34 PM | #10 | |
Quote:
It is decidedly so. |
| 08-25-2007, 09:02 PM | #12 |
Nice. I guess the posts have to be merged by a mod, if I just copy & paste it won't keep the correct format of the triggers. To whichever mod merges these posts, please include credit for Pyrogasm. & thanks :) |
| 08-25-2007, 09:13 PM | #13 |
You can quote me to get the appropriate vB code formatting. |
| 08-25-2007, 09:29 PM | #14 |
Can't believe I didn't think of that. :X Added w/ credits. |
| 08-27-2007, 06:32 PM | #15 |
Well done, you two. I approve. ![]() |
