HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

A CSCache problem?

07-07-2008, 07:18 AM#1
Ignitedstar
This is very strange... Jasshelper is getting errors when trying to compile Shadow1500's Recipe System. I get this error:

Line 15256: Missing requirement: CSCache (libraries cannot require scopes)

I noticed that the sample map that has Shadow1500's system uses CSCache 14.1, while the one that my map uses is version 14.3. I really don't know what I should do. If it helps: I've tried to go backwards (using 14.1 instead of 14.3), but I get this error (Shadow's map compiles fine):

Line 279: Symbol udg_cscache multiply defined

Is there anyone who can help? Any help is appreciated, actually.

EDIT: Oops. I'll provide the code:

Collapse JASS:
function InitTrig_RecipeSystem takes nothing returns nothing
endfunction

library RecipeSystem initializer InitRecipeSystem requires CSCache //<--- Jasshelper is getting errors with this
// **********************
// * Abstract functions *
// **********************

// Returns the item in the specified slot and page, or just item in slot
// if no advanced inventory systems are used. pages start counting at 1 and stop when Inv_GetSlots returns 0 for a page.
function Inv_ItemInSlot takes unit u, integer page, integer slot returns item
    return UnitItemInSlot(u,slot-1)
endfunction

// Returns the amount of item that an item page can have (i.e max), returns 0 if the page does not exist.
// The normal inventory has one page with 6 slots.
function Inv_GetSlots takes unit u, integer page returns integer
    return IntegerTertiaryOp(page==1,6,0)
endfunction

// Adds an item to a unit, the item is added to any page with an empty slot
function Inv_AddItem takes unit u, item i returns nothing
    call SetItemPosition(i,GetUnitX(u),GetUnitY(u))
    call UnitAddItem(u,i)
endfunction

// ***************************
// * Automated Recipe System *
// *     By Shadow1500       *
// ***************************
globals
    constant sound ERROR_MSG = CreateSoundFromLabel( "InterfaceError",false,false,false,10,10)
endglobals
function RS_Error takes player p, string s returns nothing
    if GetLocalPlayer()==p then
        if s!="" and s!=null then
            call ClearTextMessages()
            call DisplayTimedTextToPlayer(p,0.52,-1.00,2.00,"|cffffcc00"+s+"|r")
        endif
        call StartSound(ERROR_MSG)
    endif
endfunction
function RS_I2Item takes integer i returns item
    return i
    return null
endfunction
function GetInteger takes string s returns integer
    local integer i = S2I(s)
    if i==0 then
       set i = CS_Rawcode2Int(s)
    endif
    return i
endfunction
function ItemGetSB takes integer itemId returns integer
    //if HaveStoredInteger(udg_cscache,"RecipeSys_SB",I2S(itemId)) then
      return GetStoredInteger(udg_cscache,"RecipeSys_SB",I2S(itemId))
    //endif
    //return S2I(GetAbilityEffectById(itemId,EFFECT_TYPE_TARGET,0))
endfunction
function RecipeAbilityGetItem takes integer abilId returns integer
    if HaveStoredInteger(udg_cscache,"RecipeSys_Item",I2S(abilId)) then
        return GetStoredInteger(udg_cscache,"RecipeSys_Item",I2S(abilId))
    endif
    return S2I(GetAbilityEffectById(abilId,EFFECT_TYPE_CASTER,0))
endfunction
function CreateRecipe takes integer itemId, integer sbAbilId, integer abilId returns nothing
    call StoreInteger(udg_cscache,"RecipeSys_Item",I2S(abilId),itemId)
    call StoreInteger(udg_cscache,"RecipeSys_SB",I2S(itemId),sbAbilId)
endfunction
function UseRecipe takes unit u, integer abilId returns nothing
    local string key = "RecipeSys_R"+I2S(abilId)
    local integer array req_Count
    local integer array req_Item
    local integer array hav_Count
    local integer array hav_Item
    local integer got_Item = 0
    local string last = null
    local string cur = null
    local integer x = 0
    local integer y = 0
    local item i
    local integer reqsNum = 0
    local integer z = 0
    local integer w = GetStoredInteger(udg_cscache,key,"len")
    
    if w>0 then
        // Read recipe data stored in gamecache from previous use.
        loop
            exitwhen x>w
            if not HaveStoredBoolean(udg_cscache,key,"g_"+I2S(x)) then
                set hav_Item[x] = CreatePool()
                set req_Count[x] = GetStoredInteger(udg_cscache,key,"count_"+I2S(x))
                set req_Item[x] = GetStoredInteger(udg_cscache,key,"item_"+I2S(x))
                set reqsNum = reqsNum + 1
            else
                set got_Item = GetStoredInteger(udg_cscache,key,"item_"+I2S(x))
            endif
            set x = x + 1
        endloop
    else
        // Read recipe data from ability.   
        loop
            set cur = GetAbilityEffectById(abilId,EFFECT_TYPE_TARGET,x)
            exitwhen cur==last
            set last = cur
            if SubString(cur,0,1)=="r" then
                set hav_Item[x] = CreatePool()
                set req_Count[x] = S2I(SubString(cur,2,4))
                call StoreInteger(udg_cscache,key,"count_"+I2S(x),req_Count[x])
                set req_Item[x] = GetInteger(SubString(cur,5,StringLength(cur)))
                call StoreInteger(udg_cscache,key,"item_"+I2S(x),req_Item[x])
                set reqsNum = reqsNum + 1
            elseif SubString(cur,0,1)=="g" then
                set got_Item = GetInteger(SubString(cur,2,StringLength(cur)))
                call StoreInteger(udg_cscache,key,"item_"+I2S(x),got_Item)
                call StoreBoolean(udg_cscache,key,"g_"+I2S(x),true)
            endif
            set x = x + 1
        endloop
        call StoreInteger(udg_cscache,key,"len",x-1)
    endif

    set w = 1
    // Get items on hero that are required by recipe.
    loop
        set z = Inv_GetSlots(u,w)
        exitwhen z==0
        set x = 1
        loop
            exitwhen x>z
            set i = Inv_ItemInSlot(u,w,x)
            if i!=null then
                loop
                    exitwhen y>=reqsNum
                    if GetItemTypeId(i)==req_Item[y] then
                        call PoolAddItem(hav_Item[y],CS_H2I(i))
                        if GetItemCharges(i)==0 then
                            set hav_Count[y] = hav_Count[y] + 1
                        else
                            set hav_Count[y] = hav_Count[y] + GetItemCharges(i)
                        endif
                        exitwhen true
                    endif
                    set y = y + 1
                endloop
            endif
            set y = 0
            set x = x + 1
        endloop
        set w = w + 1
    endloop
    
    // Make sure hero has enough charges of each item, show error and exit if not.
    set x = 0
    loop
        exitwhen x>=reqsNum
        if req_Count[x]>hav_Count[x] then
            call RS_Error(GetOwningPlayer(u),"You do not meet the requirments for the recipe")
            set i = null
            set u = null
            return
        endif
        set x = x + 1
    endloop
    
    // Take away charges from items, or remove them if more charges are required.
    set x = 0
    set y = 1
    set z = 0
    loop
        exitwhen x>=reqsNum
        loop
            exitwhen y>CountItemsInPool(hav_Item[x])
            set i = RS_I2Item(PoolGetItem(hav_Item[x],y))
            set z = GetItemCharges(i)
            if z==0 then
               set z = 1
            endif
            if req_Count[x]>=z then
                set req_Count[x] = req_Count[x] - z
                call RemoveItem(i)
                // Do any neccecary operations on item before removing it..
                if req_Count[x]<=0 then
                    exitwhen true
                endif
            else
                call SetItemCharges(i,GetItemCharges(i)-req_Count[x])
                exitwhen true
            endif
            set y = y + 1
        endloop
        call DestroyPool(hav_Item[x])
        set y = 1
        set x = x + 1
    endloop
    
    // Create the recipe's resulting item.
    set i = CreateItem(got_Item,GetUnitX(u),GetUnitY(u))
    call Inv_AddItem(u,i)
    // Do any neccecary operations on item after adding it..
    set u = null
    set i = null
endfunction
function Trig_RecipeAbility_Conditions takes nothing returns boolean
    return RecipeAbilityGetItem(GetSpellAbilityId())>0
endfunction
function Trig_RecipeAbility_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer id = GetSpellAbilityId()
    local item i
    local location loc
    local integer itemId
    
    if GetSpellTargetUnit()==u then
        call UseRecipe(u,id)
    else
        set loc = GetSpellTargetLoc()
        set itemId = RecipeAbilityGetItem(id)
        set i = CreateItem(itemId,0,0)
        call UnitRemoveAbility(u,ItemGetSB(itemId))
        if loc==null then
            call Inv_AddItem(GetSpellTargetUnit(),i)
        else
            call SetItemPosition(i,GetLocationX(loc),GetLocationY(loc))
            call RemoveLocation(loc)
            set loc = null
        endif
        set i = null
    endif
    
    set u = null
endfunction
function Trig_RecipeGet_Conditions takes nothing returns boolean
    return ItemGetSB(GetItemTypeId(GetManipulatedItem()))>0
endfunction
function Trig_RecipeGet_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item i = GetManipulatedItem()
    local integer id = ItemGetSB(GetItemTypeId(i))

    call RemoveItem(i)
    call UnitAddAbility(u,id)
    call SetPlayerAbilityAvailable(GetOwningPlayer(u),id,false)

    set u = null
    set i = null
endfunction
function InitRecipeSystem takes nothing returns nothing
    local trigger t1 = CreateTrigger()
    local trigger t2 = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ(t1,EVENT_PLAYER_UNIT_USE_ITEM)
    call TriggerRegisterAnyUnitEventBJ(t2,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    
    call TriggerAddCondition(t1,Condition(function Trig_RecipeGet_Conditions))
    call TriggerAddAction(t1,function Trig_RecipeGet_Actions)
    call TriggerAddCondition(t2,Condition(function Trig_RecipeAbility_Conditions))
    call TriggerAddAction(t2,function Trig_RecipeAbility_Actions)
endfunction
endlibrary
07-07-2008, 07:48 AM#2
Feroc1ty
Although after so many tries to make people stop using CSCache, people keep reverting back to it...
07-07-2008, 09:58 AM#3
chobibo
Quote:
Line 279: Symbol udg_cscache multiply defined
you have 2 variables called udg_cscache
Quote:
Line 15256: Missing requirement: CSCache (libraries cannot require scopes)
put CSCache inside a library
Collapse JASS:
library CSCache
endlibrary
07-07-2008, 10:38 AM#4
Ignitedstar
Quote:
Originally Posted by Feroc1ty
Although after so many tries to make people stop using CSCache, people keep reverting back to it...

I can't help it; Shadow's system uses CSCache, and only he is the one who can get it off of it. We don't have the right to change someone else's stuff without the original creator's permission.

Thanks, chobibo. I'll try that as soon as I can get on the computer in the afternoon. Can anyone confirm, in the mean time?
07-07-2008, 12:19 PM#5
chobibo
I'll try.
07-07-2008, 04:20 PM#6
Vexorian
You got to remove old CSCache, implement the newest one, and get rid of udg_ variables from the old one (wipe them from the GUI variable editor)
07-07-2008, 10:24 PM#7
Ignitedstar
Hmm... I just realized that CS15.2 is out; now CSCache is completely updated (and it compiles, fine, too). After I delete the old variables, all I need to do then is get the ones within CS15.2, or are those exclusive to the Caster System?

CSDamagers requires the Caster System, but since I don't plan on using CSDamagers anyhow, not including it would be okay, wouldn't it?

EDIT: It works perfectly. Wonderful! Thanks to Vex and chobibo.