Would that cause desync ?
I'm making this for a larger system that I will make if this work correctly.
Edit: Btw I call this function from a Unit Respawn System that's why there's no Init in this trigger. In singleplayer it definitively works, but I got no idea if it will multiplayer. There's probably better ways to do a few things in there too.
Edit2: Yeah I know I got a "useless" condition in there, it's only set to be able to change drop rate, but I made it 100% for testing purposes.
Edit3: Updated my system to make it easier to add items drops.
Edit4: Updated to be easier the read, changed variable names. It was suggested by Teelo .
Edit5: Updated found a Force Leak.
Edit6: Added GoldLoot that was on 4th post to first post:
Edit7: Updated both Triggers as rulerofiron99 indicated, with the exception of nulling the item variable since I don't how :/...
Edit8: Updated ItemLoot Trigger, nulled itemCreated.
Edit9: It caused desync so I built another system that I;m having problems with it creates the item but then any other call seem to have no effect. Seems like the variable ain't registering the item correctly.
New trigger:
JASS:
library ItemLoot
private function HideItem takes item itemCreated, boolean show, force forWhom returns nothing
if (IsPlayerInForce(GetLocalPlayer(), forWhom)) then
call SetItemVisible(itemCreated, show)
endif
endfunction
private function MakeItem takes integer itemID, unit dyingUnit, player ownerOfKillingUnit, integer chances returns nothing
local integer randomNumber = GetRandomInt(1, 100)
local real locX = GetUnitX(dyingUnit)
local real locY = GetUnitY(dyingUnit)
local force forWhom = CreateForce()
local item itemCreated
if randomNumber <= chances then
set itemCreated = CreateItem(itemID, locX, locY)
call SetItemInvulnerable(itemCreated, true)
call ForceAddPlayer(forWhom, ownerOfKillingUnit)
call HideItem(itemCreated, false, bj_FORCE_ALL_PLAYERS)
call HideItem(itemCreated, true, forWhom)
call TriggerSleepAction(5)
call HideItem(itemCreated, true, bj_FORCE_ALL_PLAYERS)
endif
set itemCreated = null
call DestroyForce(forWhom)
endfunction
function ItemLoot takes unit dyingUnit, player ownerOfKillingUnit returns nothing
local integer itemID
local integer chances
if GetUnitTypeId(GetTriggerUnit()) == 'hfoo' then
set chances = 100
set itemID = 'modt'
call MakeItem(itemID, dyingUnit, ownerOfKillingUnit, chances)
endif
endfunction
endlibrary
I'm making this for a larger system that I will make if this work correctly.
Edit: Btw I call this function from a Unit Respawn System that's why there's no Init in this trigger. In singleplayer it definitively works, but I got no idea if it will multiplayer. There's probably better ways to do a few things in there too.
Edit2: Yeah I know I got a "useless" condition in there, it's only set to be able to change drop rate, but I made it 100% for testing purposes.
Edit3: Updated my system to make it easier to add items drops.
Edit4: Updated to be easier the read, changed variable names. It was suggested by Teelo .
Edit5: Updated found a Force Leak.
Edit6: Added GoldLoot that was on 4th post to first post:
JASS:
library GoldLoot
globals
private integer goldMinX = 3
private integer goldMinPlus = 4
private integer goldMaxX = 6
private integer goldMaxPlus = 8
endglobals
function GoldLoot takes unit dyingUnit, player ownerOfKillingUnit returns nothing
local integer goldDrop = GetRandomInt((GetUnitLevel(dyingUnit) * goldMinX) + goldMinPlus, (GetUnitLevel(dyingUnit) * goldMaxX) + goldMaxPlus)
local texttag goldNumber = CreateTextTag()
local force forWhom = CreateForce()
call SetPlayerState(ownerOfKillingUnit, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(ownerOfKillingUnit, PLAYER_STATE_RESOURCE_GOLD) + goldDrop)
call SetTextTagText(goldNumber, I2S(goldDrop), 0.026)
call SetTextTagPermanent(goldNumber, false)
call ForceAddPlayer(forWhom, ownerOfKillingUnit)
call ShowTextTagForceBJ(false, goldNumber, bj_FORCE_ALL_PLAYERS)
call ShowTextTagForceBJ(true, goldNumber, forWhom)
call SetTextTagColor(goldNumber, 255, 225, 0, 255)
call SetTextTagFadepoint(goldNumber, 0.50)
call SetTextTagLifespan(goldNumber, 1.50)
call SetTextTagPos(goldNumber, GetUnitX(dyingUnit) - 30.00, GetUnitY(dyingUnit), 75.00)
call SetTextTagVelocity(goldNumber, 0.00, 0.03)
call DestroyForce(forWhom)
endfunction
endlibrary
Edit7: Updated both Triggers as rulerofiron99 indicated, with the exception of nulling the item variable since I don't how :/...
Edit8: Updated ItemLoot Trigger, nulled itemCreated.
Edit9: It caused desync so I built another system that I;m having problems with it creates the item but then any other call seem to have no effect. Seems like the variable ain't registering the item correctly.
New trigger:
JASS:
library ItemLoot initializer ILInit requires PlayerColors
globals
private hashtable itemLootHashTable InitHashtable()
endglobals
private function MakeItem takes integer itemId, unit dyingUnit, unit killingUnit, integer itemIdWhite returns nothing
local real locX = GetUnitX(dyingUnit)
local real locY = GetUnitY(dyingUnit)
local item itemCreated = CreateItem(itemId, locX, locY)
local integer id = itemIdWhite
call SaveInteger(itemLootHashTable, GetHandleId(itemCreated), StringHash("itemIdWhite"), itemIdWhite)
call SaveUnitHandle(itemLootHashTable, GetHandleId(itemCreated), StringHash("killingUnit"), killingUnit)
call SaveUnitHandle(itemLootHashTable, GetHandleId(itemCreated), StringHash("dyingUnit"), dyingUnit)
call TriggerSleepAction(5)
call RemoveItem(itemCreated)
call CreateItem(id, locX, locY)
call FlushChildHashtable(itemLootHashTable, GetHandleId(itemCreated))
set itemCreated = null
endfunction
private function UnitFootman takes unit dyingUnit, unit killingUnit returns nothing
local player ownerOfKillingUnit = GetOwningPlayer(killingUnit)
local integer chances = 50
local integer randomInteger = GetRandomInt(1, 100)
local integer itemId
local integer itemIdWhite // "white" meaning "neutral" item
if randomInteger <= chances then
if ownerOfKillingUnit == Player(0) then
set itemId = 'I001'
set itemIdWhite = 'I000'
endif
if ownerOfKillingUnit == Player(1) then
set itemId = 'I002'
set itemIdWhite = 'I000'
endif
call MakeItem(itemId, dyingUnit, killingUnit, itemIdWhite)
endif
endfunction
function ItemLoot takes unit dyingUnit, unit killingUnit returns nothing
if GetUnitTypeId(dyingUnit) == 'hfoo' then
call UnitFootman(dyingUnit, killingUnit)
endif
endfunction
private function ItemPickup takes nothing returns nothing
local unit triggeringUnit = GetTriggerUnit()
local item manipulatedItem = GetManipulatedItem()
local integer itemIdWhite = LoadInteger(itemLootHashTable, GetHandleId(manipulatedItem), StringHash("itemIdWhite"))
local unit killingUnit = LoadUnitHandle(itemLootHashTable, GetHandleId(manipulatedItem), StringHash("killingUnit"))
local unit dyingUnit = LoadUnitHandle(itemLootHashTable, GetHandleId(manipulatedItem), StringHash("dyingUnit"))
local texttag textTag = CreateTextTag()
local player ownerOfTriggeringUnit = GetOwningPlayer(triggeringUnit)
local force f = CreateForce()
if triggeringUnit == killingUnit then
call RemoveItem(manipulatedItem)
call UnitAddItemById(triggeringUnit, itemIdWhite)
else
call RemoveItem(manipulatedItem)
call MakeItem(GetItemTypeId(manipulatedItem), dyingUnit, killingUnit, itemIdWhite)
call SetTextTagText(textTag, "This item is owned by " + GetPlayerColorCode(ownerOfTriggeringUnit) + GetPlayerName(ownerOfTriggeringUnit) + "|r!", 0.026)
call SetTextTagPermanent(textTag, false)
call ForceAddPlayer(f, ownerOfTriggeringUnit)
call ShowTextTagForceBJ(false, textTag, bj_FORCE_ALL_PLAYERS)
call ShowTextTagForceBJ(true, textTag, f)
call SetTextTagFadepoint(textTag, 2.00)
call SetTextTagLifespan(textTag, 3.00)
call SetTextTagPos(textTag, GetUnitX(dyingUnit), GetUnitY(dyingUnit), 100.00)
endif
call FlushChildHashtable(itemLootHashTable, GetHandleId(manipulatedItem))
call DestroyForce(f)
call DestroyTextTag(textTag)
set manipulatedItem = null
endfunction
private function ILInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(t, function ItemPickup)
endfunction
endlibrary
Last edited: