• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] The scripts don't work fine

Status
Not open for further replies.
Level 6
Joined
Jun 19, 2010
Messages
143
Hi,
I converted my map into vJass but there are many things don't work out in my map. I rewrote them all in proper way I think as I tried to optimize the map with as less bj as possible.
SetUnitColor
Deselect
TriggerRegisterEnterRegion
Since the map has library & scopes, so it'd be best if you could open it and check what's wrong with it and help me some tips to improve my writing.
Thank you.

Here's how it works in GUI, not perfectly but it can at least work. The Jass one is supposed to work like this but after many attempts I don't get it work yet. Please help.
 

Attachments

  • askforhelp1.1B[Jass].w3x
    839.3 KB · Views: 44
  • workinGUI.w3x
    914.4 KB · Views: 55
Last edited by a moderator:
Level 6
Joined
Jun 19, 2010
Messages
143
It's not corrupt. I have just opened the attachment and run it a test. You can open it with JNGP or any Jass editor, then just press Save button & press Test the map. Its vJass script should be saved one or couple of times before testing the map.
 
Level 6
Joined
Jun 19, 2010
Messages
143
I think you can get the GUI opened & test how the game should work but it'd be much better if optimized in vJass, so I copy all Jass script here for all of you to check, please help me, I really need your help. After writing a script I always save it and correct few errors. However, it's been 4 days I haven't figured out the problems even though I saved the maps very many times and no errors found, JassHelper saved all scripts successfully. What did make them not work?
Since the scripts are long. Please refer to the head of my thread to see the problem I am having. You can collapse the challenge parts since you can help me on them later, after those problems are solved.

JASS:
library Peon
    globals  
    constant integer PEONID='hpea'
    constant integer FILLEID='n001'
    constant integer TELEPORTID='ncop'
    constant integer SPIDERID='nnwa'
    constant integer SACREDHAUNTID='usap'
    constant integer DUMMYID='u007'
    constant integer GENERALEXPIREID='BTLF'
    constant integer FLAME1ID='ANfs'
    constant integer TARANTURAID='n00F'
    constant integer STORMBOLDNEUTRALID='ANsb'
    constant string FLAMESTRIKEID="flamestrike"
    constant string BREATHOFFIREID="breathoffire"
    constant string STAMPEDEID="stampede"
    constant string STATEFULLID="Abilities\\Spells\\Items\\AIhe\\AIheTarget.mdl"
    constant string FREEZINGBREATHID="Abilities\\Spells\\Undead\\FreezingBreath\\FreezingBreathTargetArt.mdl"
    unit array Peon
    unit TempUnit=null
    group Peon_grp=CreateGroup()
    integer whichPlayer=0
    endglobals
    public function PeonAkh takes unit whichUnit,integer color,real x,real y returns nothing
        local real z
        local effect fx=AddSpecialEffect(STATEFULLID,x,y)
        call DestroyEffect(fx)
        set fx=null
        if GetUnitState(whichUnit,UNIT_STATE_LIFE)<1 then
            call GroupRemoveUnit(Peon_grp,whichUnit)
            call CreateUnit(Player(10),PEONID,x,y,0)
            set whichUnit=bj_lastCreatedUnit
            call SetUnitColor(bj_lastCreatedUnit,GetPlayerColor(Player(color)))
            call GroupAddUnit(Peon_grp,bj_lastCreatedUnit) 
            else 
            set z=GetUnitState(whichUnit,UNIT_STATE_MAX_LIFE)
            call SetUnitState(whichUnit,UNIT_STATE_LIFE,z)
            call SetUnitX(whichUnit,x)
            call SetUnitY(whichUnit,y)
        endif
    endfunction
    public function CreateTimerWindow takes timer T,timerdialog T_WINDOW,string TIMERSTRING,real INTERVAL returns nothing
            set T_WINDOW=CreateTimerDialog(T)
            call TimerDialogSetTitle(T_WINDOW,TIMERSTRING)
            call TimerDialogDisplay(T_WINDOW,true)
            call TimerStart(T,INTERVAL,false,null)
    endfunction
endlibrary

JASS:
library Item
    globals
        integer array OrbofCorruption
        integer array OrbofDarkness
        integer array OrbofFire
        integer array OrbofFrost
        integer array OrbofLightning
        integer array OrbofSlow
        integer array OrbofVenoms
        integer array ShadowOrb
        integer array Claw
        integer array Gloves
        integer array HelmValor
        integer array HornCunning
        integer array Medalion
        integer array ArmorEmperor
        integer array FrostWym
        integer array TitanSword
        integer array Ring1
        integer array Ring2
        integer array Ring3
    endglobals
    public function removeItem takes unit u, integer itemID returns nothing
        local integer n=0
        local item indexItem
        loop
            set indexItem = UnitItemInSlot(u,n)
            if indexItem != null and GetItemTypeId(indexItem)==itemID then
                call UnitRemoveItem(u,indexItem)
                set n=6
            endif
            set n=n+1
            exitwhen n>6
        endloop
    endfunction
    public function GetInventoryIndexOfItemType takes unit u, integer itemID returns integer
        local integer n=1
        local item array indexItem
        local integer m=0
        loop
            set indexItem[n] = UnitItemInSlot(u,n)
            if indexItem[n] != null and GetItemTypeId(indexItem[n])==itemID then
                return m+1
            endif
            set n=n+1
            exitwhen n>6
        endloop
        return 0
    endfunction
    public function UnitHasItemOfType takes unit u,integer itemID returns boolean
        return GetInventoryIndexOfItemType(u,itemID)>0
    endfunction
endlibrary
Initilization
JASS:
scope INIT initializer initial   
    globals
    private constant integer TECH1ID='Repm'     //Backpack(NightElf)
    private constant integer TECH2ID='Rosp'     //Spiked Barricade
    private constant integer TECH3ID='Rufb'     //Freezing Breath
    private constant integer TECH4ID='Rucr'     //Creature Carapace
    private constant integer TECH5ID='Rupc'     //Disease Cloud
    private constant integer TECH6ID='Ruwb'     //Web      
    private constant integer POTIONSHOPID='h00P'
    private constant integer WORKSHOPID='h00G'
    private constant integer TECH_MAGICSENTRYID='Rhse'
    private constant integer TECHTREE='n000'
    private constant string DEATH="Decay Flesh"
    endglobals    
    function initial takes nothing returns nothing
        local real x=-2940
        local real y=-760
        local texttag t=CreateTextTag()        
//Hostile Player
        call SetPlayerTechResearched(Player(11),TECH2ID,3)
        call SetPlayerTechResearched(Player(11),TECH3ID,1)
        call SetPlayerTechResearched(Player(11),TECH4ID,3)
        call SetPlayerTechResearched(Player(11),TECH5ID,1)
        call SetPlayerTechResearched(Player(11),TECH6ID,1)
        call SetPlayerState(Player(11),PLAYER_STATE_GIVES_BOUNTY,1)
        call SetPlayerHandicapXP(Player(11),400.00)
        call SetPlayerColor(Player(11),PLAYER_COLOR_RED)
//Neutral Player
        call SetPlayerState(Player(10),PLAYER_STATE_RESOURCE_GOLD,1000)
        call SetPlayerState(Player(10),PLAYER_STATE_RESOURCE_LUMBER,1000)
        call SetPlayerTechResearched(Player(10),TECH1ID,1)
        call SetPlayerTechMaxAllowed(Player(10),1,TECHTREE)
        call SetUnitFacing(gg_unit_h005_0111,180)
//GameInterface
        call SetTextTagText(t,"|c00ff00ffTown Portal!",0)
        call SetTextTagPos(t,-7607,7344,0)        
        call SetTextTagColor(t,255,255,255,0)        
//Camera       
        call CameraSetupApply(gg_cam_Explorer,true, true)
        call SetCameraQuickPosition(x+250,y)
//Loop for multiplayer settings
        set whichPlayer=0        
        loop
            exitwhen whichPlayer>7
//Players Configuration           
            call SetPlayerHandicapXP(Player(whichPlayer),80.00)
            call SetPlayerTechResearched(Player(whichPlayer),TECH1ID,1)
            call SetPlayerTechResearched(Player(whichPlayer),TECH_MAGICSENTRYID,1)
            call SetPlayerTechMaxAllowed(Player(whichPlayer),1,POTIONSHOPID)
            call SetPlayerTechMaxAllowed(Player(whichPlayer),1,WORKSHOPID)
            call SetPlayerState(Player(whichPlayer),PLAYER_STATE_GIVES_BOUNTY,1)
            call SetPlayerAlliance(Player(10),Player(whichPlayer),ALLIANCE_SHARED_ADVANCED_CONTROL,true) 
//Peon creation            
            call CreateUnit(Player(10),PEONID,x+whichPlayer*40,y,0)
            set Peon[whichPlayer]=bj_lastCreatedUnit
            call SetUnitColor(bj_lastCreatedUnit,GetPlayerColor(Player(whichPlayer)))
            call SetUnitAnimation(bj_lastCreatedUnit,DEATH)
            call GroupAddUnit(Peon_grp,bj_lastCreatedUnit)             
//Game Interface
            set whichPlayer=whichPlayer+1
        endloop
        call ModifyGateBJ(bj_GATEOPERATION_OPEN,gg_dest_ATg3_0014)
        call ModifyGateBJ(bj_GATEOPERATION_OPEN,gg_dest_ATg1_0015)
    endfunction
endscope
JASS:
scope ItemVariable initializer itemload
    function itemload takes nothing returns nothing
     local integer n=1
        set OrbofCorruption[n]='ocor'
        set OrbofDarkness[n]='odef'
        set OrbofFire[n]='I010'
        set OrbofFrost[n]='I00Y'
        set OrbofLightning[n]='I00Z'
        set OrbofSlow[n]='oslo'
        set OrbofVenoms[n]='oven'
        set ShadowOrb[n] = 'sora'
        set Claw[n]='I016'
        set Gloves[n]='I015'
        set HelmValor[n]='I012'
        set HornCunning[n]='I013'
        set Medalion[n]='I014'
        set ArmorEmperor[n]='I01N'
        set FrostWym[n]='I00Q'
        set TitanSword[n]='I01M'
        set Ring1[n]='I00W'
        set Ring2[n]='I011'
        set Ring3[n]='I00V'
    //==============================================
        set n=n+1
        set OrbofCorruption[n] = 'I02F'
        set OrbofDarkness[n] = 'I029'
        set OrbofFire[n] = 'I020'
        set OrbofFrost[n] = 'I023'
        set OrbofLightning[n] = 'I026'
        set OrbofSlow[n] = 'I02I'
        set OrbofVenoms[n] = 'I02C'
        set ShadowOrb[n] = 'I02L'
        set Claw[n] = 'I02O'
        set Gloves[n] = 'I00K'
        set HelmValor[n] = 'I01R'
        set HornCunning[n] = 'I01W'
        set Medalion[n] = 'I01U'
        set ArmorEmperor[n] = 'I01T'
        set FrostWym[n] = 'I01Y'
        set TitanSword[n] = 'I02P'
        set Ring1[n] = 'I02S'
        set Ring2[n] = 'I02V'
        set Ring3[n] = 'I02U'
    //==============================================
        set n=n+1
        set OrbofCorruption[n] = 'I02G'
        set OrbofDarkness[n] = 'I02A'
        set OrbofFire[n] = 'I021'
        set OrbofFrost[n] = 'I024'
        set OrbofLightning[n] = 'I027'
        set OrbofSlow[n] = 'I02J'
        set OrbofVenoms[n] = 'I02D'
        set Gloves[n] = 'I01Q'
        set HelmValor[n] = 'I01S'
        set HornCunning[n] = 'I01X'
        set Medalion[n] = 'I01V'
        set ArmorEmperor[n] = 'I019'
        set FrostWym[n] = 'I01Z'
        set TitanSword[n] = 'I02Q'
        set Ring1[n] = 'I02T'
        set Ring2[n] = 'I02W'
        set Ring3[n] = 'I02X'
    //==============================================
        set n=n+1
        set OrbofCorruption[n] = 'I02H'
        set OrbofDarkness[n] = 'I02B'
        set OrbofFire[n] = 'I022'
        set OrbofFrost[n] = 'I025'
        set OrbofLightning[n] = 'I028'
        set OrbofSlow[n] = 'I02K'
        set OrbofVenoms[n] = 'I02E'
        set Gloves[n] = 'I00L'
    endfunction
endscope
JASS:
scope Deselection initializer Deselect
    function Des_Conditions takes nothing returns boolean
        local unit u=GetTriggerUnit()
        set whichPlayer=GetPlayerId(GetTriggerPlayer())
        if GetUnitTypeId(u)==PEONID then
            if Peon[whichPlayer]==u then 
                  call SelectUnit(u,false)
            endif
        endif
        set u=null
        return false
    endfunction
    function Deselect takes nothing returns nothing
        local trigger Des=CreateTrigger()
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(0),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(1),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(2),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(3),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(4),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(5),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(6),true)
        call TriggerRegisterPlayerSelectionEventBJ(Des,Player(7),true)
        call TriggerAddCondition(Des,Condition(function Des_Conditions))
        set Des=null
    endfunction
endscope

JASS:
scope x2
    function X2Con takes nothing returns boolean
        if GetUnitTypeId(GetEnteringUnit())==PEONID then
            call DisableTrigger(GetTriggeringTrigger())
            call CreateUnit(Player(11),SACREDHAUNTID,-4007,-1731,0)
            call SetDestructableInvulnerable(gg_dest_ATg2_0019,true)
        endif    
    return false   
    endfunction
    function X2 takes nothing returns nothing
        local trigger t=CreateTrigger()
        local region r=CreateRegion()
        local rect r1=Rect(-3350,-1180,-3300,-250)
        call RegionAddRect(r,r1)
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddCondition(t,Condition(function X2Con))        
        call RemoveRegion(r)
        set r=null
        set r1=null
        set t=null
    endfunction
//==========================EndX2============================
    function EndX2Con takes nothing returns boolean
        if GetUnitTypeId(GetDyingUnit())==SACREDHAUNTID then
            call SetDestructableInvulnerable(gg_dest_ATg2_0019,false)
            call DisableTrigger(GetTriggeringTrigger())
        endif
        return false
    endfunction
    function EndX2 takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(t,Player(11),EVENT_PLAYER_UNIT_DEATH,null)
        call TriggerAddCondition(t,Condition(function EndX2Con))        
        set t=null
    endfunction
endscope

JASS:
scope x3
    globals
        private group grp=CreateGroup()
    endglobals
    function X3Act takes nothing returns nothing
        local real x=-7100
        local real y=3660
        set whichPlayer=0
            loop
                exitwhen whichPlayer>7
                set x=x+whichPlayer*40
                call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
                set whichPlayer=whichPlayer+1
            endloop
            call DestructableRestoreLife(gg_dest_ATg2_0019,GetDestructableMaxLife(bj_lastCreatedDestructable),true)
            call ModifyGateBJ(bj_GATEOPERATION_CLOSE,gg_dest_ATg2_0019)
            call SetDestructableInvulnerable(gg_dest_ATg2_0019,true)
            call SetDestructableInvulnerable(gg_dest_ATg1_0020,true)
            call SetDestructableInvulnerable(gg_dest_ATg3_0018,true)
            call DisableTrigger( GetTriggeringTrigger())
    endfunction        
    function X3 takes nothing returns nothing
        local trigger t=CreateTrigger()       
        call TriggerRegisterDeathEvent(t,gg_dest_ATg2_0019)
        call TriggerAddAction(t,function X3Act)
        set t=null      
    endfunction
//============================EndX3=======================   
    function EndX3Act takes nothing returns nothing
        local unit FoG=null
        call GroupEnumUnitsInRange(grp,-7067,2590,1040.,null)
            loop
                set FoG=FirstOfGroup(grp)
                exitwhen FoG==null
                if GetOwningPlayer(FoG)==Player(11) then
                    call KillUnit(FoG)
                endif
                call GroupRemoveUnit(grp,FoG)
            endloop                
        call DisableTrigger(GetTriggeringTrigger())
    endfunction
    function EndX3 takes nothing returns nothing        
        local trigger t= CreateTrigger()
        call TriggerRegisterDeathEvent(t,gg_dest_ATg2_0013)
        call TriggerAddAction(t,function EndX3Act)
        set t=null
    endfunction
endscope
JASS:
scope x4
    globals
    private trigger tr
    endglobals
    function X4Con takes nothing returns boolean
        local real x=-6760
        local real y=525
        if GetUnitTypeId(GetEnteringUnit())==PEONID and IsTriggerEnabled(GetTriggeringTrigger())==true then
            call DisableTrigger(GetTriggeringTrigger())
            set whichPlayer=0
            loop
                exitwhen whichPlayer>7
                set y=y+whichPlayer*40
                call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
                set whichPlayer=whichPlayer+1
            endloop
            call ModifyGateBJ(bj_GATEOPERATION_CLOSE,gg_dest_ATg3_0014 )
            call SetDestructableInvulnerable(gg_dest_ATg3_0014,true)
            call CreateUnit(Player(11),SPIDERID,-7365,710,0)
            set TempUnit=bj_lastCreatedUnit
            call IssuePointOrder(TempUnit,STAMPEDEID,x,y)        
        endif
        return false
    endfunction
    function X4 takes nothing returns nothing
        local trigger t=CreateTrigger()
        local region r=CreateRegion()
        local rect r1=Rect(-6760,525,-6710,1070)
        call RegionAddRect(r,r1)
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddCondition(t,Condition(function X4Con))    
        call RemoveRegion(r)
        set r=null
        set r1=null
        set t=null
    endfunction
//===========================ClosingX4=============================
    function EndX4Con takes nothing returns boolean
        if GetUnitTypeId(GetTriggerUnit())==SPIDERID then
            call DisableTrigger(GetTriggeringTrigger())
            call CreateUnit(Player(10),TELEPORTID,-7860,55,0)
            set TempUnit=null
            call EnableTrigger(tr)
        endif
        return false
    endfunction
    function EndX4 takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterDeathEvent(t,TempUnit)
        call TriggerAddCondition(t,Condition(function EndX4Con))
        set t=null
    endfunction
//========================EndX4=======================
    function X425Con takes nothing returns boolean
        local real x=-4600
        local real y=-2000
        if GetUnitTypeId(GetEnteringUnit()) ==PEONID and IsTriggerEnabled(tr)==true then
            call DisableTrigger(tr)
            set tr=null
            set whichPlayer=0
            loop
                exitwhen whichPlayer>7
                set y=y+whichPlayer*40
                call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
                set whichPlayer=whichPlayer+1
            endloop            
            call SetDestructableInvulnerable(gg_dest_ATg1_0020,false)
            call SetDestructableInvulnerable(gg_dest_ATg3_0018,false)            
        endif
        return false
    endfunction
    function X428 takes nothing returns nothing
        local region r=CreateRegion()
        local rect r1=Rect(-7910,0,-7810,110)
        set tr= CreateTrigger()  
        call RegionAddRect(r,r1)
        call DisableTrigger(tr)
        call TriggerRegisterEnterRegion(tr,r,null)
        call TriggerAddCondition(tr,Condition(function X425Con))    
        call RemoveRegion(r)
        set r=null
        set r1=null
    endfunction   
endscope
JASS:
scope x5
    globals
        private constant string TIMERSTRING="|c00ffff80Challenge Time"
        private timer         T             = CreateTimer()
        private timerdialog   T_WINDOW      
        private real          INTERVAL      = 50.
        private constant integer FIRELORD='Nalc'
        private group grp=CreateGroup()
        private trigger t
        private trigger tr
        private trigger bf
     endglobals
    function X5Con takes nothing returns boolean
        local real x=-5600
        local real y=2455
        local real z  
        local effect fx
        if GetUnitTypeId(GetEnteringUnit())==PEONID and IsTriggerEnabled(GetTriggeringTrigger())==true then
            set whichPlayer=0        
            loop
                exitwhen whichPlayer>7
                set z=GetUnitState(Peon[whichPlayer],UNIT_STATE_MAX_LIFE)
                call SetUnitState(Peon[whichPlayer],UNIT_STATE_LIFE,z)
                set x=x+whichPlayer*40
                call SetUnitX(Peon[whichPlayer],x)             
                call SetUnitY(Peon[whichPlayer],y)
                set fx=AddSpecialEffect(STATEFULLID,x,y)
                call DestroyEffect(fx)
                set fx=null
                set whichPlayer=whichPlayer+1
            endloop
            call EnableTrigger(tr)
            call ModifyGateBJ( bj_GATEOPERATION_CLOSE, gg_dest_ATg1_0015 )
            call SetDestructableInvulnerable( gg_dest_ATg1_0015,true )
            set T_WINDOW=CreateTimerDialog(T)
            call TimerDialogSetTitle(T_WINDOW,TIMERSTRING)
            call TimerDialogDisplay(T_WINDOW,true)
            call TimerStart(T,INTERVAL,false,null)
            call DisableTrigger(GetTriggeringTrigger())
        endif
        return false
    endfunction
    function X5 takes nothing returns nothing
        local region r=CreateRegion()
        local rect r1=Rect(-5620,2380,-4880,2500)
        set t=CreateTrigger()
        call RegionAddRect(r,r1)
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddCondition(t,Condition(function X5Con))    
        call RemoveRegion(r)
        set r=null
        set r1=null
    endfunction
//==========================AUTO-BACKFIRE=======================
    function BackFire_Con takes nothing returns boolean
        local integer m=0
        local integer n=GetRandomInt(0,7)
        local real x
        local real y
        if GetUnitTypeId(GetAttacker())==FIRELORD then
            set m=m+1
            if m==10 then
                set m=0
                set n=GetRandomInt(0,7)
                set x=GetUnitX(Peon[n])
                set y=GetUnitY(Peon[n])
                call IssuePointOrder(GetAttacker(),BREATHOFFIREID,x,y)
                call IssuePointOrder(GetAttacker(),FLAMESTRIKEID,x,y)
            endif
        endif
    return false
    endfunction
    function AutoBackFire takes nothing returns nothing
    set bf=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(bf,EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(bf,Condition(function BackFire_Con))
    endfunction
//=========================EndX5==========================
    function EndX5Con takes nothing returns boolean
        local unit FoG=null 
        if IsTriggerEnabled(tr)==true then
            call DestroyTimerDialog(T_WINDOW)
            call DisableTrigger(bf)
            set bf=null
            call GroupEnumUnitsInRect(grp,bj_mapInitialPlayableArea,null)
            loop
                set FoG=FirstOfGroup(grp)
                exitwhen FoG==null
                if GetUnitTypeId(FoG)==FIRELORD then
                    call KillUnit(FoG)
                endif
                    call GroupRemoveUnit(grp,FoG)
            endloop      
            call ModifyGateBJ(bj_GATEOPERATION_OPEN,gg_dest_ATg1_0015)
            call DisableTrigger(t) 
            call DisableTrigger(GetTriggeringTrigger()) 
        endif
    return false
    endfunction
    function EndX5 takes nothing returns nothing
        local trigger tr= CreateTrigger()        
        call TriggerRegisterTimerExpireEvent(tr,T)
        call TriggerAddCondition(tr,Condition(function EndX5Con))
        set t=null
        set tr=null        
    endfunction
endscope
JASS:
scope x6
     globals
        private constant string TIMERSTRING="|c00ffff80Challenge Time"
        private timer         T             = CreateTimer()
        private timerdialog   T_WINDOW      
        private real          INTERVAL      = 60.
    endglobals
//================trigger t=X6Flame===========
    function flame takes nothing returns nothing
        local real x
        local real y
        loop
        set x=GetRandomReal(-4310,-2805)
        set y=GetRandomReal(1720,3300)
        exitwhen x+y>-2585
        endloop
        call CreateUnit(Player(11),DUMMYID,x,y,0)
        call UnitApplyTimedLife(bj_lastCreatedUnit,GENERALEXPIREID,3.)
        call UnitAddAbility(bj_lastCreatedUnit,FLAME1ID)
        call IssuePointOrder(bj_lastCreatedUnit,FLAMESTRIKEID,x,y)
    endfunction
//================trigger tr=EndX6============
    function X6 takes nothing returns nothing
        local real x=-3553
        local real y=2424
        local trigger t=CreateTrigger()
        local destructable dest 
        call TriggerRegisterDeathEvent(t,gg_dest_ATg4_0016)
        set dest=gg_dest_ATg4_0016
        set whichPlayer=0
        loop
            exitwhen whichPlayer>7
            set x=x-whichPlayer*8
            set y=y-whichPlayer*8
            call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
            set whichPlayer=whichPlayer+1
        endloop
        call DestructableRestoreLife(dest,GetDestructableMaxLife(dest),false)
        call ModifyGateBJ(bj_GATEOPERATION_CLOSE,dest)
        call SetDestructableInvulnerable(dest,true)
        call Peon_CreateTimerWindow(T,T_WINDOW,TIMERSTRING,INTERVAL)
//Flame Creation
        call TimerStart(T,1.8,true,function flame)
        call TriggerSleepAction(INTERVAL)
        call DestroyTimerDialog(T_WINDOW)
        call DestroyTimer(T)
        set T=null
        call DisplayTextToPlayer(GetLocalPlayer(),0,0,"|c00ffff00Done!|r")
        call ModifyGateBJ(bj_GATEOPERATION_OPEN,gg_dest_ATg4_0016)
        set t=null
    endfunction
endscope
JASS:
scope x7    
    globals
    private constant integer SMALLSPIDERID='nspr'
    private constant integer SPIDERSPLITID='ncop'
    private constant integer SPIDEREFFECTID='u00A'
    private constant integer SPIDEREGGID='h006'
    private constant integer MOONKEYID='kymn'
    endglobals
    function X7Con takes nothing returns boolean
        local real x=-3530
        local real y
        if GetUnitTypeId(GetEnteringUnit())==PEONID and IsTriggerEnabled(GetTriggeringTrigger())==true then
            set whichPlayer=0
            loop
                exitwhen whichPlayer>7
                set y=I2R(whichPlayer)*8+450
                call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
                set whichPlayer=whichPlayer+1
            endloop
            set x=GetRandomReal(-2350,-2700)
            set y=GetRandomReal(400,900)
            call CreateUnit(Player(11),TARANTURAID,x,y,bj_UNIT_FACING)
            set TempUnit=bj_lastCreatedUnit 
            call DestructableRestoreLife(gg_dest_ATg3_0018,GetDestructableMaxLife(gg_dest_ATg3_0018),false )
            call ModifyGateBJ(bj_GATEOPERATION_CLOSE,gg_dest_ATg3_0018)
            call SetDestructableInvulnerable(gg_dest_ATg3_0018,true)
            call DisableTrigger(GetTriggeringTrigger())
        endif
    return false
    endfunction    
    function X7 takes nothing returns nothing
        local trigger t=CreateTrigger()
        local region r=CreateRegion()
        local rect r1=Rect(-3630,450,-3530,1100)
        call RegionAddRect(r,r1)
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddCondition(t,Condition(function X7Con))    
        call RemoveRegion(r)
        set r=null
        set r1=null
        set t=null
    endfunction
//=========================Spider Birth=====================
    function EggBirth takes nothing returns nothing
        local widget dest
        set dest=GetTriggerWidget()
        call CreateUnit(Player(11),SMALLSPIDERID,GetWidgetX(dest),GetWidgetY(dest),0)
        call IncUnitAbilityLevel(TempUnit,SPIDERSPLITID)
        set dest=null
    endfunction
    function SpiderEgg takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterDeathEvent(t,gg_dest_DTes_0001)
        call TriggerRegisterDeathEvent(t,gg_dest_DTes_0000)
        call TriggerRegisterDeathEvent(t,gg_dest_DTes_0003)
        call TriggerRegisterDeathEvent(t,gg_dest_DTes_0004)
        call TriggerAddAction(t,function EggBirth)
        set t=null
    endfunction
//========================Spider Spawn======================
    function Spawning takes nothing returns boolean
        local real x
        local real y
        local real x1
        local real y1
        local real angle=0
        local real dist=320
        local integer n=GetRandomInt(0,10)
        if GetUnitTypeId(GetAttacker())==TARANTURAID and n==0 then
        set x=GetUnitX(GetAttacker())
        set y=GetUnitY(GetAttacker())
        loop
            set angle=angle+60*n
            set x1=x+dist*Cos(angle*bj_DEGTORAD)
            set y1=y+dist*Sin(angle*bj_DEGTORAD)
            exitwhen n>5
            call CreateUnit(Player(11),SPIDEREFFECTID,x,y,0)
            call UnitApplyTimedLife(bj_lastCreatedUnit,GENERALEXPIREID,5)
            call IssuePointOrder(bj_lastCreatedUnit,"attackground",x1,y1)
            call CreateUnit(Player(11),SPIDEREGGID,x1,y1,0)
            set n=n+1
        endloop
        endif
    return false
    endfunction
    function Spawn takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddCondition(t,Condition(function Spawning))
        set t=null
    endfunction
//========================Tarantura dies=====================
    function TaranturaDeath takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterDeathEvent(t,TempUnit)
        call CreateItem(MOONKEYID,GetUnitX(GetDyingUnit()),GetUnitY(GetDyingUnit()))
        call SetDestructableInvulnerable(gg_dest_ATg3_0018, false )
        call DisableTrigger(GetTriggeringTrigger())
        set t=null
    endfunction
endscope
JASS:
scope x8
    globals
    private group grp=CreateGroup()
    private effect array fx
    endglobals
    function X8 takes nothing returns nothing
        local trigger t=CreateTrigger()
        local real x=-4590
        local real y=-1900
        call TriggerRegisterDeathEvent(t,gg_dest_ATg1_0020)
        set whichPlayer=0
        loop
            exitwhen whichPlayer>7
            set y=y+whichPlayer*40
            call Peon_PeonAkh(Peon[whichPlayer],whichPlayer,x,y)
            set whichPlayer=whichPlayer+1
        endloop
        set t=null
    endfunction 
    function Killa takes nothing returns boolean
        local real x
        local real y
        local unit u
        local real z
        if GetUnitTypeId(GetEnteringUnit())==PEONID then
            if fx[GetPlayerId(GetTriggerPlayer())]!=null then
                    call DestroyEffect(fx[GetPlayerId(GetTriggerPlayer())])
                    set fx[GetPlayerId(GetTriggerPlayer())]=null
            endif
            set u=GetEnteringUnit()
            set x=GetUnitX(u)
            set y=GetUnitY(u)
            set z=GetUnitState(u,UNIT_STATE_MAX_LIFE)
            call SetUnitState(u,UNIT_STATE_LIFE,z*0.6)
            call CreateUnit(Player(11),DUMMYID,x,y,0)
            call UnitApplyTimedLife(bj_lastCreatedUnit,GENERALEXPIREID,3.)
            call UnitAddAbility(bj_lastCreatedUnit,STORMBOLDNEUTRALID)
            call IssueTargetOrder(bj_lastCreatedUnit,"thunderbolt",u)
            set fx[GetPlayerId(GetTriggerPlayer())]=AddSpecialEffect(FREEZINGBREATHID,x,y)   
        endif
    return false
    endfunction
    function WrongWay takes nothing returns nothing
        local trigger t=CreateTrigger()
        local region r=CreateRegion()
        local rect r1=Rect(-5910,-2160,-4850,-2070)
        local rect r2=Rect(-5910,-2040,-5660,-1513)
        local rect r3=Rect(-5910,-1013,-5740,-1513)
        local rect r4=Rect(-5910,-1100,-5330,-1025)
        local rect r5=Rect(-5910,-1785,-4985,-1370)
        local rect r6=Rect(-5085,-1490,-4580,-1037)
        call RegionAddRect(r,r1)
        call RegionAddRect(r,r2)
        call RegionAddRect(r,r3)
        call RegionAddRect(r,r4)
        call RegionAddRect(r,r5)
        call RegionAddRect(r,r6)
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddCondition(t,Condition(function Killa))        
        call RemoveRegion(r)
        set r=null
        set r1=null
        set r2=null
        set r3=null
        set r4=null
        set r5=null
        set r6=null
        set t=null
    endfunction 
    function EndX8Action takes nothing returns nothing
        local unit FoG=null
        set whichPlayer=0
        loop
            exitwhen whichPlayer>7
            call DestroyEffect(fx[whichPlayer])
            set whichPlayer=whichPlayer+1
        endloop
        call GroupEnumUnitsInRange(grp,-5210,-1590,850.,null)
            loop
                set FoG=FirstOfGroup(grp)
                exitwhen FoG==null
                if GetOwningPlayer(FoG)==Player(11) then
                    call KillUnit(FoG)
                endif
                call GroupRemoveUnit(grp,FoG)
            endloop           
    endfunction
    function EndX8 takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterDeathEvent(t,gg_dest_ATg1_0020)
        call TriggerAddAction(t,function EndX8Action)
        set t=null
    endfunction
endscope

JASS:
scope ringswap
    globals
    private constant integer MECHANICALCRITTERID='Amec'
    endglobals
    function RingSwapCon takes nothing returns boolean
        local unit u
        local integer n=0
        local integer itemID
        if GetSpellAbilityId()==MECHANICALCRITTERID then
            set u=GetTriggerUnit()
            set itemID=Ring1[3]
            if Item_UnitHasItemOfType(u,itemID)==true then
                call Item_removeItem(u,itemID)
                call UnitAddItemById(u,Ring2[3])
                return true
            endif            
            set itemID=Ring2[3]
            if Item_UnitHasItemOfType(u,itemID)==true then
                call Item_removeItem(u,itemID)
                call UnitAddItemById(u,Ring3[3])
                return true
            endif 
            set itemID=Ring3[3]
            if Item_UnitHasItemOfType(u,itemID)==true then
                call Item_removeItem(u,itemID)
                call UnitAddItemById(u,Ring1[3])
                return true
            endif  
        endif
    return false
    endfunction
    function RingSwap takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
        call TriggerAddCondition(t,Condition(function RingSwapCon))
        set t=null
    endfunction
endscope
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
how do you expect that to work..?\

first of all, your init triggers are never run because they are not listed under initializer in the scope definiton. Second, you null the trigger. That just deletes everything,..
 
Second, you null the trigger. That just deletes everything,..

-->I don't think so because he only nulls the pointer/variable... the trigger is already there and the conditions are saved already so no problems with that... and I do it too sometimes when I'm not lazy to write t = null, and haven't encountered any problems...

and actually you do need to do that t = null or the local variable will leak...

I agree with the first one... and I thought scopes without initializer statement are not compiled? I never realized it has changed already...
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
before it is corrupted now I can open it, sad to say its really not worth the effort to rearrange this, why?...
1) Your pointers are a mess, coz instead of making it simple to just declare the raw codes, your making a global from a library...
sample:
PEONID, should be declared inside the Deselection code like >>> 'hpea', why?, coz it's readable...
SACREDHAUNTID, should be just 'usap', and so on...

2) You have not indicated a scope uses 'WHAT' library, so its difficult to the coder to find which is which...

3) Your initializers may not work properly coz maybe the other runs first before the other, but you need the last one to run first,
coz in your GUI, you have only 1 initializer, in jass you have 4...

4) You have to tell us first what is the problem of your script and what it does, one by one, then we'll help...and lastly, dont double post...
 
Level 6
Joined
Jun 19, 2010
Messages
143
Hi,
Thank you for your replies.
mind telling us what exactly happens?
It happens to create 8 peasants for player(10) which is just fine in the map when running a test but the peasants' colors are supposed to be changed into red,blue,teal,...(playercolor),
tell us first what is the problem of your script and what it does, one by one
in the game they are still all dark green(player10color). Player 10 must share all units control in its alliance setting set by calling SetPlayerAlliance but this didn't work too.

TriggerRegisterEnterRegion in GameChallenge 2, a torch to fire all functions in GameChallenge2, didn't work.

As I'm advised lately about this, it seems I must delete this row call RemoveRegion(r) to get the event work, then in the actions maybe I can RemoveRegion, because I only wish it to happen one time once any peasant enters the region or come across it, the first peasant is enough, trigger must be disabled to prevent the other peasants come into the region.

@mckill: all global variables defined by different libraries will be moved to the first of the long script by JassHelper. Why pointers are messy and 'uses a library' is needed to be put besides scope if all global variables are defined?
you mean making the scope use the library like these?

scope INIT uses Peon initializer initial
scope x2 uses Peon
I want scope x2(Challenge 2 in game) not to fire at map initialization, it only fires when a peasant comes across the region in it.
Must all scopes have initializer as for calling an event function to work?
 
Last edited:
Level 29
Joined
Mar 10, 2009
Messages
5,016
I forgot to tell you that your trigger doesnt run coz you dont have initializers for;
function X2, function EndX2, function EndX3 and many more...

If you dont want to run X2, etc..., then create a condition for it, but let it have initializers so that the trigger will be called...

@mckill: all global variables defined by different libraries will be moved to the first of the long script by JassHelper. Why pointers are messy and 'uses a library' is needed to be put besides scope if all global variables are defined?
you mean making the scope use the library like these?
I know that but the object editor raw codes is already global ones, so why create some extra?...
sample in your Deselection code should be something like this, easy to read...
JASS:
scope Deselection initializer Deselect
    function Des_Conditions takes nothing returns boolean
        local unit u=GetTriggerUnit()
        if GetUnitTypeId(u)=='hpea' then
            if GetOwningPlayer(u)==Player(GetPlayerId(GetTriggerPlayer())) then 
                call SelectUnit(u, true)
            else
                call SelectUnit(u, false)
            endif
        endif
        set u=null
        return false
    endfunction
    
    function Deselect takes nothing returns nothing
        local trigger Des=CreateTrigger()
        local integer i = 11
        loop
            call TriggerRegisterPlayerUnitEvent(Des, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            exitwhen i==0
            set i = i - 1            
        endloop
        call TriggerAddCondition(Des,Condition(function Des_Conditions))
        set Des=null
    endfunction
endscope

scope INIT uses Peon initializer initial
scope x2 uses Peon
I want scope x2(Challenge 2 in game) not to fire at map initialization, it only fires when a peasant comes across the region in it.
Must all scopes have initializer as for calling an event function to work?
You cant do that, only libraries require *something*

I mean like this, so that coders can know 'quickly' that a particular function uses WHAT library, else he will look all the 4 libraries for it...
JASS:
scope Deselection initializer Deselect
//uses Peon

endscope
 
Level 6
Joined
Jun 19, 2010
Messages
143
Must all scopes have initializer as for calling an event function to work?

It seems that challenge 3 must be divided into 2 scopes to have every initializer for each event function. I changed the name of the library since unit array Peon & library Peon make confusion. now library is unitlib.

I'll make the initializer for challenge 2,3,4 & the rest. Everyone, please discuss further to the problem. It seems the problems are tough in function 'initial', the function works but as I mentioned the color changing & SetPlayerAlliance functions didn't work. I doubt the last created unit isn't stored into the unit group Peon_grp either.
 
Last edited:
Status
Not open for further replies.
Top