Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
Ruthven said:
Lumos is pretty nice for a real-life Balrog. Also the fact he can type on a human keyboard at all is pretty impressive.
It's pretty difficult to find flame-retardant keyboards, that much I can say. :razz:


AelleCyning said:
I do want utf-8. Why give me a cp-1254 code thwn?
I merely pointed towards the fact that some ModSys files have coding defined in general, then said:
Lumos said:
I'd try with
Code:
utf-8
as the desired encoding. That should be good for everything.


AelleCyning said:
Also, what is the equivalent  of an if command in the M&B scripts?
I'd like to implement something like this:

IF knight_kingdom_1 has >-50 relation with king_1, THEN make knight_kingdom_1 leader of new_kingdom and declare war on kingdom_1.
Logic is conducted using try_* loops - more info on the different options can be found either in Caba'drin's syntax guide, or inside Lav's header_operations (which you should most definitely be using; link in Caba'drin's syntax thread). There's also a myriad examples in the default code.

ninja
 
While I'm here, what's the neatest way to make AI destroy scene props? Specifically I want bots to be able to take out sally doors (therefore making them seek the prop is not an issue, AI mesh will take them there already.) It shouldn't need to be an elaborate code, just make bots start swinging. But I wonder if its better to make bots just start swinging at random when they're within a meter of the prop or if perhaps invisible agents are a better way to go. Any ideas? I guess I could always take a look at Arch3r's Invasion source, IIRC he had something like that for the barriers.
 
Ruthven said:
But I wonder if its better to make bots just start swinging at random when they're within a meter of the prop or if perhaps invisible agents are a better way to go. Any ideas?
Go for the first method, extra agents mean extra network traffic.
 
I'm trying to set up a multiplayer team whitelist system. It works fine when one player is trying to switch teams, but when multiple people spam click teams it tends to bug out and let players join any team they want.

Here is my current logic:
[list type=decimal]
[*]Player attempts to join team which runs game_receive_network_message
[*]game_receive_network_message RECEIVES EVENT "multiplayer_event_change_team_no"
[*]game_receive_network_message RUNS SCRIPT "script_cf_multiplayer_team_is_available"
[*]cf_multiplayer_team_is_available RUNS WEBSCRIPT checkteams.php
[*]checkteam.php RETURNS 100 if GUID found in team1, OR 200 if GUID found in team2
[*]game_receive_url_response CHECKS checkteam.php result ($allow_switch)
[*]If result == 100, and game state is between 0 and 5, allow player to join team 1 (SET $allow_switch = 0)
[*]If result == 100, and game state is greater than 5, allow player to join team 2 (SET $allow_switch = 1)
[*]If result == 200, and game state is between 0 and 5, allow player to join team 2 (SET $allow_switch = 1)
[*]If result == 200, and game state is greater than 5, allow player to join team 1 (SET $allow_switch = 0)
[*]cf_multiplayer_team_is_available CHECKS IF $allow_switch == requested team to join, if FALSE REJECT REQUEST[/list]

Obvious issue I see: $allow_switch is a global variable on the game server. If multiple people are attempting to join teams at the same time this causes issues.. How could I go about passing this variable locally for the player? And are there any other issues that I'm not seeing?

1. game_receive_network_message
[/list]
Code:
(eq, ":event_type", multiplayer_event_change_team_no),                                   
        (store_script_param, ":value", 3),                      
        (try_begin),
          #validity check
          (player_get_team_no, ":player_team", ":player_no"),                                      
          (neq, ":player_team", ":value"),                                                    
          #condition checks are done
          (try_begin),
            #check if available
            (call_script, "script_cf_multiplayer_team_is_available", ":player_no", ":value"),
            #reset troop_id to -1
            (player_set_troop_id, ":player_no", -1),                                               
            (player_set_team_no, ":player_no", ":value"),                                         
            (try_begin),
              (neq, ":value", multi_team_spectator),                                              
              (neq, ":value", multi_team_unassigned),
      
              (store_mission_timer_a, ":player_last_team_select_time"),         
              (player_set_slot, ":player_no", slot_player_last_team_select_time, ":player_last_team_select_time"),
      
              (multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_confirmation),
            (try_end),
          (else_try),
            #Grimsight
             #reject request 
            (str_store_string, s1, "@Wrong team!"),
            (multiplayer_send_string_to_player,":player_no",multiplayer_event_show_server_message,s1),  
            (multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_rejection),
          (try_end),

2. cf_multiplayer_team_is_available
Code:
("cf_multiplayer_team_is_available",
   [
     (store_script_param, ":player_no", 1),
     (store_script_param, ":team_no", 2),

     (assign, reg1, ":player_no"),
     (player_get_unique_id, ":guid", ":player_no"),
     (assign, reg2, ":guid"),

     #GRIMSIGHT CONTACT PHP SCRIPT
     (send_message_to_url, "@http://*MYWEBSITE*.net/checkteams.php?guid={reg2}&playerid={reg1}&serverid=102"), #NACENTRAL 2

     (assign, ":continue_change_team", 1),
     (try_begin),
       (neq, "$g_multiplayer_game_type", multiplayer_game_type_deathmatch),
       (neq, "$g_multiplayer_game_type", multiplayer_game_type_duel),
       (is_between, ":team_no", 0, multi_team_spectator),
       (neg|teams_are_enemies, ":team_no", ":team_no"), #checking if it is a deathmatch or not
       (assign, ":continue_change_team", 0),
       #counting number of players for team balance checks
       (assign, ":number_of_players_at_team_1", 0),                       
       (assign, ":number_of_players_at_team_2", 0),                    
       (get_max_players, ":num_players"),                                    
       (try_for_range, ":cur_player", 0, ":num_players"),                               
         (player_is_active, ":cur_player"),                                       
         (neq, ":cur_player", ":player_no"),                             
         (player_get_team_no, ":player_team", ":cur_player"),                                
         (try_begin),
           (eq, ":player_team", 0),                                                              
           (val_add, ":number_of_players_at_team_1", 1),                            
         (else_try),  
           (eq, ":player_team", 1),                                                               
           (val_add, ":number_of_players_at_team_2", 1),                                   
         (try_end),
       (try_end),
       (store_sub, ":difference_of_number_of_players", ":number_of_players_at_team_1", ":number_of_players_at_team_2"),   

       (try_begin),
         (ge, ":difference_of_number_of_players", 0),                                         
         (val_add, ":difference_of_number_of_players", 1),                                    
       (else_try),
         (val_add, ":difference_of_number_of_players", -1),                                         
       (try_end),

      #test messages
        #(str_store_string,s1,"@test"),
        #(call_script,"script_mm_message_all_players"),
        #(assign, reg20, ":team_no"),
        #(str_store_string,s1,"@1: {reg20}"),
        #(assign, reg20, "$allow_switch"),
        #(call_script,"script_mm_message_all_players"),
        #(str_store_string,s1,"@2: {reg20}"),
        #(call_script,"script_mm_message_all_players"), 
        #(call_script, "cf_team_whitelist_check"),

       (try_begin),
         (eq, ":team_no", "$allow_switch"),       
         (lt, ":difference_of_number_of_players", "$g_multiplayer_auto_team_balance_limit"),                    
         (assign, ":continue_change_team", 1),                                                            
       (else_try),
         (eq, ":team_no", "$allow_switch"),                                                               
         (store_mul, ":checked_value", "$g_multiplayer_auto_team_balance_limit", -1),           
         (gt, ":difference_of_number_of_players", ":checked_value"),                                   
         (assign, ":continue_change_team", 1),                         
       (try_end),
     (try_end),
     (eq, ":continue_change_team", 1),
     ]),

3. checkteams.php
Code:
<?php

$GUID = $_GET["guid"];
$PlayerID = $_GET["playerid"];
$ServerID = $_GET["serverid"];

$ServerTxtNum;
$Team1Txt;
$Team2Txt;

if($GUID == "") {
	echo "100|50";
	exit;
}

/*
ServerIDs:
101 = NACentral1 (1052047016)
102 = NACentral2 (765169537)
...

201 = EUWest1 (1175065723)
202 = EUWest2 (1329641234)
...
*/

if ($ServerID == 101)
{
	$ServerTxtNum = "1052047016";
	$Team1Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team1.txt";
	$Team2Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team2.txt";
}
if ($ServerID == 102)
{
	$ServerTxtNum = "765169537";
	$Team1Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team1.txt";
	$Team2Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team2.txt";
}
if ($ServerID == 201)
{
	$ServerTxtNum = "1175065723";
	$Team1Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team1.txt";
	$Team2Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team2.txt";
}
if ($ServerID == 202)
{
	$ServerTxtNum = "1329641234";
	$Team1Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team1.txt";
	$Team2Txt = "servers/" . $ServerTxtNum . "/" . $ServerTxtNum . "team2.txt";
}

$team1 = file_get_contents($Team1Txt);
$team2 = file_get_contents($Team2Txt);

if (strpos($team1,"$GUID;") !== false) 
{
	echo "2|100|$PlayerID";
	exit;	
} 

if (strpos($team2,"$GUID;") !== false) 
{
	echo "2|200|$PlayerID";
	exit;	
} 
?>

4. game_receive_url_response
Code:
(try_begin),
          (eq, ":event_type", 2),
          (try_begin),
            (ge, ":integer_count", 1),                  
            (assign, ":return_code", reg1),
            (assign, ":player_no", reg2),

            (try_begin),
              (eq, ":return_code", 100), #Player is in team1 list
              (try_begin),

                (is_between,"$comp_game_state",0,5),  #If game state is in or before first set
                (assign, "$allow_switch", 0),         #allow swap to team 1

                #(str_store_string,s1,"@1"),
                #(call_script,"script_mm_message_all_players"),   
              (try_end),
              (try_begin),

                (is_between,"$comp_game_state",5,100), #if game state is in halftime or further
                (assign, "$allow_switch", 1),         #allow swap to team 2

                #(str_store_string,s1,"@2"),
                #(call_script,"script_mm_message_all_players"), 
              (try_end),
            (try_end),

            (try_begin),
              (eq, ":return_code", 200), #Player is in team1 list
              (try_begin),

                (is_between,"$comp_game_state",0,5),  #If game state is in or before first set
                (assign, "$allow_switch", 1),         #allow swap to team 2

                #(str_store_string,s1,"@3"),
                #(call_script,"script_mm_message_all_players"), 
              (try_end),
              (try_begin),

                (is_between,"$comp_game_state",5,100), #if game state is in halftime or further
                (assign, "$allow_switch", 0),         #allow swap to team 1

                #(str_store_string,s1,"@4"),
                #(call_script,"script_mm_message_all_players"), 
              (try_end),
            (try_end),

            (assign, reg20, "$allow_switch"),
            (str_store_string,s1,"@allow_switch: {reg20}"),
            (call_script,"script_mm_message_all_players"),   
           
          (try_end),
    (try_end),
 
Is this based on one of the existing whitelist systems? I don't know enough about multiplayer to give any advice but if you're doing this all on your own there are one or two existing whitelist systems that might be a good reference.
 
@grimsight
You're not waiting for the http response before doing the team switch.
It checks for "$allow_switch" directly after sending the request to your url, but at this time "$allow_switch" still contains the state of the last check/player.

So execute the team switch after getting the response.
 
Lumos said:
Ruthven said:
Lumos is pretty nice for a real-life Balrog. Also the fact he can type on a human keyboard at all is pretty impressive.
It's pretty difficult to find flame-retardant keyboards, that much I can say. :razz:


AelleCyning said:
I do want utf-8. Why give me a cp-1254 code thwn?
I merely pointed towards the fact that some ModSys files have coding defined in general, then said:
Lumos said:
I'd try with
Code:
utf-8
as the desired encoding. That should be good for everything.


AelleCyning said:
Also, what is the equivalent  of an if command in the M&B scripts?
I'd like to implement something like this:

IF knight_kingdom_1 has >-50 relation with king_1, THEN make knight_kingdom_1 leader of new_kingdom and declare war on kingdom_1.
Logic is conducted using try_* loops - more info on the different options can be found either in Caba'drin's syntax guide, or inside Lav's header_operations (which you should most definitely be using; link in Caba'drin's syntax thread). There's also a myriad examples in the default code.

ninja

But HOW do I encode in Utf+8??
 
@grimsight you should check which team a player can join when they join the server. Make 2 player slots (slot_player_can_join_team_0 and slot_player_can_join_team_1). When the player joins the server, send the GUID (and also the local id/player no) and 'run' the php file.
When you receive a message in game_receive_url_response (you should receive the player GUID, the local id/player no and also which team it can join (two values (0 or 1 for first team, 0 or 1 for second team) or a single value which can have 4 possible values (0 - can't join any teams; 1 - can join team 0; 2 - can join team 1; 3 - can join both teams))); check if the player no is active, get it's GUID and check if it is the same as the one you received and then set the player's slots accordingly. Then, all you have to do is check those two slots in cf_multiplayer_team_is_available.

Make sure to initialize the slots when the player joins the server to 'can't join team' value (it is whatever you decide, preferably 0).
 
AelleCyning said:
But HOW do I encode in Utf+8??

google: "Python encode utf-8", or go back in the first posts about this subject as we posted links for Python documentation (more technical)

http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-in-python-source
 
kalarhan said:
AelleCyning said:
But HOW do I encode in Utf+8??

google: "Python encode utf-8", or go back in the first posts about this subject as we posted links for Python documentation (more technical)

http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-in-python-source

I don't understand.
 
Literally write
Code:
# -*- coding: utf-8 -*-
at the top of the file, as I explicitly told you to do. Which exactly part of "use
Code:
utf-8
as the desired encoding" was hard to understand?
You seem to be one of those people who don't read instructions carefully and then wonder why things don't work out properly. Unfortunately, this isn't an effective mentality when it comes to programming.
 
Lumos said:
Literally write
Code:
# -*- coding: utf-8 -*-
at the top of the file, as I explicitly told you to do. Which exactly part of "use
Code:
utf-8
as the desired encoding" was hard to understand?
You seem to be one of those people who don't read instructions carefully and then wonder why things don't work out properly. Unfortunately, this isn't an effective mentality when it comes to programming.

Maybe explain things a bit clearer. Like taking the one second effort to write "# -*- coding: utf-8 -*-". Instead of writing a cryptic knot of an answer that would have Alexander reaching for his sword.
 
I sincerely doubt that a tactical genius wouldn't have understood my "here is how to use this, do the absolute same thing, but replace this word with that word" statement. I understand it, at the very least.
 
Lumos said:
I sincerely doubt that a tactical genius wouldn't have understood my "here is how to use this, do the absolute same thing, but replace this word with that word" statement. I understand it, at the very least.

Took you a long time to write this comment and the other when you could have written the code.
And you can insult my intelligence all you want, I don't give a ****. You're really quite unpleasant, and I don't understand why you help here if all you do is whine about "noobs" and post unhelpful "advice", or rather, puzzles.

Lumos said:
Just look at some of the ModSys files. They've got an explicitly declared
Code:
# -*- coding: cp1254 -*-
right at the top. Might have been module_strings. I don't remember.
At any rate, it's obvious enough what you need to do from the "Examples" section in the given article. "I'm too bad at coding" isn't an excuse when you're here to code, and even less so when nobody wants you to do any coding.
I don't know which set your characters belong to, but I'd try with
Code:
utf-8
as the desired encoding. That should be good for everything.


1 new reply
I really wish you newbies would read the damn logs instead of re-posting the same old errors ad infinitum.
AelleCyning said:
Code:
Traceback (most recent call last):
  File "process_global_variables.py", line 106, in <module>
    save_variables(export_dir, variables,variable_uses)
  File "C:\Games\Mod System (500AD)\Module_system 1.166\process_operations.py",
line 171, in save_variables
    file = open(export_dir + "variables.txt","w")
IOError: [Errno 2] [b][color=blue]No such file or directory: 'C:/Program Files/Mount&Blade Warb
and/Modules/500 AD/variables.txt[/color][/b]'
Are you sure your folders and your module_info are okay, and that you're got permissions to read/write in that folder?

5 lines of whining, without saying "replace", just stating a "desired encoding". Not how to implement the encoding.
 
AelleCyning said:
all you do is whine

review the last 1000 pages of this thread. See how many are doing that. I will give you a hint: 1 (one/uno/um/solo)

Can we go back to answer serious questions now?

This is not a thread for ranting, whining, etc, its to help modders (people with the desire to change the game and the will to do the work)
 
Status
Not open for further replies.
Back
Top Bottom