Force key press for dropping weps?

Users who are viewing this thread

Muzzle C

Sergeant Knight
Heya,

I'm struggling to make agent drop a ranged, or thrown weapon on demand.
It's fairly easy to make agent drop a single weapon by spawn_item and agent_unequip_item , but when it comes to quantity of ammo or thrown weps, it get's complicated.

I need to store the quantity of thrown weps or ammo to the item that gets spawned to the scene.
I'm not sure how to do this..

However, Warband has hardcoded function for dropping weapon on key press.
I could easily bypass this issue by initializing a keypress on agent for gk_drop_weapon.

Is there any way to force a keypress so that the trigger (key_clicked, gk_drop_weapon), would apply?

Thanks in advance.. I hope someone has some sort of suggestion.
 
to be straight: no there is no "click_key" or "click_game_key" command, you need to do it the hard way.

to store the ammo, use a dummy troop and store the ammo in it's slots.
also:
Code:
# Scene items operations

scene_item_get_num_instances                = 1830  # (scene_item_get_num_instances, <destination>, <item_id>),
                                                    # Gets the number of specified scene items present on the scene. Scene items behave exactly like scene props (i.e. cannot be picked).
scene_item_get_instance                     = 1831  # (scene_item_get_instance, <destination>, <item_id>, <instance_no>),
                                                    # Retrieves the reference to a single instance of a scene item by it's sequential number.
scene_spawned_item_get_num_instances        = 1832  # (scene_spawned_item_get_num_instances, <destination>, <item_id>),
                                                    # Retrieves the number of specified spawned items present on the scene. Spawned items are actual items, i.e. they can be picked by player.
scene_spawned_item_get_instance             = 1833  # (scene_spawned_item_get_instance, <destination>, <item_id>, <instance_no>),
                                                    # Retrieves the reference to a single instance of a spawned item by it's sequential number.

replace_scene_items_with_scene_props        = 1891  # (replace_scene_items_with_scene_props, <old_item_id>, <new_scene_prop_id>),
                                                    # Replaces all instances of specified scene item with scene props. Can only be called in ti_before_mission_start trigger in module_mission_templates.py.

set_spawn_position                          = 1970  # (set_spawn_position, <position>) ## DUPLICATE ENTRY
                                                    # Defines the position which will later be used by (spawn_scene_prop), (spawn_scene_item), (spawn_agent) and (spawn_horse) operations.
spawn_item                                  = 1971  # (spawn_item, <item_kind_id>, <item_modifier>, [seconds_before_pruning]),
                                                    # Spawns a new item, possibly with modifier, on the scene in the position specified by previous call to (set_spawn_position). Optional parameter determines time period (in second) after which the item will disappear. Using 0 will prevent the item from disappearing.
spawn_item_without_refill                   = 1976  # (spawn_item_without_refill, <item_kind_id>, <item_modifier>, [seconds_before_pruning]),
 
Many thanks Ikaguia. I'll try this method today.
It's for the reason of making a native multiplayer server with only one equipable weapon.
 
Hmm, probably I misunderstood your objective then.

Actually, what are you trying to achieve? A mission with only one equippable weapon - meaning if player tries to pick up a weapon, he automatically drops his current one? Because that might be possible to achieve by filling 3 slots out of player's 4 with unremovable unusable items (like shields with insanely high prerequisite, or firearm cartridges when player has no way of buying firearms...).
 
Lav said:
Hmm, probably I misunderstood your objective then.

Actually, what are you trying to achieve? A mission with only one equippable weapon - meaning if player tries to pick up a weapon, he automatically drops his current one? Because that might be possible to achieve by filling 3 slots out of player's 4 with unremovable unusable items (like shields with insanely high prerequisite, or firearm cartridges when player has no way of buying firearms...).

Here, i'll explain the whole concept of the server:

-Native Warband DM server
-Agents cannot buy any weapons, nor armour, but they spawn with a random knife and with random wear
-Scenes are filled with pickable items, which include all weapon types and shields
-Agents can only pickup one weapon at the time > If agent already has a weapon, it will be dropped. Shields and knives however will not have effect on this.

I have everything done expect for those ammos when weapon is dropped.
When agent dies, i simply wield his ranged/throwing weapon, so that the warband stores the amount of remaining ammo.
The server has already been up for some time, but with unfinished features. The server is called CC_Knifeparty. (Obviously knives are the main theme :wink:)

I tried the method of having players slots filled, but i couldn't make it work..
Since there is a possibility to unwield weapon, or to have multiple items in inventory, it would be needed to wield the corresponding weapon BEFORE ti_on_item_picked_up.
If i'm correct, the hardcoded function to drop currently wielded weapon applies before this trigger..
I need to test it again tho, since i was on slow mood yesterday.

EDIT:
-Agent drops all his weapons/shields when it dies (done)
 
Hmm...

Just a random idea.

Create an invisible neutral agent, and whenver you want some stuff dropped, equip that stuff on your Invisible Man, teleport him to required point, kill him and resurrect/respawn him immediately with no items. :smile:
 
You can start a pair of presentations at the start that only ends when players press their normal and "alternate" pick up and drop keys respectively and saves the key codes into player slots, bypassing hardcoded picking up and dropping altogether. When the alternate drop key is pressed, you'll "drop" the currently-wielded/used weapons while the alternate pick up key only picks up and buries the nearest item prop in the vicinity if it's not out of place and you have an empty slot. When dropping ammo, just spawn a bunch of missiles.
 
Lav said:
Hmm...

Just a random idea.

Create an invisible neutral agent, and whenver you want some stuff dropped, equip that stuff on your Invisible Man, teleport him to required point, kill him and resurrect/respawn him immediately with no items. :smile:

Wow, that's a great idea.. Will try that thanks :grin:
BTW, tried again to wield a corresponding weapon on ti_on_item_picked_up.. I was right, the hardcoded weapon drop happens before this trigger applies.

Dusk Voyager said:
You can start a pair of presentations at the start that only ends when players press their normal and "alternate" pick up and drop keys respectively and save the key codes into player slots, bypassing hardcoded picking up and dropping altogether. When the alternate drop key is pressed, you'll "drop" the currently-wielded/used weapons while the alternate pick up key only picks up and buries the nearest item prop in the vicinity if it's not out of place and you have an empty slot. When dropping ammo, just spawn a bunch of missiles.

Hmm, not understanding this completely.. Since i'm fairly new to modding i've got to read this couple of hundred times to understand :smile:
 
Still not sure what Dusk Voyager meant, but i came up with this script

Code:
	(0, 0, 0, [],
    [
		(multiplayer_is_server),
		(get_player_agent_no, ":player_agent"),
		(agent_is_active,":player_agent"),
		(agent_is_alive,":player_agent"),
		(agent_is_human,":player_agent"),
		(try_begin),
			(game_key_clicked, gk_action),
			(agent_get_item_slot,":slot1",":player_agent",ek_item_0),
			(agent_get_item_slot,":slot2",":player_agent",ek_item_1),
			(agent_get_item_slot,":slot3",":player_agent",ek_item_2),
			(agent_get_item_slot,":slot4",":player_agent",ek_item_3),
			(try_begin),
				(item_get_type,":weapon_type1",":slot1"),				
				(this_or_next|eq,":weapon_type1",itp_type_bow),
				(this_or_next|eq,":weapon_type1",itp_type_crossbow),
				(this_or_next|eq,":weapon_type1",itp_type_thrown),
				(eq,":weapon_type1",itp_type_pistol),
				(agent_set_wielded_item,":player_agent",":slot1"),
				(try_begin),
					(le,":slot2",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot3",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot4",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
			(try_end),
			(try_begin),
				(item_get_type,":weapon_type2",":slot2"),				
				(this_or_next|eq,":weapon_type2",itp_type_bow),
				(this_or_next|eq,":weapon_type2",itp_type_crossbow),
				(this_or_next|eq,":weapon_type2",itp_type_thrown),
				(eq,":weapon_type2",itp_type_pistol),
				(agent_set_wielded_item,":player_agent",":slot2"),
				(try_begin),
					(le,":slot1",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot3",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot4",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
			(try_end),
			(try_begin),
				(item_get_type,":weapon_type3",":slot3"),				
				(this_or_next|eq,":weapon_type3",itp_type_bow),
				(this_or_next|eq,":weapon_type3",itp_type_crossbow),
				(this_or_next|eq,":weapon_type3",itp_type_thrown),
				(eq,":weapon_type3",itp_type_pistol),
				(agent_set_wielded_item,":player_agent",":slot3"),
				(try_begin),
					(le,":slot1",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot2",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot4",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
			(try_end),
			(try_begin),
				(item_get_type,":weapon_type4",":slot4"),				
				(this_or_next|eq,":weapon_type4",itp_type_bow),
				(this_or_next|eq,":weapon_type4",itp_type_crossbow),
				(this_or_next|eq,":weapon_type4",itp_type_thrown),
				(eq,":weapon_type4",itp_type_pistol),
				(agent_set_wielded_item,":player_agent",":slot4"),
				(try_begin),
					(le,":slot1",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot2",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
				(try_begin),
					(le,":slot3",1),
					(agent_equip_item,":player_agent",2),
				(try_end),
			(try_end),
		(try_end),
				
    ])		 

	(ti_on_item_picked_up, 0, 0, [(multiplayer_is_server),],
       [
	    (store_trigger_param_1,":agent_no"),
	    (try_begin),
		  (agent_is_active,":agent_no"),
		  (agent_is_alive,":agent_no"),
		  (agent_is_human,":agent_no"),
		  (neg|agent_is_non_player,":agent_no"),
		  (agent_unequip_item,":agent_no",2),
		(try_end),
         ])

This code wield's the agents ranged/thrown weapon when action key is pressed and fills all the empty equipment slots.
It happens before the actual item gets picked up.
When item is picked up it frees the slots that were filled.

This script would work if i could make it trigger only when agent is trying to pick up an item.
Now it of course triggers everytime the key is pressed..
I would need to get the item type of that item, so that it wouldn't trigger when picking up ammo etc..
The answer for this problem could be this presentation shown in the picture:
knife_presentation.jpg
However, this little textbox seems to be hardcoded, since i can't find any reference to it..

Another method could be to use agent_get_look_position and check if there is items around this position. This however is quite unaccurate method, since there can be multiple items stacked very close to each other..

If you guys have any idea for this thing, please tell..
 
Why not using the classic scene props slots?

What you do is this: when a player picks an item, first get it's type, then establish what it is (is melee, ranged or ammo) then loop throu the player's equipment and drop all items that are the same thing as the item (if the player had a sword and he picked sword, then drop the first sword).

For saving the ammo you need to use scene slots. Go into module constants and make a new one.

If the players drops an ammo type item (or you need to 'drop' it using a script) then once you got the scene item id, you set it's slot to how much ammo that item had before it got dropped (I think that you can check for ammo in the ti_on_item_drop trigger).
If the player picks up ammo, get the scene item id, then read that slot and then set the specific ammo value.
 
The_dragon said:
Why not using the classic scene props slots?

What you do is this: when a player picks an item, first get it's type, then establish what it is (is melee, ranged or ammo) then loop throu the player's equipment and drop all items that are the same thing as the item (if the player had a sword and he picked sword, then drop the first sword).

For saving the ammo you need to use scene slots. Go into module constants and make a new one.

If the players drops an ammo type item (or you need to 'drop' it using a script) then once you got the scene item id, you set it's slot to how much ammo that item had before it got dropped (I think that you can check for ammo in the ti_on_item_drop trigger).
If the player picks up ammo, get the scene item id, then read that slot and then set the specific ammo value.

Hmm, using the scene prop slots is new to me.. I might as well try this. Thanks Dragon.

I now have 3 options for storing ammo amount into dropped item:
Dummy troop, scene prop slots, Dummy agent. I think the agent thingie won't work as well as i first thought, since when agent dies, there is a delay for spawning the wielded item.
There is also the sound when agent dies, which should be disabled on that dummy.

Scripting is very slow for me, since im noob with this thing, so it takes time for me to test the ****.
I'll get back to you when i have something to tell.

Anyways.. i'd still like to know about this textbox..
knife_presentation.jpg
 
Muzzle of CC said:
Anyways.. i'd still like to know about this textbox..
knife_presentation.jpg

Yes it is.

You are overcomplicating your problem by thinking outside the box. This can be done 100% server side (with the method that I described), so forget about getting if the player hit the use button, if he can possible pick up an item or not and so on.

If you are newbie at this, then it is recommended to script from simple to more complicated stuffs. First try and make your item drop script (which takes two arguments: agent id and the weapon slot); then make the script(s)/trigger(s) that will handle melee weapons only (when player picks up an item, you drop all other items that he has (using calls to the drop_item script)). When you succeed, you start thinking of how to add ranged and shields and ammo into the system. Think of how to modify the drop_item script so it will work for ammo and so on.

Good luck with your mod!
 
The_dragon said:
Muzzle of CC said:
Anyways.. i'd still like to know about this textbox..
knife_presentation.jpg

Yes it is.

You are overcomplicating your problem by thinking outside the box. This can be done 100% server side (with the method that I described), so forget about getting if the player hit the use button, if he can possible pick up an item or not and so on.

If you are newbie at this, then it is recommended to script from simple to more complicated stuffs. First try and make your item drop script (which takes two arguments: agent id and the weapon slot); then make the script(s)/trigger(s) that will handle melee weapons only (when player picks up an item, you drop all other items that he has (using calls to the drop_item script)). When you succeed, you start thinking of how to add ranged and shields and ammo into the system. Think of how to modify the drop_item script so it will work for ammo and so on.

Good luck with your mod!

Thanks. I'm newbie allright, but have learned alot in a short time.
I've already made a item drop script with handling different weapon types. I decided to put that script aside, since i thought there is easy way for storing ammo data with warband's hardcoded drop weapon function..
Apparently that is not a easy way.. Next i have to start learning how to use slots for storing and retrieving data.

 
Back
Top Bottom