ok, so ive been working for a while on working with getlocalplayer and SetItemVisible to create a localized item system. im 99% done. my last desync (theres been tons so far >.<)
ill clean leaks later no worry. My problem is that, if you have a full inventory and try to grab an item, desync ahoy. Anyone got a solution, trigger-wise? My current solution is to make all items tomes, but thats alot of work. -.-
JASS:
library CustomDrop initializer init
globals
private hashtable Hash_t = InitHashtable()
private location SendToItem = Location(0,0)
endglobals
private function OnDeath takes nothing returns nothing
local unit u = GetDyingUnit()
local integer unitId = GetUnitTypeId(u)
local integer count = LoadInteger(Hash_t,unitId,0) // if the unit type was not registred for drop it will be equal to 0, else it will be > 0
local real random
local integer i
local item drop
loop // loop on all dropable item for unitID
exitwhen count == 0
set i = 0
loop // player loop
exitwhen i == 11
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER then
set random = GetRandomReal(0,100)
if random < LoadReal(Hash_t,unitId,count) then
set drop = CreateItem(LoadInteger(Hash_t,unitId,count),GetUnitX(u),GetUnitY(u))
call SetItemVisible(drop,GetLocalPlayer()==Player(i))// the item will be visible only for Player(i)
endif
endif
set i = i+1
endloop
set count = count-1
endloop
set u = null
set drop = null
endfunction
private function RegisterDrop takes integer unitId , integer itemId, real chanceToDrop returns nothing // chanceToDrop in percent
local integer n = LoadInteger(Hash_t,unitId,0)
/* integer : unitId ; 0 -> number of possible item drop for the unit type unitId
integer : unitId ; x -> rawcode of the item to drop ; x > 0
real : unitId ; x -> chance of the item x to drop
*/
set n = n+1
call SaveInteger(Hash_t,unitId,0,n)
call SaveInteger(Hash_t,unitId,n,itemId)
call SaveReal(Hash_t,unitId,n,chanceToDrop)
endfunction
private function onItemPickup takes nothing returns nothing
local item it = GetOrderTargetItem()
local unit u = GetTriggerUnit()
local boolean b
local integer i = 0
// call SetItemPosition(i, GetItemX(i), GetItemY(i))
//// call TriggerSleepAction(0.01)
/// call UnitAddItem(u , i)
if it != null then
call IssueImmediateOrder(u, "stop")
call SetUnitPositionLoc(u, GetUnitLoc(u))
call SetItemVisible(it, true)
call UnitAddItem(u, it)
endif
endfunction
private function init takes nothing returns nothing
local trigger trig = CreateTrigger()
local trigger trig2 = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
call TriggerRegisterAnyUnitEventBJ(trig2, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddAction(trig,function OnDeath)
call TriggerAddAction(trig2, function onItemPickup)
call RegisterDrop('n000','rat6',25)
endfunction
endlibrary
ill clean leaks later no worry. My problem is that, if you have a full inventory and try to grab an item, desync ahoy. Anyone got a solution, trigger-wise? My current solution is to make all items tomes, but thats alot of work. -.-