• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Turn Jass trigger on\off by GUI trigger

Status
Not open for further replies.
Level 4
Joined
Jun 19, 2010
Messages
113
first of all - i'm not understand anything in Jass

i'm currently working on single player RPG (10% done)
and i used custom game cam, maked by YourNameHere

Here is the request: i need to switch this cam on\off by simple GUI trigger.(for cinematic, example)
you can try this - set a condition, based on variable. if true, trigger runs. if false - trigger not affect game cam. pfff.. i dont know.


that what YourNameHere write in thread with system http://www.hiveworkshop.com/forums/spells-569/cam-system-v3-144480/?prev=search=3d%20cam&d=list&r=20

YourNameHere said:
You really dont need any great JASS knowledge here.
Just do a trigger that fires on the chatmessage or spell cast, and do

JASS:
call CamSwitch(GetPlayerId(GetTriggerPlayer()))
for the chatmessage or

JASS:
call CamSwitch(GetPlayerId(GetOwningPlayer(GetTriggerUnit())))
for the spell cast. And you're done.
one problem: what da hell? what is this? lol
added: this doesn't work

here is the code
JASS:
//! zinc

    library CameraSystem requires optional CameraKeyboardMovement
    {
        //////////////////////////////////////////////////////////////////////////
        //
        //      Configuration area
        
        //          - Just default variables which the system will use when no other ones are specified by the user.
        constant    real    CAMERA_DEFAULT_X        =   0,
                            CAMERA_DEFAULT_Y        =   0,
                            CAMERA_DEFAULT_ZANGLE   =   350,
                            CAMERA_DEFAULT_ZHEIGHT  =   190,
                            CAMERA_DEFAULT_ROTATION =   0,
                            CAMERA_DEFAULT_DISTANCE =   175,
                            
        //          - This is tricky. It defines the weight the measurements of the z position have. This system measures
        //            out 4 locations to get a neat z height, 2 of them are at the unit's location and 2 are at the camera
        //            location which is a bit further away. Those values define which measure has more weight - if you have
        //            low terrain with less cliff heights you should probably give the unit's measurement more weight.
        //            If you don't understand a bit of what I'm trying to explain, just play around a bit with those values
        //            and look what effect they might have.
                            CAMERA_TARGET_WEIGHT    =   1,
                            CAMERA_CAMERA_WEIGHT    =   2 - CAMERA_TARGET_WEIGHT,
        //          - What difference the measures have, if you have really steep cliffs (I'm not talking about blizzard cliffs)
        //            you should probably decrease this.
                            CAMERA_ZDIST_MEASURE    =   50,
                            
        //          - Pretty much self-explaining. You don't really have to change anything here.
                            CAMERA_LOOP_INTERVAL    =   0.01,
                            CAMERA_UPDATE_INTERVAL  =   0.2;
        //////////////////////////////////////////////////////////////////////////
        //
        //      Struct area
        
        public struct CAMERA
        {
        
        //////////////////////////////////////////////////////////////////////////
        //
        //      Struct variable area
        
            public
            {
                real x = CAMERA_DEFAULT_X, y = CAMERA_DEFAULT_Y,
                     zAngle = CAMERA_DEFAULT_ZANGLE, zHeight = CAMERA_DEFAULT_ZHEIGHT,
                     rotation = CAMERA_DEFAULT_ROTATION, distanceToTarget = CAMERA_DEFAULT_DISTANCE;
                
                player applyFor = null;
                unit   toFollow = null;
            }
            
            private
            {
                integer node;
                boolean activated = false;
            
                static timer t = CreateTimer();
                static integer count = 0;
                static thistype data[];
                
                static location loc = Location(0,0);
            }
            
            optional module CameraKeyboardMovement;
            
        //////////////////////////////////////////////////////////////////////////
        //
        //      Struct method area
            
            static method create(player p) -> thistype
            {
                thistype this = thistype.allocate();
                applyFor = p;
                static if (thistype.movementInit.exists) { movementInit(); }
                return this;
            }
            
            method apply()
            {
                if (count == 0)
                    TimerStart(t, CAMERA_LOOP_INTERVAL, true, static method thistype.cameraLoop);
                    
                data[count] = this;
                node = count;
                count += 1;
                
                activated = true;
            }
            
            private static method cameraLoop()
            {
                real tX = 0, tY = 0, tZ[], tzAngle = 0, tzHeight = 0, tRotation = 0;
                thistype this;
                integer i = 0;
                
                while (i < count)
                {
                    this = data[i];
                    static if (thistype.movement.exists) { movement(); }
                    
                    if (toFollow != null)
                    {
                        x = GetUnitX(toFollow); y = GetUnitY(toFollow);
                        tRotation = GetUnitFacing(toFollow)*bj_DEGTORAD;
                        tzHeight = GetUnitFlyHeight(toFollow);
                    }
                    
                    tX = x; tY = y;
                    
                    tX += CAMERA_ZDIST_MEASURE/2 * Cos(tRotation);
                    tY += CAMERA_ZDIST_MEASURE/2 * Sin(tRotation);
                    MoveLocation(loc, tX, tY);
                    tZ[0] = GetLocationZ(loc);
                    
                    tX -= CAMERA_ZDIST_MEASURE * Cos(tRotation);
                    tY -= CAMERA_ZDIST_MEASURE * Sin(tRotation);
                    MoveLocation(loc, tX, tY);
                    tZ[1] = GetLocationZ(loc);
                    
                    tX = GetCameraTargetPositionX() + CAMERA_ZDIST_MEASURE/2 * Cos(tRotation);
                    tY = GetCameraTargetPositionY() + CAMERA_ZDIST_MEASURE/2 * Sin(tRotation);
                    MoveLocation(loc, tX, tY);
                    tZ[2] = GetLocationZ(loc);
                    
                    tX -= CAMERA_ZDIST_MEASURE * Cos(tRotation);
                    tY -= CAMERA_ZDIST_MEASURE * Sin(tRotation);
                    MoveLocation(loc, tX, tY);
                    tZ[3] = GetLocationZ(loc);
                    
                    tZ[2] = ((tZ[0]-tZ[1])*CAMERA_TARGET_WEIGHT+(tZ[2]-tZ[3])*CAMERA_CAMERA_WEIGHT)/4;
                    
                    tX = x; tY = y;
                    
                    tRotation += rotation*bj_DEGTORAD;
                    tX -= (distanceToTarget+tZ[2]) * Cos(tRotation);
                    tY -= (distanceToTarget+tZ[2]) * Sin(tRotation);
                    MoveLocation(loc, tX, tY);
                    
                    tzAngle = zAngle + tZ[2];
                    tzHeight += zHeight + GetCameraField(CAMERA_FIELD_ZOFFSET) + GetLocationZ(loc) + RAbsBJ(tZ[2]) - GetCameraEyePositionZ();
                    
                    if (GetLocalPlayer() == applyFor)
                    {
                        PanCameraToTimed(tX, tY, CAMERA_UPDATE_INTERVAL);
                        SetCameraField(CAMERA_FIELD_ZOFFSET, tzHeight, CAMERA_UPDATE_INTERVAL);
                        SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, tzAngle, CAMERA_UPDATE_INTERVAL);
                        SetCameraField(CAMERA_FIELD_ROTATION, tRotation*bj_RADTODEG, CAMERA_UPDATE_INTERVAL);
                        SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, distanceToTarget+tZ[2], CAMERA_UPDATE_INTERVAL);
                    }
                    
                    i += 1;
                }
            }
            
            method operator active() -> boolean
                { return activated; }
            
            method operator active=(boolean b)
            {
                if (b && !activated)
                    apply();
                else if (!b && activated)
                {
                    data[node] = data[count-1];
                    data[node].node = node;
                    count -= 1;
                    
                    if (count == 0)
                        PauseTimer(t);
                        
                    activated = false;
                }
            }
            
            method destroy()
            {
                if (activated)
                {
                    data[node] = data[count-1];
                    data[node].node = node;
                    count -= 1;
                    
                    if (count == 0)
                        PauseTimer(t);
                }
                
                deallocate();
            }
        }
    }

//! endzinc

JASS:
//! zinc

    library CameraKeyboardMovement
    {
    
        //CONFIGURABLES
            //How much a unit should turn around when pressing left/right. Leave the * bj_DEGTORAD, or it won't work.
            //Default is the unit's turn speed, if you want to leave that, just set TURN_ANGLE to 0.
            constant real    TURN_ANGLE      = 0 * bj_DEGTORAD;
            //Animation that the unit get's when no key is pressed.
            constant string  ANIM_STOP       = "stand";
            //Default animation of a unit if none is found.
            constant integer ANIM_DEFAULT    = 5;
            
            //Same for this library, because the cam variables are private. (And should stay so)
            constant real    LOOP_INTERVAL   = 0.01,
                             UPDATE_INTERVAL = 0.2;
            
            function CanUnitMove(unit who) -> boolean
            {
                return UnitAlive(who) && !IsUnitPaused(who) && !(GetUnitAbilityLevel(who, 'Bens') > 0) && /*
                  */!(GetUnitAbilityLevel(who, 'Bena') > 0) && !(GetUnitAbilityLevel(who, 'Beng') > 0)     && /*
                  */!(GetUnitAbilityLevel(who, 'BSTN') > 0) && !(GetUnitAbilityLevel(who, 'BPSE') > 0);
            }
        //CONFIGURABLES
    
        CAMERA TriggerCam = -1;
        public CAMERA PlayerCameras[];
        
        public function GetTriggerCam() -> CAMERA
        {
            return TriggerCam;
        }
    
        public module CameraKeyboardMovement
        {
            integer animationIndex = ANIM_DEFAULT;
            real animationDur = 0;
        
            private
            {
                boolean upPressed, downPressed, rightPressed, leftPressed, playAnimation;
                trigger onKeyEvent;
                
                real animationCount = 0;
            }
        
            method movementInit()
            {
                upPressed = false; downPressed = false; rightPressed = false; leftPressed = false; playAnimation = false;
                
                onKeyEvent = CreateTrigger();
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_UP_DOWN);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_UP_UP);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_DOWN_DOWN);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_DOWN_UP);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_RIGHT_DOWN);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_RIGHT_UP);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_LEFT_DOWN);
                TriggerRegisterPlayerEvent(onKeyEvent, applyFor, EVENT_PLAYER_ARROW_LEFT_UP);
                
                PlayerCameras[GetPlayerId(applyFor)] = this;
                
                registerKeyEvent(function()
                {
                    TriggerCam = PlayerCameras[GetPlayerId(GetTriggerPlayer())];
                
                    if (GetTriggerEventId() == EVENT_PLAYER_ARROW_UP_DOWN) {
                        TriggerCam.upPressed = true;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_UP_UP) {
                        TriggerCam.upPressed = false;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_DOWN) {
                        TriggerCam.downPressed = true;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_UP) {
                        TriggerCam.downPressed = false;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_RIGHT_DOWN) {
                        TriggerCam.rightPressed = true;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_RIGHT_UP) {
                        TriggerCam.rightPressed = false;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_LEFT_DOWN) {
                        TriggerCam.leftPressed = true;
                    } else if (GetTriggerEventId() == EVENT_PLAYER_ARROW_LEFT_UP) {
                        TriggerCam.leftPressed = false;
                    } 
                });
            }
        
            method movement()
            {
                real x, y, ox, oy, facing, movespeed;
                if (CanUnitMove(toFollow))
                {
                    x = GetUnitX(toFollow); y = GetUnitY(toFollow); facing = GetUnitFacing(toFollow)*bj_DEGTORAD;
                    ox = x; oy = y;
                    movespeed = GetUnitMoveSpeed(toFollow);
                
                    if (upPressed && !downPressed)
                    {
                        playAnimation = true;
                        
                        if (rightPressed && !leftPressed)
                        {
                            x += movespeed * LOOP_INTERVAL * Cos(facing - GetUnitDefaultTurnSpeed(toFollow));
                            y += movespeed * LOOP_INTERVAL * Sin(facing - GetUnitDefaultTurnSpeed(toFollow));
                        }
                        else if (!rightPressed && leftPressed)
                        {
                            x += movespeed * LOOP_INTERVAL * Cos(facing + GetUnitDefaultTurnSpeed(toFollow));
                            y += movespeed * LOOP_INTERVAL * Sin(facing + GetUnitDefaultTurnSpeed(toFollow));
                        }
                        else
                        {
                            x += movespeed * LOOP_INTERVAL * Cos(facing);
                            y += movespeed * LOOP_INTERVAL * Sin(facing);
                        }
                            
                        SetUnitPosition(toFollow, x, y);
                        
                        if (RAbsBJ(GetUnitX(toFollow) - x) > 0.5 || RAbsBJ(GetUnitY(toFollow) - y) > 0.5)
                        {
                            SetUnitPosition(toFollow, x, oy);
                            
                            if (RAbsBJ(GetUnitX(toFollow) - x) > 0.5)
                            {
                                SetUnitPosition(toFollow, ox, y);
                                
                                if (RAbsBJ(GetUnitY(toFollow) - y) > 0.5)
                                {
                                    SetUnitPosition(toFollow, x, y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (playAnimation)
                        {
                            playAnimation = false;
                            SetUnitAnimation(toFollow, "stand");
                        }
                    }
                    
                    if (rightPressed && !leftPressed)
                    {
                        if (TURN_ANGLE == 0)
                        {
                            SetUnitFacingTimed(toFollow, (facing - GetUnitDefaultTurnSpeed(toFollow)) * bj_RADTODEG, UPDATE_INTERVAL);
                        }
                        else
                        {
                            SetUnitFacingTimed(toFollow, (facing - TURN_ANGLE) * bj_RADTODEG, UPDATE_INTERVAL);
                        }
                    }
                    else if (!rightPressed && leftPressed)
                    {
                        if (TURN_ANGLE == 0)
                        {
                            SetUnitFacingTimed(toFollow, (facing + GetUnitDefaultTurnSpeed(toFollow)) * bj_RADTODEG, UPDATE_INTERVAL);
                        }
                        else
                        {
                            SetUnitFacingTimed(toFollow, (facing + TURN_ANGLE) * bj_RADTODEG, UPDATE_INTERVAL);
                        }
                    }
                    
                    animationCount += LOOP_INTERVAL;
                    
                    if (animationCount >= animationDur && playAnimation)
                    {
                        SetUnitAnimationByIndex(toFollow, animationIndex);
                        animationCount = 0;
                    }
                }
            }
            
            method registerKeyEvent(code cb) -> triggeraction
            {
                return TriggerAddAction(onKeyEvent, cb);
            }
            
            method unregisterKeyEvent(triggeraction ta)
            {
                TriggerRemoveAction(onKeyEvent, ta);
            }
        }
    }

//! endzinc

    native UnitAlive takes unit whichUnit returns boolean

JASS:
library CamExampele initializer init requires CameraSystem

    private function rotate takes nothing returns nothing
        // If the pressed key was down, we will rotate the unit by 180°
        // GetTriggerEventId() returns the id so we can check which arrow was pressed or released.
        if GetTriggerEventId() == EVENT_PLAYER_ARROW_DOWN_DOWN then
            call SetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow, GetUnitFacing(PlayerCameras[GetPlayerId(GetTriggerPlayer())].toFollow) + 180)
        endif
    endfunction

    private function init takes nothing returns nothing
        local group g = CreateGroup()
        local unit  u
        
        // Creating the camera struct for Player 1 (Red)
        local CAMERA cam = CAMERA.create(Player(0))
        
        // Getting the hero of Player 1
        call GroupEnumUnitsInRange(g, 0, 0, 999999, null)
        loop
            set u = FirstOfGroup(g)
            exitwhen u == null

            if GetUnitTypeId(u) == 'O000' then
                exitwhen true
            endif
            
            call GroupRemoveUnit(g, u)
        endloop
        call DestroyGroup(g)
        
        // Setting the unit which the camera follows to the hero we just found out
        set cam.toFollow = gg_unit_H000_0002
        // Change the camera to active
        set cam.active = true
        // This is a member of the keyboard plugin. We have to set a animationIndex (for most units) and a animation duration (for all units).
        // How do you get the index? Seriously. No idea. Play around with numbers from 0 to whatever until you get a good-looking walk
        // animation
        // How do you get the animation duration?
        // Place a unit in the editor, click on it and click through it's animations until you find the walk animation. Write down the duration
        // and you're done.
        set cam.animationDur = 0.733
        
        // Registering a new key event is easy - just like this.
        call cam.registerKeyEvent(function rotate)
        
        // Nulling is cool.
        set g = null
        set u = null
    endfunction
    
endlibrary


and one thing:
YourNameHere is don't want to answer me, i have pissed him off with my stupid question D:
 
Last edited:
Level 20
Joined
Jul 6, 2009
Messages
1,885
  • CameraSwitch
    • Events
      • Player - Player 1 (Red) types a chat message containing -cam as An exact match
    • Conditions
    • Actions
      • Custom script: call CamSwitch(GetPlayerId(GetTriggerPlayer()))
This will switch camera on/off everytime player 1 types "-cam" which is what YourNameHere meant.
 
Level 4
Joined
Jun 19, 2010
Messages
113
i tryed this. it's not work

attachment.php
 

Attachments

  • x_59d85401.jpg
    x_59d85401.jpg
    90.6 KB · Views: 239
Level 4
Joined
Jun 19, 2010
Messages
113
oh god... oh crap...
what the hell =\

attachment.php


now cam trigger don't want to work.
i just dl map with cam system, and copy-past code (to make sure that i have latest version of trigger)

wat i doing wrong? wtf?
help me D:
 

Attachments

  • x_59d85401.jpg
    x_59d85401.jpg
    60 KB · Views: 237
Level 4
Joined
Jun 19, 2010
Messages
113
what do you mean?

models, sounds... yes, i import them, but how can it affect trigger?

god, i have open old copy of my project(cam works on it), and copy-paste code
error not gone.
how can it be?

code works on old version of my map, and not works on current version.
code is have not got any errors, i have latest version of Jass helper and New Gen WE
what the?
 
Level 4
Joined
Jun 19, 2010
Messages
113
бляяяяяять i REALY don't know HOW
but i make this bastard work again

okey now, can some one edit trigger, just like i asked?
with out any "call CamSwitch(GetPlayerId(GetTriggerPlayer()))"
thats not work =\
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
First, don't bump your thread in less than one day.
Second of all, this thread is in the wrong place which is why barely anyone is trying to help you.

Anyway, for some reason, the Camera System no longer has that function anymore. (I think it got substituted for another function as the whole thing is practically a struct now and has a method active.)

You probably won't get anywhere with this system if you don't have any basic knowledge of vJass.
 
Level 4
Joined
Jun 19, 2010
Messages
113
don't bump your thread in less than one day.
me sorry D:

the whole thing is practically a struct now and has a method active
this words are too clever for me
i don't understand anything

You probably won't get anywhere with this system if you don't have any basic knowledge of vJass.

but why?
just set a boolen variable condition in the begining of code, or... this imposible?
it sounds simple
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
By my quick glance at the system, you have to create the camera with something like
JASS:
local CAMERA cam = CAMERA.create(Player(0))
This would create a camera for the Player 1 (Red) (In Jass, the players start from 0 instead of 1) Why am I talking about creating a camera? It's linked to how you would activate/deactivate the camera.

To activate/deactivate the camera, you would need to do something like
JASS:
set cam.active = true
JASS:
set cam.active = false
Of course, that would only work if that was put with the local variable. If you needed to do this somewhere else, you would probably need a global variable instead of a local variable.

It is simple, but to some people, (v)Jass can be very confusing.

Edit: Posted a test-map. It'll probably make more sense that way.
Trigger:
  • CameraCommand
    • Events
      • Player - Player 1 (Red) types a chat message containing -cam as An exact match
    • Conditions
    • Actions
      • Custom script: if MyCamera.active then
      • Game - Display to (All players) the text: Camera is deactivat...
      • Custom script: set MyCamera.active = false
      • Custom script: else
      • Game - Display to (All players) the text: Camera is activated!
      • Custom script: set MyCamera.active = true
      • Custom script: endif
Note MyCamera is a global CAMERA variable that I declared in the Example trigger. You should declare the global variable in vJass instead of using the Variable Editor.
 

Attachments

  • Cam System.w3x
    29.8 KB · Views: 65
Level 4
Joined
Jun 19, 2010
Messages
113
...aand.. why we can't use global variable? :D
lol, seriosly, i don't get, why is this so difficult

ok, mb there is some problems with global variable
condition can also be based on... don't know, on some unit. condition true if unit belond to red player.

emmm... tell me, is it possible to create new condition in that system or not?

ps
mb i must start new thread in "Triggers & Scripts"?

added:
ah, you have edited post
give me a sec :D

oooh man
you... you... you just saved me :D
thank you veeeeeeeeeeeeeeeeeryyyyyyyyyy much, i mean REALY VERY MUCH
gonna give you credit.. no, it's not enough. gonna write ur name at load screen, at ALL load screen.. ur name is going to be load screen. yeah
emm, ok, thank u again, and good luck :D
 
Last edited:
Status
Not open for further replies.
Top