[Snippet] Item Bound

nelmvn
Registered users
Registered users
Posts: 9
Joined: Mon Nov 19, 2018 5:44 pm
Reputation: 0
Website: https://fugatsu.freeforums.net/
Contact:
Philippines

[Snippet] Item Bound

#1

Post by nelmvn » Mon Apr 20, 2020 12:50 am

Item Bound

It is used to set the ownership to an item.

Requires:
- optional RegisterPlayerUnitEvent
- optional SimError

Code: Select all

scope ITEMBOUND initializer main /* v1.0.0.1
************************************************************************************
*
*    This script is used to set the ownership in an item.
*
************************************************************************************/

static if LIBRARY_RegisterPlayerUnitEvent then
    private function OccurA takes nothing returns nothing
else
    private function OccurB takes nothing returns boolean
endif
        local unit    UNIT      = GetTriggerUnit()
        local item    ITEM      = GetManipulatedItem()
        local integer ITEM_ID   = GetItemUserData(ITEM)

        local player  PICKER    = GetOwningPlayer(UNIT)
        local integer PLAYER_ID = GetPlayerId(PICKER)
        local player  OWNER
        local string  NAME

        if ITEM_ID == 0 then
            // Set the ownership id.
            call SetItemUserData(ITEM, PLAYER_ID + 1)
        else
            // Check if the ownership id and player id are same.
            if ITEM_ID - 1 != PLAYER_ID then
                set OWNER = Player(ITEM_ID - 1)
                set NAME  = GetPlayerName(OWNER)

                // Display the error message.
                static if LIBRARY_SimError then
                    call SimError(PICKER, "This item is owned by " + NAME + ".")
                else
                    call DisplayTimedTextToPlayer(PICKER, 0, 0, 2, "This item is owned by " + NAME + ".")
                endif

                // Drop a picked item on the ground.
                call UnitRemoveItem(UNIT, ITEM)

                set OWNER = null
                set NAME  = null
            endif
        endif

        // Remove memory leaks.
        set UNIT   = null
        set ITEM   = null
        set PICKER = null

    static if not LIBRARY_RegisterPlayerUnitEvent then
        return false
    endif
    endfunction

    private function main takes nothing returns nothing
        static if LIBRARY_RegisterPlayerUnitEvent then
            call RegisterAnyPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM, function OccurA)
        else
            local trigger trg = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_PICKUP_ITEM)
            call TriggerAddCondition(trg, Condition(function OccurB))
            set trg = null
        endif
    endfunction
endscope
Last edited by nelmvn on Sat Sep 19, 2020 5:45 pm, edited 1 time in total.

Jiren
Registered users
Registered users
Posts: 1
Joined: Sat Nov 03, 2018 1:49 am
Reputation: 0

Re: [Snippet] Item Bound

#2

Post by Jiren » Thu Jun 25, 2020 5:48 am

there is no attachments?

User avatar
ZODD
Administrator
Administrator
Posts: 3658
Joined: Sat Sep 15, 2018 2:16 pm
Reputation: 3638
Location: NYC,New York
Website: http://chaosrealm.co
Twitch: https://www.twitch.tv/z0ddz
Contact:
United States of America

Re: [Snippet] Item Bound

#3

Post by ZODD » Fri Jun 26, 2020 2:05 pm

Its a snippet there is no need for a attachment all the info is there
Image

Return to “Systems”

×