• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Does anyone know how to make this light system MUI? +rep

Status
Not open for further replies.
Level 18
Joined
Jan 21, 2006
Messages
2,552
So you're looking for an overhaul of your system to make it more usable for the user. I noticed that your setup and examples are all in GUI however I do not use GUI, and whatever I do would be in vJass (and require JNGP) but you probably won't be disappointed.

Let me try to clarify some things.

This system I noticed is for a single torch carrier, which gives me a specific "sight" radius which is just a light model that is offset a certain amount from the position of the torch carrier. Did you want a system that would allow for many different "torch carriers" at any given time?

Also, what do you mean by "make the light radius bigger"? If it is just model work involved then that would be entirely up to a model editor (not a scripter). If all you want is to add more of the light units for more visibility then that can be accomplished.
 
Level 9
Joined
Jul 11, 2009
Messages
294
Yes i want it to be usable by different players.
and also make the visibility bigger.
But it would be better if anyone can do it in GUI,if not jass would be fine,but make it more understandable because i don't really know how to jass.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Okay but tell me what exactly do you mean by "make the visibility bigger"? There is no function that modifies models (other than animation changes) so it's pretty limited as to what the capabilities of the script will be.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Alright I'm working on something that allows it to be MUI.

Here's some preliminary code. It's written in vJass so you're going to need JNGP. You use that right?

JASS:
library TorchSystem

    //***************************************************************************
    // Torch Light
    // ¯¯¯¯¯¯¯¯¯¯¯
    // Provides a light radius for any given unit based on that unit's facing
    // rotation. Each torch is created by "torchlight.create()":
    //
    //      torchlight.create() --> takes a unit parameter
    //          @subject          > the unit that will acquire the light
    //
    // It will also be necessary to be able to acquire a specific unit's torch
    // in case special actions are to be performed, such as "kill" and "pause".
    //
    //      torchlight[]        --> takes a unit parameter
    //          @subject          > unit data used to obtain the appropriate 
    //                              torch
    //
    //      local torchlight torch
    //      call torchlight.create(udg_TempUnit)
    //
    //      //even though we do not have direct reference now, we can obtain it
    //      //by using the static method operator
    //      set torch = torchlight[udg_TempUnit]
    //      
    // The static method operator uses a loop that iterates through the entire
    // stack until finding the correct one. The more torches there are the slower
    // this will respond, obviously.
    //          
    // Each unit is only capable of acquiring one torch. If torches are created
    // multiple times for each unit, only the first that is added will remain the
    // other constructors will be ignored. 
    //
    struct torchlight
        private unit    subject = null
        private unit    torch   = null
        
        private static  timer               looptmr     = CreateTimer()
        private static  constant real       looptmrRef  = 0.033
        private         boolean             mkill       = false
        private         boolean             mpause      = false
        
        private static  thistype array      stack
        private static  unit array          stackref
        private static  integer             stacksize   = 0
        private         integer             stackindex
        
        private static  constant real       torchOffset = 300
        private static  constant integer    torchUnitId = 'hfoo'

        //this will allow torches to be referenced per unit. each unit will 
        //not be able to have multiple torches, and as such this can only 
        //return the unit-specific torch or a null struct (0).
        static method operator [] takes unit subject returns thistype
            local integer i=0
            loop
                exitwhen(i==stacksize)
                if(stackref[i]==subject) then
                    return stack[i]
                endif
                set i=i+1
            endloop
            return 0 //returns 0 if the unit has no torch.
        endmethod
        
        private method onDestroy takes nothing returns nothing
            set thistype.stacksize=thistype.stacksize-1
            set thistype.stack[stackindex]=thistype.stack[thistype.stacksize]
            set thistype.stack[stackindex].stackindex=stackindex
        
            call RemoveUnit(torch)
            if(thistype.stacksize==0) then
                call PauseTimer(thistype.looptmr)
            endif
        endmethod
        
        method kill takes nothing returns nothing
            set mkill=true
        endmethod
        method pause takes boolean flag returns nothing
            set mpause=flag
        endmethod
        
        static method loopFunc takes nothing returns nothing
            local integer i=stacksize-1
            local thistype data
            local real x
            local real y
            local real f

            loop
                exitwhen(i<=0)
                set data=stack[i]
                
                if(data!=0) then
                
                    if(data.mkill) then
                        //if the torch is to be destroyed then kill it before
                        //updating it's position.
                        call data.destroy()
                    elseif not(data.mpause) then
                        set f=GetUnitFacing(data.subject)
                        set x=GetUnitX(data.subject)        +Cos(f*bj_RADTODEG)
                        set y=GetUnitY(data.subject)        +Sin(f*bj_RADTODEG)
                        //the only thing necessary to adjust for the torch is the 
                        //position of the light emitter.
                        call SetUnitX(data.torch, x)
                        call SetUnitY(data.torch, y)
                    endif
                    
                endif
                set i=i-1
            endloop
        endmethod
        
        static method create takes unit subject returns thistype
            local thistype data
            local real x
            local real y
            local real f
            
            if(thistype[subject]!=0) then
                return 0
            endif
            set data=allocate()
            set x=GetUnitX(subject)
            set y=GetUnitY(subject)
            set f=GetUnitFacing(subject)
            
            if(stacksize==0) then
                call TimerStart(looptmr, looptmrRef, true, function thistype.loopFunc)
            endif
            set data.stackindex=stacksize
            set stackref[stacksize]=subject
            set stack[stacksize]=data
            set stacksize=stacksize+1
            
            set data.subject=subject
            set x=x+torchOffset*Cos(f*bj_DEGTORAD)
            set y=y+torchOffset*Sin(f*bj_DEGTORAD)
            set data.torch=CreateUnit(GetOwningPlayer(subject), torchUnitId, x, y, 0)
            
            return data
        endmethod
    endstruct

endlibrary

If you don't know how to use this directly then I could make some GUI code that allows you to use certain GUI actions to control what happens here. It wouldn't be very hard for you to use it yourself, though, through the custom script action.

The GUI interface would look something like this:

  • Untitled Trigger 001
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • Custom script: call torchlight.create(GetTriggerUnit())
  • Untitled Trigger 002
    • Events
      • Unit - A unit Finishes casting an ability
      • Unit - A unit Stops casting an ability
    • Conditions
    • Actions
      • Custom script: call torchlight[GetTriggerUnit()].kill()
There is a way of making it possible for you to use entirely GUI and still maintain the system, as I said before. Let's say you have a unit array and the size of said unit-array. Let's say for some reason you want to add a unit to that array, and have units within the array given a torch if they do not already have one.

  • Untitled Trigger 003
    • Events
    • Conditions
    • Actions
      • Set UnitArray[UnitArraySize] = (Triggering unit)
Now that the unit is in the array, we can use another trigger that can be executed to give a torch to units in the array that do not have one.

  • Untitled Trigger 004
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 0 to UnitArraySize, do (Actions)
        • Loop - Actions
          • Custom script: if(torchlight[udg_UnitArray[bj_forLoopAIndex]]==0) then
          • Custom script: call torchlight.create(udg_UnitArray[bj_forLoopAIndex])
          • Custom script: endif
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
You got it working? I hadn't even tested this yet it's just preliminary code that I was going to test and give to you, but if you got it working already then congrats.
 
Last edited:
Status
Not open for further replies.
Top