Coding: Crouch Script (In need of assistance)

Users who are viewing this thread

Blobmania

Grandmaster Knight
Howdy there people,

So i've been working on a modified version of Shredz's Crouch feature from AOFI, and i've run into a bit of a wall. I'm not hugely experienced in scripts and suchlike, so I thought i'd dump what i've got in here and see if any of you lovely people can help me. As far as i'm aware the solution is fairly simple, but i'm not hugely sure what I should be doing (or where it should be going) to fix the issue.

The point i'm currently at is that the scripts work and everything, in my own self-hosted server, hosted on my own PC. However, it doesn't work when hosted on a dedicated server. Once it goes onto a dedicated server, sod all happens when you hit the button.

So, here's the script:

Code:
      (eq, ":event_type", multiplayer_event_animation_at_player),
        (store_script_param,":animation",3),
    
        (player_get_agent_id,":agent",":player_no"),
        (agent_is_active, ":agent"),
        (agent_is_alive, ":agent"),
        (agent_is_human, ":agent"),

        (agent_set_animation,":agent",":animation"),
   
        (eq, ":event_type", multiplayer_event_crouch_begins_at_player),
        (player_is_active, ":player_no"),
        (get_max_players, ":num_players"),
    
        (try_for_range, ":player_no2", 1, ":num_players"),
          (player_is_active, ":player_no2"),
          (multiplayer_send_int_to_player, ":player_no2", multiplayer_event_player_begin_crouch, ":player_no"),            
        (try_end),
      (else_try),    
   
            (eq, ":event_type", multiplayer_event_crouch_ends_at_player),
      (get_max_players, ":num_players"),
    
                   (try_for_range, ":player_no2", 1, ":num_players"),
                      (player_is_active, ":player_no2"),
                      (multiplayer_send_int_to_player, ":player_no2", multplayer_event_player_end_crouch, ":player_no"),            
                   (try_end),
(else_try),

So, suggestions?

Cheers

- Blobski
 
Dunde's code, here, is for SP. From a quick glance at Blob's post, his problems aren't with the crouching part, but the server-client messaging...which I unfortunately am no help with, but I don't think dunde's work will be of assistance either.
 
Aye, that's what I was thinking. I mean, I know the issue is going to be somewhere in the server and client messaging (or lack of it?), but i'm clueless as to what needs adding to make it work.
 
Code:
multiplayer_event_animation_at_player = 49  
multiplayer_event_animation_begins_at_player = 125   
multiplayer_event_animation_ends_at_player = 126
Code:
multiplayer_event_player_play_animation = 117
multiplayer_event_player_begin_animation = 118
multplayer_event_player_end_animation = 119
Check that they are not overlapping indexes with existing events after you have pasted them in.
Code:
      (else_try),
            (eq, ":event_type", multiplayer_event_animation_at_player),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(store_script_param,":animation",3),
		(get_max_players, ":num_players"),
      
	    (player_get_agent_id,":agent",":player_no"),
	    (agent_set_animation,":agent",":animation"),
	  
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_2_int_to_player, ":player_no2", multiplayer_event_player_play_animation, ":animation", ":player_no"),             
                   (try_end),
      (else_try),

            (eq, ":event_type", multiplayer_event_animation_begins_at_player),
			#(display_message,"@player is crouching"),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(get_max_players, ":num_players"),
      
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_int_to_player, ":player_no2", multiplayer_event_player_begin_animation, ":player_no"),             
                   (try_end),
      (else_try),      
	  
            (eq, ":event_type", multiplayer_event_animation_ends_at_player),
			#(display_message,"@player is not"),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(get_max_players, ":num_players"),
      
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_int_to_player, ":player_no2", multplayer_event_player_end_animation, ":player_no"),             
                   (try_end),
Code:
        (else_try),
                (eq, ":event_type", multiplayer_event_player_play_animation),
		  (store_script_param, ":animation", 3),
		  (store_script_param, ":player", 4),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  (agent_is_alive,":agent"),
			  (agent_set_animation,":agent",":animation"),
		  (end_try),
		  
        (else_try),
                (eq, ":event_type", multiplayer_event_player_begin_animation),
				#(display_message,"@someone is crouching"),
		  (store_script_param, ":player", 3),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  #(agent_set_walk_forward_animation,":agent","anim_walk_forward_crouch"),
		  (end_try),
		 
        (else_try),
                (eq, ":event_type", multplayer_event_player_end_animation),
				#(display_message,"@someone is not crouching"),
		  (store_script_param, ":player", 3),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  (agent_set_walk_forward_animation,":agent","anim_run_forward"),
		  (end_try),
Code:
    (0, 0, 1, [(key_clicked, key_left_control)], # to make sure the tree above triggers stay in sync. (there is a slight delay between the calling of the triggers)
     
       [
         (try_begin),
          (eq,"$g_in_crouch",0),
        (multiplayer_get_my_player, ":my_player"),
          (player_get_agent_id, ":my_agent", ":my_player"),
          (agent_get_horse, ":horse", ":my_agent"),
          (le, ":horse", 0),
         #(display_message,"@crouch key pressed (begin)."),
          (assign,"$g_in_crouch",1),
          (multiplayer_send_int_to_server,multiplayer_event_animation_at_player, "anim_stand_to_crouch"),
          (multiplayer_send_message_to_server,multiplayer_event_animation_begins_at_player),
       (else_try),
          (eq,"$g_in_crouch",1),
         #(display_message,"@crouch key pressed (end)."),
          (assign,"$g_in_crouch",0),
          (multiplayer_send_int_to_server,multiplayer_event_animation_at_player, "anim_crouch_to_stand"),
          (multiplayer_send_message_to_server,multiplayer_event_animation_at_player),   
       (end_try),
       ]),

 
mr.master said:
Code:
multiplayer_event_animation_at_player = 49  
multiplayer_event_animation_begins_at_player = 125   
multiplayer_event_animation_ends_at_player = 126
Code:
multiplayer_event_player_play_animation = 117
multiplayer_event_player_begin_animation = 118
multplayer_event_player_end_animation = 119
Check that they are not overlapping indexes with existing events after you have pasted them in.
Code:
      (else_try),
            (eq, ":event_type", multiplayer_event_animation_at_player),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(store_script_param,":animation",3),
		(get_max_players, ":num_players"),
      
	    (player_get_agent_id,":agent",":player_no"),
	    (agent_set_animation,":agent",":animation"),
	  
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_2_int_to_player, ":player_no2", multiplayer_event_player_play_animation, ":animation", ":player_no"),             
                   (try_end),
      (else_try),

            (eq, ":event_type", multiplayer_event_animation_begins_at_player),
			#(display_message,"@player is crouching"),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(get_max_players, ":num_players"),
      
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_int_to_player, ":player_no2", multiplayer_event_player_begin_animation, ":player_no"),             
                   (try_end),
      (else_try),      
	  
            (eq, ":event_type", multiplayer_event_animation_ends_at_player),
			#(display_message,"@player is not"),
		(this_or_next|neq,":player_no",0),
		(neg|multiplayer_is_dedicated_server),
		(get_max_players, ":num_players"),
      
                   (try_for_range, ":player_no2", 0, ":num_players"),
                      (this_or_next|neq,":player_no2",0),
                      (neg|multiplayer_is_dedicated_server),

                      (player_is_active, ":player_no2"),
                      (multiplayer_send_int_to_player, ":player_no2", multplayer_event_player_end_animation, ":player_no"),             
                   (try_end),
Code:
        (else_try),
                (eq, ":event_type", multiplayer_event_player_play_animation),
		  (store_script_param, ":animation", 3),
		  (store_script_param, ":player", 4),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  (agent_is_alive,":agent"),
			  (agent_set_animation,":agent",":animation"),
		  (end_try),
		  
        (else_try),
                (eq, ":event_type", multiplayer_event_player_begin_animation),
				#(display_message,"@someone is crouching"),
		  (store_script_param, ":player", 3),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  #(agent_set_walk_forward_animation,":agent","anim_walk_forward_crouch"),
		  (end_try),
		 
        (else_try),
                (eq, ":event_type", multplayer_event_player_end_animation),
				#(display_message,"@someone is not crouching"),
		  (store_script_param, ":player", 3),
		  (player_get_agent_id,":agent",":player"),
		  (try_begin),
			  (neq,":agent",-1),
			  (agent_set_walk_forward_animation,":agent","anim_run_forward"),
		  (end_try),
Code:
    (0, 0, 1, [(key_clicked, key_left_control)], # to make sure the tree above triggers stay in sync. (there is a slight delay between the calling of the triggers)
     
       [
         (try_begin),
          (eq,"$g_in_crouch",0),
        (multiplayer_get_my_player, ":my_player"),
          (player_get_agent_id, ":my_agent", ":my_player"),
          (agent_get_horse, ":horse", ":my_agent"),
          (le, ":horse", 0),
         #(display_message,"@crouch key pressed (begin)."),
          (assign,"$g_in_crouch",1),
          (multiplayer_send_int_to_server,multiplayer_event_animation_at_player, "anim_stand_to_crouch"),
          (multiplayer_send_message_to_server,multiplayer_event_animation_begins_at_player),
       (else_try),
          (eq,"$g_in_crouch",1),
         #(display_message,"@crouch key pressed (end)."),
          (assign,"$g_in_crouch",0),
          (multiplayer_send_int_to_server,multiplayer_event_animation_at_player, "anim_crouch_to_stand"),
          (multiplayer_send_message_to_server,multiplayer_event_animation_at_player),   
       (end_try),
       ]),

Coded it in, but got nothing. Maybe I should set it up a bit differently...
 
I know you said you solved it, but here's some food for thought (and me posting that code I promised).

2 triggers, 1 network event (Warning, not optimized yet).

Mission template triggers
Code:
NvP_crouch = (0, 0, 0, [(key_clicked, key_z),],[
	(multiplayer_send_int_to_server, nvp_common, nvp_crouch),
])
NvP_server_crouch = (0, 0, 0, [(multiplayer_is_server),],[
	(try_for_agents, ":cur"),
		(agent_is_alive, ":cur"),
		(agent_is_human, ":cur"),
		(agent_slot_eq,":cur",crouch_slot,1),
		
		(agent_get_speed, pos6, ":cur"),
		(set_fixed_point_multiplier, 1000),
		(position_get_x,":vX",pos6),
		(position_get_y,":vY",pos6),
		(val_abs,":vX"),
		(val_abs,":vY"),
		
		(try_begin), #Don't take ABS and elaborate for direction movements.
			(this_or_next|gt, ":vX", 0),
			(gt, ":vY", 0),
			(agent_set_animation, ":cur", "anim_walk_forward_crouch"),
		(else_try),
			(agent_set_animation, ":cur", "anim_crouch_idle"),
		(try_end),
	(try_end),
])

Network script
Code:
(eq, ":val", nvp_crouch),
			(player_get_agent_id, ":aid", ":player_no"),
			(agent_is_alive,":aid"),
			(try_begin),
				(agent_slot_eq,":aid",crouch_slot,1),
				(agent_set_animation, ":aid", "anim_crouch_to_stand"),
				(agent_set_kick_allowed, ":aid", 1),
				(agent_set_slot,":aid",crouch_slot,0),
			(else_try),
				(agent_set_slot,":aid",crouch_slot,1),
				(agent_set_kick_allowed, ":aid", 0),
			(try_end),
 
Vincenzo said:
I know you said you did not optimize it but having a agent loop running every frame will strain your server loads.

I'd suggest you find a solution far from that one.
Well, if the game mode is going to involve bots, it's pretty much needed one way or another. As long as it's kept linear, and there aren't many more per-frame loops (although, this one could probably done every 10th frame or so), it shouldn't be too big of an issue.
 
Back
Top Bottom