PYTHON SCRIPT/SCHEME EXCHANGE

Users who are viewing this thread

Highlander said:
Sorry, Colt, for for breaking your monopoly.
The formation code:

in module_scripts:
========================
("formation_start",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
  (try_for_range,reg(20),1,100), #reset of the player dummy-slots
  (agent_set_slot,reg(10),reg(20),0),
  (try_end),
          (try_for_agents,reg(5)),
             (assign,reg(0),0),
             #Not the player
             (neq, reg(5), reg(10)),
             #Not Dead
             (agent_is_alive, reg(5)),
             #Not a Horse?
             (agent_is_human, reg(5)),
             #If the Selected Troop is an Ally
             (agent_is_ally,reg(5)),
  (assign,reg(1),1),
(try_begin),
    (assign,reg(20),1), #reg(20) is the agent number to use every position only once
    (agent_get_slot,reg(21),reg(10),reg(20)), #player agent used as a dummy not to make several agent use one position
    (eq,reg(21),0), #number isn't used, yet
    (assign,reg(1),reg(20)),
(assign,reg(3),reg(1)),
(val_mul,reg(3),100),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)), #number 1 = 100 metres right to the player agent 2= 200 etc...
(agent_set_scripted_destination,reg(5),reg(1)), #tells the agent to run there
    (agent_set_slot,reg(5),1,reg(1)), #tells the agent which position he has - only important if you want to do somethink else with the script, it would work without it right now.
(agent_set_slot,reg(10),reg(20),1), #tells the game that the number is used, by using the player slots.
(else_try),
#very odd, sorry (the more call_scripts are there \/, the more agents will build a formation
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),
  (try_end),  
(try_end),
]),
("formation_repeat",
[     (val_add,reg(20),1), # adds 1 to the agent number
    (agent_get_slot,reg(21),reg(10),reg(20)),
    (eq,reg(21),0), # again, is the number already used?
    (assign,reg(1),reg(20)), #just copying the number to use it somewhere else...
(assign,reg(3),reg(1)), #again copying
(assign,reg(4),0), #assigns the row of this agent to 0
#-#-#-#-#-#-#-#-#-#
(try_for_range,reg(15),1,100), #this try-code assigns the right row.
(assign,reg(17),reg(15)),
(assign,reg(16),reg(15)),
(val_mul,reg(15),5), #number of troops in one line
(val_mul,reg(16),5), #has to be the same as above
(val_add,reg(16),5), #has to be the same as above
(gt,reg(3),reg(15)),
(le,reg(3),reg(16)),
(assign,reg(15),reg(17)),
(val_mul,reg(15),6), #number of troops in one line + 1
(val_sub,reg(3),reg(15)),
(assign,reg(4),reg(17)),
(try_end),
#delete these lines to get a 1 line formation
#-#-#-#-#-#-#-#-#-#

(val_mul,reg(3),100),
(val_mul,reg(4),200),
(copy_position,reg(1),1),
(position_move_x,reg(1),reg(3)),
(position_move_y,reg(1),reg(4)),
(agent_set_scripted_destination,reg(5),reg(1)),
    (agent_set_slot,reg(5),1,reg(1)),
(agent_set_slot,reg(10),reg(20),1),
]),
========================
100 is the distance between the agents from right to left,
200 is the distance between the agents from the front to background


how to use:
add [(ti_on_weapon_attack,[(call_script,"script_formation_start")])] to the weapon that should cause the formation
!Don't change the distance to less than 70 in a line formation, less than 100 otherwise! The guys will build the formation after weapon attack on your right hand site. The max. number of agents is 40 right now.
Everyone feel free to use it, would be nice if I get credit.
Screenshot? Here you go:
formationdq3.jpg


i make this whit ctrl+c ctrl+v and i got this error:
int object is unsocrptable what i am makeng wrong this only hapens wen i add [(ti_on_weapon_attack,[(call_script,"script_formation_start")])] to the end of the weapon and they become:
["formation_sword",        "Infantry sword", [("cheap_sword",0),("cheap_sword", ixmesh_carry)], itp_type_one_handed_wpn|itp_merchandise|itp_primary, itc_longsword|itcf_carry_sword_left_hip|itcf_show_holster_when_drawn, 148 , weight(1.5)|difficulty(0)|spd_rtng(100) | weapon_length(102)|swing_damage(34 , cut) | thrust_damage(30 ,  pierce),imodbits_sword [(ti_on_weapon_attack,[(call_script,"script_formation_start")])]],
pls help me
 
["formation_sword",        "Infantry sword", [("cheap_sword",0),("cheap_sword", ixmesh_carry)], itp_type_one_handed_wpn|itp_merchandise|itp_primary, itc_longsword|itcf_carry_sword_left_hip|itcf_show_holster_when_drawn, 148 , weight(1.5)|difficulty(0)|spd_rtng(100) | weapon_length(102)|swing_damage(34 , cut) | thrust_damage(30 ,  pierce),imodbits_sword ,[(ti_on_weapon_attack,[(call_script,"script_formation_start")])]],
 
question on this... perhaps it already been addressed....

but since the inventory command has been deactivated for battle, can't this be re-tagged nad activated to drawing the formation command? maw
 
good idea, that... but it does mean only the player's troops can be ordered into formations.
I use ti_on_init_item for mine, and have experimented with different ways of having the enemy parties use the commands too....  It's not hugely successful yet...


different theme:
If one wanted to create an NPC, would it be possible to have a menu option which would be a close copy of the start-game character menus, but instead of creating the player, create an NPC as companion?
I think the main problem would be how to make the game recognise the newly created NPC as such...
Any thoughts?
 
Amman - yes, it's possible.  You can change any troop's stats, not just the PC's, using those commands.

I suggest you check out Schattenlander and you'll see this already in action.
 
Amman de Stazia said:
good idea, that... but it does mean only the player's troops can be ordered into formations.
I use ti_on_init_item for mine, and have experimented with different ways of having the enemy parties use the commands too....  It's not hugely successful yet...


different theme:
If one wanted to create an NPC, would it be possible to have a menu option which would be a close copy of the start-game character menus, but instead of creating the player, create an NPC as companion?
I think the main problem would be how to make the game recognise the newly created NPC as such...
Any thoughts?

Just don't spawn the npc until you 'create' him/her. 
 
Or spawn them with temporary stats and have their gear in that scene not depend on the character creation process for some reason - for example because they're in civvies at the time.
 
The only problem is the facecodes and name are hardcoded.  Being able to change these would definitely be nice....
 
Speak it, brother.

Sounds like in Edit mode we might be able to let them change their face codes, though; someone mentioned that earlier.  That's something, at least, although I don't like having to run in Edit mode.  Could explain the option in a tutorial, though; I may, although I'm pretty happy with my NPC faces overall right now.
 
wow I actually managed to get the formation code to work however, I assigned it to a jarid, (well a variation doing 0 damage), but how do you make the the weilder attack automatically as soon as battle starts, or is there a way to increase range of weapon cuz troops attack as soon aas there in range (at least Ithink so).
 
upgrading items:

What is a nice clean way to get Python to assign an imodbit to the currently equipped items?  And, to do it in such a way that when it is unequipped, it does not lose the imodbit?

What I am trying to do is have items upgraded: The player must equip the item, then speak to a particular NPC.  This will trigger that the item is upgraded with my new modifier 'upgraded'.

I am thinking along the lines of assigning a slot to 'equipped weapon 1' and then replacing 'equipped weapon 1'  with 'equipped weapon 1_imodbit_upgraded'

I'd just like a little help....
 
Right now there's no way to equip an item on the player at all, or to modify one in situ.  I'm afraid what you're going for is literally impossible right now.  I suggest you take a leaf from Craftmod's book and, rather than triggering it on the player equipping it (which is the one thing you can't touch), trigger it on the player giving it to a chest-like item or just to the upgrading NPC.
 
OK, that's just as good - after all, I'd have to hand over for the master smith to upgrade it.
And I am right in thinking, that python can IDENTIFY the item?  Ie, if I hand over a bastard sword, then it can be registered as 'slot_41' or suchlike, then handed back as bastard sword_upgraded?

If I get something coherent, I'll post the script up here...
 
will this work??

    [trp_cobbler,"start", [[eq,"$craftsman_introduced"]], "Hello there. I'm a bit busy now, is it important?.",
    "craftsman_request_1"],
  [trp_cobbler|plyr,"craftsman_request_1", [], "Well, I have a good pair of boots that I am fond of, but they don't offer much protection for a fighter like myself.  Can you do some work on them and fix that please?", "craftsman_request_2",[]],
  [trp_cobbler,"craftsman_request_2", [], "Certainly, young {man/lady}  It will cost you a pretty penny though, my skills are not cheap. Can I see the item in question?", "craftsman_request_3",[(change_screen_trade)]],
  [trp_cobbler|plyr,"craftsman_request_3", [], "So, why did you give me money? .", "craftsman_request_4",[(troop_get_inventory_slot,reg1,trp_cobbler,1),]],
  [trp_cobbler,"craftsman_request_4", [], "It is a receipt-bond.  It guarantees that I will do the work and not sell your property to anybody else.", "craftsman_request_5",[]],
  [trp_cobbler|plyr,"craftsman_request_5", [], "When can I pick it up?", "craftsman_request_6",[(troop_remove_item,trp_cobbler,reg1,),(troop_add_item,trp_cobbler,reg1,[imod_upgraded]),]],
  [trp_cobbler,"craftsman_request_6", [], "I will not take long.  My speed at work is almost as legendary as my skill!", "craftsman_request_7",[(change_screen_trade)]],
  [trp_cobbler|plyr,"craftsman_request_7", [], "Wow! That was fast.  Thank you, Master Craftsman! You are truly worthy of your title!", "close_window",[]],
 
Yeah, that'll work, for the most part.  Your use of get_inventory_slot isn't correct - you need to name a numbered slot, which is far from ideal for your purposes; for one thing, slots 0-9 are the "equipped items" slots, the classical inventory starts at 10, so you'd need to name slot 10.  But then what happens if they player slops it into the NPC inventory not in slot 10?  I'm not sure when the NPCs' "auto-cleanup" functions kick in.  Nor do you have any checks that (a) this is indeed a pair of boots, nor that (b) they've only handed over one item, or indeed (c) that they handed over anything at all.

If you want to use get_inventory_slot then you need to (try_for_range) across the inventory slots 10 through (get_inventory_capacity).  Probably better, use (try_for_range) from some defined boots_begin to boots_end, using (store_item_kind_count) to log the total for each item.  [If you check "does this troop have it equipped" and subtract one from the count if so, you'll neatly avoid the issue of what the cobbler's wearing on his own feet.]  You could also use the loop over itemIDs to do your "is this a nonboot item?" check - just loop from the first item in your mod to the last, and if you spot anything that's not a boot, flag that fact and return to the dialogue with a "I can't fix that up!" line (and then reopen the trade/loot screen so they can take it back).  Basically if you count the number of every item in the game, subtract one if that item's equipped, and set a global if you ever spot a nonboot item, then the total count (zero, one, or 2+) plus the "not a boot" flag will give you all the possible outcomes of the trading screen, which you can then reflect in dialogue.  Only the zero-items or the one-item-and-it's-a-boot outcomes don't immediately send them back to the trade screen, which means they can't leave the dialogue with an inappropriate state of things.

You've got some options here, by the way; if you use change_screen_loot instead of change_screen_trade, then no money will change hands.  Also, right now your upgrading dialogue will turn any imod (from "ragged" to "hardened") into "upgraded".  Certainly this is much easier than writing imod identification, just something you should be aware of.
 
Thanks Highlander, that formation script works awesomely! :grin:
http://img402.imageshack.us/my.php?image=formationlj4.png
http://img338.imageshack.us/my.php?image=formationafterbattlelh2.png
Just look at that! What I must know though, is how can I change the identifiers on the agent so that only enemies form up, rather than only friends?
 
hellequin - you are, in fact, a genius - I am very impressed how you understood what I was trying to do and then wrote up such a good explanation for how to actually do it!  Now I have to apply your explanation to python... we'll see how that goes...

thanks heaps!

Do you want to be featured as, for example, master tailor hellequin?
 
Back
Top Bottom