• 🏆 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!

[JASS] Function Question

Status
Not open for further replies.
Level 10
Joined
Feb 20, 2008
Messages
448
hi evry1, i am learning jass and THERE IS a trigger i found usefull : but i dont understand it a all : this trigger is suposed to work like this : a unit is allowed to wear ONLY 1 ITEM of id "I01X" if he pick up the item the item stay on ground...... glitch : but if he drop the ticket he have HE cannot retake same ticket or another 1. so i would like to understand the function well and fix the glitch also ^^

can some1 explain me this trigger because i don't understand those 2 function UnituserData & removeitemswapped ? what is so different from removeitem ?
and how can i fix the glitch i explain "uper"

i had no reason to understand the trigger until i found the glitch ....XD

some1 can help me ? + rep for all helper :)

p.s. i got jngp is there any book or guide i can download to explain me how tu use jass native function ?there is so much function.... and there some of them that i don't even know what they do......XD

sorry for my bad english.... trying to fix

JASS:
function Trig_One_Ticket_Only_Func003C takes nothing returns boolean
	return((GetOwningPlayer(GetManipulatingUnit())==Player(0)))or((GetOwningPlayer(GetManipulatingUnit())==Player(1)))or((GetOwningPlayer(GetManipulatingUnit())==Player(2)))or((GetOwningPlayer(GetManipulatingUnit())==Player(3)))or((GetOwningPlayer(GetManipulatingUnit())==Player(5)))or((GetOwningPlayer(GetManipulatingUnit())==Player(6)))
endfunction

function Trig_One_Ticket_Only_Conditions takes nothing returns boolean
	return((GetItemTypeId(GetManipulatedItem())=='I01X'))and(Trig_One_Ticket_Only_Func003C())
endfunction

function Trig_One_Ticket_Only_Func001C takes nothing returns boolean
	return((GetUnitUserData(GetManipulatingUnit())==1))
endfunction

function Trig_One_Ticket_Only_Actions takes nothing returns nothing
	if(Trig_One_Ticket_Only_Func001C())then
		call UnitRemoveItemSwapped(GetItemOfTypeFromUnitBJ(GetManipulatingUnit(),'I01X'),GetManipulatingUnit())
	else
		call SetUnitUserData(GetManipulatingUnit(),1)
	endif
endfunction

	set udg_trigger11=CreateTrigger()
	call TriggerRegisterAnyUnitEventBJ(udg_trigger11,EVENT_PLAYER_UNIT_PICKUP_ITEM)
	call TriggerAddCondition(udg_trigger11,Condition(function Trig_One_Ticket_Only_Conditions))
	call TriggerAddAction(udg_trigger11,function Trig_One_Ticket_Only_Actions)

edit : i dont know what userunitdata mean but i have made a trigger : when he drop set user data to 0 o_O but i still want to know if there is a guide book function for jass O_O
 
Last edited:
RemoveItemSwapped is the same as RemoveItem, it just has its parameters switched for GUI users. Use RemoveItem() if you are using JASS.

Try this:
JASS:
function OneTicketCond takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem())=='I01X' and GetPlayerId(GetOwningPlayer(GetTriggerUnit()))<=6
//Checks if the item is 'I01X' and if the Player is either 1, 2, 3, 4, 5, 6, or 7.
endfunction

function OneTicketAct takes nothing returns nothing
    local integer i = 0
    local integer slot = -1
    local item X = null
    local item A
    local real x
    local real y 
    //Integer i is the index for hte loop
    //The slot will let you know which slot the item is located in. It is initially as -1 for the check below.
    //The item X is used to check the item in the slot
    loop
        exitwhen i >= 6 
        //It checks when the index equals 6, checking all the slots
        set X = UnitItemInSlot(GetTriggerUnit(),i)
        //Sets item X as the item in the slot of the index. 
        //If there is no item, it will return as "null" for X
        if X != null and GetItemTypeId(X) == 'I01X' then
        //Checks if the X item is null and checks to make sure the item in the slot is 'I01X'
            set slot = i 
            set i = 6   
        //this allows the loop to immediately exit, since we know which slot the item is in
        endif
        set i = i + 1
        //If it wasn't in the slot, it will move on to the next slot and run the loop again
    endloop
    if slot != -1 then
    //Checks to make sure that the slot value isn't its original value of -1. It should be some number from 0-5.
        set x = GetRandomReal(GetUnitX(GetTriggerUnit())-32,GetUnitX(GetTriggerUnit())+32)
        set y = GetRandomReal(GetUnitY(GetTriggerUnit())-32,GetUnitY(GetTriggerUnit())+32)
        //This makes it so that the item is dropped randomly next to the unit.
        call UnitRemoveItem(GetTriggerUnit(),UnitItemInSlot(GetTriggerUnit(),slot))
        //Removes the item from the inventory
        set A = CreateItem('I01X',x,y)
        //Creates the item dropped at x and y.
        call SetItemDropID(A,GetUnitTypeId(GetTriggerUnit()))
        call UpdateStockAvailability(A)  
        //Just traditional item dropping stuff. 
    endif
    //null the variables
    set A = null
    set X = null
endfunction

function InitTrig_One_Ticket_Only takes nothing returns nothing
    local trigger t = CreateTrigger()
//Creates the trigger
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
//Register when a unit picks up an item.
    call TriggerAddCondition(t,Condition(function OneTicketCond))
    call TriggerAddAction(t,function OneTicketAct)
    set t = null
endfunction

I commented the text so that you know what it does. A lot of JASS functions are kind of self-explanatory, eg: SetUnitX and SetUnitY will set the units position. (x,y) coordinates

If you need help finding out what functions do, you can always just make a GUI function, convert it to custom text, and then look at how the function works. (This is not typically advised though, since more than half of the GUI functions are converted as BJ's, which are slower than directly calling natives)

Otherwise, try to look at some JASS tutorials to get the basic syntax down. That trigger you posted is someone who used a GUI trigger and then just converted it and left it like that. It is hard to learn from that since blizzard uses odd naming conventions such as Func003C and lots of underscores. (This is probably blizzard's method of "private" functions to prevent function names from being used twice.)
 
Level 10
Joined
Feb 20, 2008
Messages
448
Thanks both :D now i got 2 trigger :eek: : which 1 better ?

edit the first trigger glitch ........ if i got 2 item they dropped thats good....but if i pick the item again...... its create 2 and still cant pick up againlol
testing second spell now : same glitch ...... if i got 1 item than i take a next 1 there is 3 ticket on groud.....instead of 2 and the unit still cant pick the ticket he dropped
 
Last edited:
Here you go, I tested it (I was too lazy to before), and this works:
JASS:
function OneTicketCond takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem())=='I01X' and GetPlayerId(GetOwningPlayer(GetTriggerUnit()))<=6
endfunction

function OneTicketAct takes nothing returns nothing
    local integer i = 0
    local integer slot = -1
    local item X = null
    loop
        exitwhen i > 5
        set X = UnitItemInSlot(GetTriggerUnit(),i)
        if X != null and GetItemTypeId(X) == 'I01X' and X != GetManipulatedItem() then
            set slot = i 
            set i = 6   
        endif
        set i = i + 1
    endloop
    if slot != -1 then
        call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem()) 
    endif
    set X = null
endfunction

function InitTrig_One_Ticket_Only takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function OneTicketCond))
    call TriggerAddAction(t,function OneTicketAct)
    set t = null
endfunction

Name the trigger One Ticket Only.
 
Last edited:
Status
Not open for further replies.
Top