Zoom-in Function

Users who are viewing this thread

bjorne.

Sergeant Knight
Well. I was wondering. How does this zoom-in function work?.

[list type=decimal]
[*]Is it soft or hard coded?
[*]Can I make some items zoom in more?
[*]If it is somft coded where may I find it?
[/list]
 
I've played with moving the camera in my tournament that I am building into my mod.  In this case, when the player fires his arrow, the camera moves forward to look at the target.

###Camera stuff (if possible)
(0.1,0,0,
[###Conditions that the arrow was fired
(get_player_agent_no, ":player_agent"),
(agent_get_ammo, ":ammo", ":player_agent"),
(gt,"$num_arrows",":ammo"),                  ##means an arrow was fired
],
[###Moving the camera near pos10 with delta-y about 300
(display_message,"@An arrow was fired"),
(val_sub,"$num_arrows",1),
(mission_cam_clear_target_agent),

(position_move_y,pos10,-100),
(position_move_z,pos10,80),
(mission_cam_set_mode,1),
(mission_cam_animate_to_position, pos10, 1000, 0),
(assign,"$cam_lock",20),
],
),
(0.1,0,1,
[###Camera has moved, need to move it back after 4 seconds
(try_begin),
(gt,"$cam_lock",1),
(val_sub,"$cam_lock",1),
(try_end),
(eq,"$cam_lock",1),
],
[(assign,"$cam_lock",0),
(mission_cam_set_mode,0),
(get_player_agent_no, ":player_agent"),
(mission_cam_set_target_agent, ":player_agent", 1),
],
),
###Camera Stuff ends

I'm not sure how things work when the camera is zoomed in this case.  You could always take the players Y direction to move the camera where they are looking.  If you are talking about pressing Shift, I think that is hard coded, though you can make your own.
 
jik said:
I've played with moving the camera in my tournament that I am building into my mod.  In this case, when the player fires his arrow, the camera moves forward to look at the target.

###Camera stuff (if possible)
(0.1,0,0,
[###Conditions that the arrow was fired
(get_player_agent_no, ":player_agent"),
(agent_get_ammo, ":ammo", ":player_agent"),
(gt,"$num_arrows",":ammo"),                  ##means an arrow was fired
],
[###Moving the camera near pos10 with delta-y about 300
(display_message,"@An arrow was fired"),
(val_sub,"$num_arrows",1),
(mission_cam_clear_target_agent),

(position_move_y,pos10,-100),
(position_move_z,pos10,80),
(mission_cam_set_mode,1),
(mission_cam_animate_to_position, pos10, 1000, 0),
(assign,"$cam_lock",20),
],
),
(0.1,0,1,
[###Camera has moved, need to move it back after 4 seconds
(try_begin),
(gt,"$cam_lock",1),
(val_sub,"$cam_lock",1),
(try_end),
(eq,"$cam_lock",1),
],
[(assign,"$cam_lock",0),
(mission_cam_set_mode,0),
(get_player_agent_no, ":player_agent"),
(mission_cam_set_target_agent, ":player_agent", 1),
],
),
###Camera Stuff ends

I'm not sure how things work when the camera is zoomed in this case.  You could always take the players Y direction to move the camera where they are looking.  If you are talking about pressing Shift, I think that is hard coded, though you can make your own.

That is great news jik!
Yes I was talking about pressing Shift. But if I can make my own would be awesome aswell. Cuase I was planning to make my rifles in my mod to be able to zoom in alot more with. But what do you suggest me to do if I should do to create my own zoom-in button?
 
Not that I'm an excellent modder, but i would try to base it off the one that is hardcoded and just make the scale of zoom larger.  Not sure how you would make it different for each weapon unless you made a different zoom for each weapon and added them as flags(I think) to the weapon
 
The Red Baron said:
Not that I'm an excellent modder, but i would try to base it off the one that is hardcoded and just make the scale of zoom larger.  Not sure how you would make it different for each weapon unless you made a different zoom for each weapon and added them as flags(I think) to the weapon

That would be best, but if you don't have access to change these settings, then you have to go on your own. 

Yes I would tie it to a different button, and maybe prevent the player from moving as a disadvantage to the advantage of zooming so much.
 
Ruthven said:
Well maybe you could on_ti_weapon_attack in the item tuple and call a script to zoom in the camera ala Jik's code?
Well That's a great idea. I mean if you stand and hold the shot will say... I'll try that. Thank you all for putting your master-minds together and helped me out...

EDIT: Does the code go into module_scripts or?
EDIT2: Don't worry jik I wont use your code in my mod. It's just for testing. After all it is you code.
 
I want to do the same thing like sniperscope effect, but still no success.

That shift function is hardcored I believe.

I don't  think on_ti_weapon_attack would work good. Edit in mission_templates should work, first check which weapon the player is using, then decide how much scale he can zoom in.

mission_cam_set_target_agent or mission_cam_animate_to_position etc could do the trick, but I have some question: In my practise, I'm sure that the player's/agents' looking position, or line of sight, is not always same as aiming line, or should I say these lines NEVER perfectly matched. In this way if we move the cam to some direction, how can we sure that the player's target would still be in the sight/screen?
can you guys who have tested jik's code give us some screenies to show this effect?
 
I tried a same way as jik's, it worked bad.

if any one want to know the code, here is it:
Code:
zoom_in = (
  0, 0, 0,
   [
    (key_clicked,key_left_control), 
    ],
   [ 
     (mission_cam_clear_target_agent),
     
     (assign,":height",0),
     
     (get_player_agent_no, ":player"),
     (agent_get_look_position, pos1, ":player"),
     (position_move_y,pos1,6000),
     (position_get_z,":height",pos1),
    (try_begin),
     (lt,":height",50),
     (position_move_z,pos1,200),
    (try_end),   
     (mission_cam_set_mode,1),
     (mission_cam_animate_to_position, pos1, 5, 0),
     
   #  (start_presentation,"prsnt_scope"),
    
    ])

zoom_out = (
  0, 0, 0,
   [
    (key_clicked,key_left_alt), 
    ],
   [ 
     (mission_cam_clear_target_agent),
     
     (get_player_agent_no, ":player"),
     (mission_cam_set_mode,0),
     (mission_cam_set_target_agent, ":player", 1),
    
    ])
 
WilliamBerne said:
I want to do the same thing like sniperscope effect, but still no success.

That shift function is hardcored I believe.

I don't  think on_ti_weapon_attack would work good. Edit in mission_templates should work, first check which weapon the player is using, then decide how much scale he can zoom in.

mission_cam_set_target_agent or mission_cam_animate_to_position etc could do the trick, but I have some question: In my practise, I'm sure that the player's/agents' looking position, or line of sight, is not always same as aiming line, or should I say these lines NEVER perfectly matched. In this way if we move the cam to some direction, how can we sure that the player's target would still be in the sight/screen?
can you guys who have tested jik's code give us some screenies to show this effect?

You can use my code, that's why I posted it.  Mind you, it's not geared for what you are doing, but it can be adapted.  I can't do screen shots, since that can be faked, so I did a movie of it.  I don't use those movie sites, so here is a link to the file wmv:
http://www.yousendit.com/download/cmczZm1hV3JCTW5IRGc9PQ
(only available for 1 week)

I would add it to the on_ti_weapon_attack.  This way it can be special for each weapon.  One thing that I haven't tested is what happens if the AI uses the zoom.  You could do a check for the agent using it, but there has been trouble with coding that, though someone should lock it down...  Hmm...  ya I guess you should put it as a trigger.  You can also have it zoom more if you hold it longer, though that seems odd.  You can make a global variable that when set to 1, then the weapon will zoom.  That way if the player doesn't want to use the scope, there is no issue.

On this note, I have done a few tests with the agent_look stuff and found that the play's pos is set on the ground facing the way the player is aiming.  I did a test with moving scene props along this line (raise up about 150cm since I was testing at lance held level while on horseback), looking up or down.  I am going by the way the lance was pointed since there were no crosshairs with that weapon.
 
I can't watch the video right now, but this sounds like a very neat concept.  I agree a scope would be awesome if we could get it working, but at the minimum we could probably have a pair of binoculars that you could purchase from the shop.  If you had these in your inventory then you could press the B key to toggle the zoom, etc....  I may try and test this concept out tonight to add a check if a certain item is in inventory, etc.  Can you control the look with the mouse while it is zoomed in ?
 
I clear the agent the camera is tied to when I zoom, so with this code, no, you can't move the camera.  But I don't see why not.
 
Wow that was amazing... This is a feature I am really looking forward to seeing in various mods!
 
well, I briefly tried the zoom_in and zoom_out code WilliamBerne posted.  It works, and it would be easy enough to switch this to a single key to toggle it, or allow you to press the zoom key multiple times to switch the distance which would be cool.  However, there are a few issues I initially see....

1) the view doesn't change as you move your mouse when zoomed in.  So I think we'd need to switch this to a timer every second with a variable as a toggle switch that would check if $g_zoom=1 then it would re-do the zoom position... or something like that?
2) your body continues to move when you are zoomed in.  I tried to figure out a way to stop the player from moving, but couldn't obviously see a way how.  But if you are riding a horse or moving the keyboard when zoomed in you may end up at a different spot then you intended, or even see yourself in the zoom.
3) Since the player is still moving it is difficult to try and fight from the zoom position, so a sniper scope would be tough

anyway, a scope on a gun would be great, but even if we could add functionality like binoculars it would be very cool to check out your enemy before a battle, etc.  But it seems like we'd either have to stop the player from moving, or figure out a way to have the camera move with the player movement.  Anyway, I think this is possible, I just usually suck at trying to write code from scratch, but I'll think about it.

I'll also review the after death camera that Martin integrated into the star wars mod since it is similar
http://forums.taleworlds.com/index.php/topic,61929.msg1603855.html#msg1603855

the original concept was from this
http://forums.taleworlds.com/index.php/topic,60329.msg1559908.html#msg1559908
 
hmmm.  Maybe we need to force the player agent to stop moving when you initiate the zoom.  The problem is then you don't have the ability to aim the agent.  Just on a quick thought, you would have to match the angle of the mouse with the pos where the player is.  We can't set where an agent is looking can we?

What I did was easy since it's just the camera I was playing with, the player cannot move during my archery.
 
The way I stopped speeder bikes (horses) from moving in my mod when not ridden was to run a trigger to set the animation to an unused one every second... So maybe we have to do something similar when the player zooms in? That same trigger could potentially also change the camera angle to the player look or something...
 
Just tested move the cam without (mission_cam_set_mode,1), it didn't help. the cam was moved to the certain position in 1 secend, then it was draged back to the player very quickly.
maybe try (mission_cam_set_mode,2),  or 3 later. but I doubt if it will work.

I think we can simply tell the player: don't use this function before you fully stop, or you may run into enemies.
Sniperscope won't go well I believe, but a unmovable binoculars is acceptable.
 
Can we override the movement?  Something similar to this:

  (ti_tab_pressed, 0, 0, [],
  [(try_begin),
      (eq, "$g_mt_mode", abm_visit),
      (set_trigger_result, 1),
    (else_try),
      (question_box,"str_give_up_fight"),
    (try_end),
    ]),
 
ok, I played around with the concept of binoculars and am pretty happy with how it is working so far.  If you have itm_binocular in your inventory then the B key changes you view between a 0-4x magnification.  The player and/or horse they are ridding will stop moving while you are zoomed in.  You can also use your mouse to move the binoculars while zoomed.  It could use a presentation overlay (no clue how to add that), and I may have some redundant code so let me know if you guys can improve it any further...

create itm_binocular in module_items.py
["binocular","Macro Binoculars", [("laser_scope",0)], itp_merchandise|itp_type_goods, 0,5000,weight(5)|abundance(40),imodbits_none],

add this to the top of module_mission_templates.py
from module_animations import *

copy this into the top part of module_mission_templates.py with the other common_ code
Code:
#--------------------------------------------------------------------------------------------------------------------------------------------------
#SW - zoom in/out code by jik and WilliamBerne - http://forums.taleworlds.com/index.php/topic,68192.0.html - modified further by HokieBT
common_use_binocular_1 = (0, 0, 0, [
	(key_clicked, key_b)
	],
	[
		(get_player_agent_no, ":player_agent"),
		(agent_is_alive, ":player_agent"),
		#(troop_get_inventory_capacity, ":inv_cap", "trp_player"),
		(troop_get_inventory_capacity, ":inv_cap", "$g_player_troop"),	#since custom commander is integrated
		(assign, ":binocular_slot", -1),
		(try_for_range, ":slot_no", 0, ":inv_cap"),
			#(troop_get_inventory_slot,":item_id","trp_player",":slot_no"),
			(troop_get_inventory_slot,":item_id","$g_player_troop",":slot_no"),	#since custom commander is integrated
			#check for binoculars
			(try_begin),
				(eq, ":item_id", "itm_binocular"),
				(assign, ":binocular_slot", ":slot_no"),
			(try_end),
		(try_end),

		(try_begin),
			(eq, ":binocular_slot", -1),
			(display_message, "@You don't have any Binoculars in your inventory!"),
		(else_try),
		
			(try_begin),
				(le, "$binocular_magnification", 0),	#incase this variable isn't set yet
				(assign, "$binocular_magnification", 1000),
				(display_message, "@Binocular Zoom is 1x"),
			(else_try),
				(eq, "$binocular_magnification", 1000),
				(assign, "$binocular_magnification", 2000),
				(display_message, "@Binocular Zoom is 2x"),
			(else_try),
				(eq, "$binocular_magnification", 2000),
				(assign, "$binocular_magnification", 3000),
				(display_message, "@Binocular Zoom is 3x"),
			(else_try),
				(eq, "$binocular_magnification", 3000),
				(assign, "$binocular_magnification", 4000),
				(display_message, "@Binocular Zoom is 4x"),				
			(else_try),
				(eq, "$binocular_magnification", 4000),
				(assign, "$binocular_magnification", 0),
				(display_message, "@Binocular Zoom is off"),
			(try_end),
			#change the zoom
			(try_begin),
				(le, "$binocular_magnification", 0),
				(mission_cam_clear_target_agent),
				(mission_cam_set_mode,0),
				(mission_cam_set_target_agent, ":player_agent", 1),
			(else_try),
				(mission_cam_clear_target_agent),
				(assign,":height",0),
				#get where the player is looking
				(agent_get_look_position, pos1, ":player_agent"),
				(position_move_y,pos1,"$binocular_magnification"),
				(position_get_z,":height",pos1),
				(try_begin),
					(lt,":height",50),
					(position_move_z,pos1,200),
				(try_end), 
				(mission_cam_set_mode,1),
				(mission_cam_animate_to_position, pos1, 100, 0),		#the speed of the zoom-in
			(try_end),
		(try_end),
	])

common_use_binocular_2 = (
  0.1, 0, 0,
   [
		(try_begin),
			(gt, "$binocular_magnification", 0),
			(get_player_agent_no, ":player_agent"),
			(agent_is_alive, ":player_agent"),
			#(agent_set_animation, ":player_agent", "anim_unused_human_anim_1"),	#so the player doesn't move, must include module_animations at the top of the python file
			(agent_set_animation, ":player_agent", "anim_defend_fist"),	#so the player looks more like they are holding binoculars

			(try_for_agents, ":cur_agent"),
				(agent_is_alive, ":cur_agent"),	#so we don't try dead agents
				(neg|agent_is_human,":cur_agent"),	#agent is a horse
				(agent_get_rider,":cur_rider", ":cur_agent"),
				(eq, ":cur_rider", ":player_agent"),	#rider of this horse is the player
				(agent_set_animation, ":cur_agent", "anim_unused_horse_anim_1"),	#so the horse doesn't move, must include module_animations at the top of the python file
			(try_end),

			#fix the camera to follow the mouse movement
			#reset the camera (not sure all of these steps are necessary?)
			(mission_cam_clear_target_agent),
			(mission_cam_set_mode,0),
			(mission_cam_set_target_agent, ":player_agent", 1),
			#zoom in the camera (removed the height check so the camera wouldn't jump on the z-axis as the player moved the mouse around)
			(mission_cam_clear_target_agent),
			(agent_get_look_position, pos1, ":player_agent"),
			(position_move_y,pos1,"$binocular_magnification"),
			(mission_cam_set_mode,1),
			(mission_cam_animate_to_position, pos1, 1, 0),		#the speed of the zoom-in (really fast for the mouse movement camera, zero doesn't work)
			
		(try_end),
    ],
   [
    ])	
#---------------------------------------------------------------------------------------------------------------------------------------------------

add this to any mission template you want to be able to use them
common_use_binocular_1,
common_use_binocular_2,
 
Back
Top Bottom