Search results for query: *

  1. AgentSmith

    Warband Refined & Enhanced Compiler Kit (v1.0.0 @ Mar 01, 2015)

    This is some great work Lav & Vetrogor! Can highly recommend.
    I modified my wrecker to not convert runtime variables (eg ":trp_xyz" will not become ":trp.xyz") and to not touch python file encoding info, if anyone wants it.
    Here is a tiny plugin that lets you use (str_print, "x = :var_x, y = $g_var_y") syntax for debugging (it just converts this to assigns and display_message).
    Python:
    import re
    from compiler import *
    from header_common import reg0 as reg0
    register_plugin()
    
    cur_reg = 64
    def str_print(s, *argl):
      global cur_reg
      if s == "":
        return
    
      p = re.compiler"{?([:$][a-zA-Z_]\w*)\b}?")
    
      cur_reg = 64
      assigns = []
      def replacer(match):
        global cur_reg
    
        val = match.group(1)
        cur_reg -= 1
        assigns.append( (assign, reg0+cur_reg, val) )
        return "{reg" + str(cur_reg) + "}"
    
      s = re.sub(p, replacer, s)
    
      if s[0] != "@":
        s = "@" + s
    
      return assigns + [(display_message, s)]
    extend_syntax(str_print)
  2. AgentSmith

    Warband Script Enhancer 2 (v1.1.2.0)

    bLuaDisableGameConstWarnings
    Excellent 👍 Didn't expect it to be in rgl_config..
  3. AgentSmith

    Warband Script Enhancer 2 (v1.1.2.0)

    Send code for testing.
    Here is some simple code that reproduces the errors:
    Code:
    plant_props = {}
    
    for inst in game.propInstI(2, 5) do -- propInstI([object_id], [object_type])
        table.insert(plant_props, inst)
    end
    Code:
    v1 = vector3.new()
    v2 = vector3.new()
    v2.x = 1
    print("vec: " .. tostring( v1:dist(v2) )) --prints 1, good
    
    p1 = game.pos.new().o
    p2 = game.pos.new().o
    p2.x = 1
    print("pos: " .. tostring( p1:dist(p2) )) --prints 0, not good
    
    r1 = game.preg[0].o
    r2 = game.preg[1].o
    print("reg: " .. tostring( r1:dist(r2) )) --error (dist is nil)

    I was also wondering, how can I supress the lua const warnings? wse_settings.ini doesn't seem to be used anymore. And in Documents\Mount&Blade Warband WSE2\ there is no corresponding file.
  4. AgentSmith

    Warband Script Enhancer 2 (v1.1.2.0)

    Hi, I'm getting some errors with 1.0.9.1:
    20:09:48 - Lua error: Modules\Napoleonic Wars\lua\modules\helper.lua:22: arg 2 must have type LUA_TUSERDATA|LUA_TTHREAD but is number
    20:09:48 - #Time: 20:9:48:505
    20:09:48 - stack traceback:
    20:09:48 - [C]: in function 'propInstI'
    20:09:48 - Modules\Napoleonic Wars\lua\modules\helper.lua:22: in function 'init_plant_grid'
    20:09:48 - Modules\Napoleonic Wars\lua\modules\helper.lua:118: in function <Modules\Napoleonic Wars\lua\modules\helper.lua:114>
    20:09:48 - Modules\Napoleonic Wars\lua\modules\eventMgr.lua:108: in function 'dispatch'
    20:09:48 - Modules\Napoleonic Wars\lua\modules\eventMgr.lua:44: in function <Modules\Napoleonic Wars\lua\modules\eventMgr.lua:43>

    20:09:55 - Lua error: Modules\Napoleonic Wars\lua\modules\helper.lua:90: attempt to call method 'dist' (a nil value)
    20:09:55 - #Time: 20:9:55:197
    20:09:55 - stack traceback:
    20:09:55 - Modules\Napoleonic Wars\lua\modules\helper.lua:90: in function <Modules\Napoleonic Wars\lua\modules\helper.lua:47>
    20:09:55 - Modules\Napoleonic Wars\lua\modules\eventMgr.lua:108: in function 'dispatch'
    20:09:55 - Modules\Napoleonic Wars\lua\modules\eventMgr.lua:121: in function <Modules\Napoleonic Wars\lua\modules\eventMgr.lua:113>

    helper.lua:22
    Code:
    for inst in game.propInstI(i, game.const.somt_flora) do
        table.insert(plant_props, inst)
    end

    helper.lua:90
    Code:
    local origin = game.preg[0].o
    if not game.position_is_behind_position(1, 0) and origin:dist(game.preg[1].o) > 2 then
        ...

    This code worked fine in WSE1.
  5. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Calling dofile will just execute the file and overwrite all functions in the global table (_G) with the functions from it. It's a bit like having
    Code:
       --b.lua
    a = 3
    
      --main.lua
    a = 5
    dofile(b.lua)
    ->a=3

    I'll give you some quick code to get you started. It's been a while so please excuse any mistakes. Also its probably not exactly what you need but I want to show the important concepts.
    If you haven't learned how tables and metatables work, I recommend you do some reading. It's really crucial to do abstractions in lua. There are no things like classes, its all up to the user to implement himself with these two.
    Code:
    -------BasicState.lua--------
    BasicState = {
      new = function()
        local obj = {} -- you can also init some stuff in here if you dont want them in BasicState itself
        setmetatable(obj, BasicState)
        return obj
      end,
    
      begin = function()
        error("Did not overwrite default begin()")
        --or maybe some default code?
      end,
    }
    
    ----------IdleState.lua-----------
    IdleState = {
      new = function()
        local obj = State.new()
        setmetatable(obj, IdleState)
        return obj
      end,
    
      begin = function()
    ....
    }
    setmetatable(IdleState, BasicState) --so the table returned by idlestate.new has metatable IdleState, which has metatable BasicState. This is the lua way to do inheritance
    
    ----------main.lua------------
    require("BasicState")
    require("IdleState")
    
    globalStates = {
      idle = IdleState.new(),
      ...
    }
    selectedState = nil
    
    function setState(state)
      selectedState = globalStates[state]
    end
    
    function exec(funcName, ...)
      if selectedState then --not nil
        selectedState[funcName](...)
      end
    end
    
    ----or----
    
    function exec(stateName, funcName, ...)
      if globalStates[stateName] and globalStates[stateName][funcName] then
        globalStates[stateName][funcName](...)
      end
    end
  6. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Q1:
    Code:
    ("wse_console_command_received", [ #this is a script that WSE adds
      (store_script_param, ":command_type", 1),
    
      (str_equals, s0, "@reloadMain"),
      (lua_push_str, "@main.lua"),
      (lua_call, "@dofile", 1), #one param, the string we pushed
      (set_trigger_result, 1),
    ]),
    Note that this does not reset the entire lua state. It just runs main.lua again, but it's fine in most situations.

    Q2: As the luaGuide says, main.lua will get executed at startup, nothing else. There you can set triggers and so on. It will also try to load all the constants and opcodes from msfiles/ so that you can use them directly.

    Q3: Yes it's normal, you can put
    Code:
    [lua]
    disable_game_const_warnings = 1
    in wse_settings.ini to get rid of it. It just means that wse doesn't fully understand some line - I haven't implemented full parsing  :grin:

    For calling lua scripts with an integer, the simplest way off the top of my head would be like so:
    Code:
    funcTable = {
      function(...) ... end, --remember this is [1] in lua
      function(...) ... end,
      ...
    }
    
    function call_index(index, ...)
      funcTable[index](...)
    end
    And just call call_index with an integer. But there are certainly prettier ways to do what you want.

    Hope this helps, don't be shy to ask more questions :grin:
  7. AgentSmith

    Modding Q&A [For Quick Questions and Answers]

    SupaNinjaMan said:
    So I'm trying to do a take on the Fancy Damage System to make it so that a certain group of troops only take quarter damage from someone who isn't of the same type (for lore reasons), and it looks like it should work, and it had in the past, but now when I test it the delivered damage isn't changing.

    Code:
    common_fate_damage_system = (
     ti_on_agent_hit, 0, 0, [],
    [
    	(store_trigger_param_1, ":agent"),
    	(store_trigger_param_2, ":attacker"),	
    	(store_trigger_param_3, ":damage"),
    	(store_trigger_param_3, ":orig_damage"),
    	(assign, reg11, ":orig_damage"),
    	(agent_get_troop_id, ":troop", ":agent"),
    	(agent_get_troop_id, ":attacker_troop", ":attacker"),	
    	(str_store_troop_name, s10, ":troop"),
    	(str_store_troop_name, s11, ":attacker_troop"),
    	
    	(try_begin),
    		(is_between, ":troop", servants_begin, servants_end), 
    		(try_begin),
    			(neg|is_between, ":attacker_troop", servants_begin, servants_end), 
    			(assign, ":mod_damage", ":damage"),		
    			(val_div, ":mod_damage", 4), # puts damage at 25%
    			(val_mul, ":mod_damage", 3),
    			(val_sub, ":damage", ":mod_damage"),
    			(assign, reg10, ":damage"),
    			(display_message, "@{s10} was hit by {s11} for {reg11} but has instead taken {reg10} damage instead!"),
    		(else_try),
    			(is_between, ":attacker_troop", servants_begin, servants_end), 
    			(display_message, "@Two Servants are fighting!"),
    		(try_end),
    	(try_end),	
    	
    	(store_sub, ":diff_damage", ":damage", ":orig_damage"),
    	(val_mul, ":diff_damage", -1),
    	(store_agent_hit_points, ":hitpoints" , ":agent", 1),
    	(val_add, ":hitpoints", ":diff_damage"),
    	(agent_set_hit_points,":agent",":hitpoints", 1),
    ])

    and while my display_message says the right numbers, the game system message will still say the full damage numbers.

    What am I missing here?

    Your code is a bit needlessly complicated but looks like it should work. Maybe you have to use set_trigger_result and you can also try setting the hitpoints one frame delayed, for some stuff this works wonders.
  8. AgentSmith

    Modding Q&A [For Quick Questions and Answers]

    [Bcw]Btm_Earendil said:
    Guitarma said:
    Hey guys,

    Quick question that I feel is kinda stupid. What happens if you compile your module while you have the game open? Will it cause errors? Every time I compile my module, I exit the game beforehand and relaunch it. Is this how it's supposed to be done or have I been wasting tons of time? I tried looking through the early tutorials I used when first starting, and just realized it never mentions one way or the other.

    Thanks!

    I did this also before (sometimes still) but Khamukkamu explained me that it is easier (and less time consuming) to work with the windowed mode. If you have the game in windowed mode, you can click there on 'View' and then 'Restore Module Data'. There are however two important notes to this:
    1) You have to quit to the main menu first, then use restore module data.
    2) If you have made changes to module.ini or one of the BRFs, then they won't show up. In this case you need to relaunch the game

    Holy smokes. Wish I'd have known that a few years earlier.
  9. AgentSmith

    [WB] Warband Script Enhancer v4.9.5 for 1.174

    Whats your error log?
  10. AgentSmith

    [WB] Warband Script Enhancer v4.9.5 for 1.174

    55th_Col_Armbresker said:
    Are they any youtube videos showing step by step instructions on how to install the script for people like me who just want to use it to make mods more smooth and don't get all the tech language ? OR can anyone write out step by step instructions?
    55th_Col_Armbresker said:
    make mods more smooth
    I am familiar with the codebase but AFAIK there is no performance benefit in installing WSE. At least not if your mods don't make use of the script extensions.
  11. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    Well, back to normal MS then. Just added the lua_call in the mission_templates and let it call a function on the trigger, which works fine now. Bit of a workaround, but ye.
    Was about to ask if it works in MS. Weird...
  12. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    I don't get why you don't just use the normal native + wse operations header. Seems like that would avoid a lot of trouble  :???:
  13. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    I tested it and it works just fine. Maybe there's something wrong with your operations header?
  14. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    Hey, me again.
    Got a small problem with the on_agent_killed_or_wounded trigger. Seems as if it always returns -1 for the Agent and the KillerAgent.
    I add the trigger by doing this:

    Code:
    function onDeath()
    	--trigger param 1: dead agent id
    	--trigger param 2: killer agent id
    	--trigger param 3: 0 = killed, 1 = wounded
    	--trigger result: 1 = force kill, 2 = force wounded
    
    	local AgentID = getTriggerParam(1);
    	local KillerAgentID = getTriggerParam(2);
    	local action = getTriggerParam(3);
    	
    	print("@Trigger: agentid "..AgentID);
    	print("@Trigger: agentid "..KillerAgentID);
    	
    	return true;
    end
    
    game.addTrigger("mst_conquest", game.const.ti_on_agent_killed_or_wounded, 0, 0, onDeath);
    AgentID and KillerAgentID are always -1 for some reason, not sure why tho.

    Hi,
    I don't know either, code seems fine. Check if "game.const.ti_on_agent_killed_or_wounded" has the correct value, check if "getTriggerParam" does its thing...
    If nothing works, upload your code (native compatible) and I'll have a look.
    Btw, you don't need "@" in your strings. Such barbarism is only for MS.
  15. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    Ah, no, it was server side.
    :grin:
    To be fair, it's not in the docu.
  16. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    No time to waste, next question  :eek:

    game.addPrsnt seems to be not defined anywhere. I don't know what to do there. I included all the common headers, but no where I am able to find the function addPrsnt.
    Silly question, but you're running this on client yes?
  17. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    How should it know which armor slot to use. Kinda seems a bit random to me.
    It probably uses "item_get_type". The types are listed in "header_items.py" and you can get item nos from "ID_items.py".
  18. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Oh pretty nice, I wish we had this in vanilla...
    I guess the problem then is that you pass strings to that script as the 2nd param.
    Code:
    self.gameRef.call_script(scriptChangeArmor, AgentID, "no_head");
    
    should be
    
    self.gameRef.call_script(scriptChangeArmor, AgentID, 12345);
  19. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    Bridge_Troll said:
    Trying to remove the spawn cloths after respawning.

    You can't. Either set their clothing before spawn or respawn them (and if you respawn, you have to use a timer. Can't happen on the same tick for some reason).
    Setting other items is no problem tho, there are operations for that.
    And yeah ms documentation is really an issue... You have to read a lot of code yourself, look at other mods... or ask on the forum  :grin:
  20. AgentSmith

    WSE - Lua edition [Beta], a new way of scripting

    It depends on your setup. I personally don't have much experience besides server-side modding in native.
    If your code is running on both sides, you can use "multiplayer_is_server" and "multiplayer_is_dedicated_server" to control what to run. For example, hotkey triggers would have a no-server condition. Server announcements get a server-only condition.
    Not sure right now but I think most events trigger on client as well.

    If you're on the server only, what you do is send events to the clients you want. They receive it in "game_receive_network_message" and do their thing.
    One event that exists in native by default is "multiplayer_event_show_server_message". So you could send a message to a client like "(multiplayer_send_string_to_player, ":player_no", multiplayer_event_show_server_message, "@text")". But you have no control over the color because that's client side. You have full rbg in display_message but no alpha I think, maybe you wanna test that.
    So if you want to execute code on a client and it's triggered by the server, it must exist in the installed client module and be triggered by a server event via the network script.
Back
Top Bottom