WB Coding How to find the valid agent ref for the player character? (singleplayer)

正在查看此主题的用户

Leonea9

Recruit
Hello,

I am trying to test "agent_set_animation" on the player with some random animation.
Comparing to other scripts I found in the module system, I tried doing:

("myscript_animation_try",
[
(get_player_agent_no, ":agent_no"),
(agent_set_animation, ":agent_no", "anim_stand_townguard"),
]),


And then call "script_myscript_animation_try" via an item.

However, in-game I get an error that says ":agent_no" is invalid (-1)

So, how do I get a valid value? :smile:


Thank you in advance :smile:
 
replace with this:
插入代码块:
("myscript_animation_try",
[
(get_player_agent_no, ":player"),
(agent_set_animation, ":player", "anim_stand_townguard"),
]),
 
点赞 0
Not sure what BladeofWar's suggestion changes apart from the variable name...?

Please provide some more info:
- How exactly are you currently calling your script? (which trigger are you using?)
- As Eärendil pointed out, SP or MP?
 
点赞 0
It's for singleplayer.

I am using the item trigger (in module_items)

[(ti_on_init_item, [(call_script, "script_myscript_animation_try")])]],

I am a little confused about the difference between agent_no and agent_id.
I know agent id is meant for multiplayer, however in header_operators it says you need to use agent id for agent_set_animation...
 
点赞 0
Apologies for the delay.
First of, there isn't really a difference between agent_no and agent_id - it's just a variable name, and you can call those whatever you like. When you see agent_id or agent_no somewhere in the header files, they should refer to the same thing.

For the problem at hand, I'm not entirely sure where the problem is located. It might be just some general MBScript weirdness or perhaps you have other agents that have the same item you have being spawned in before you are?

Here's two things you could try out:
1. ti_on_init_item has a parameter that gives you the wielding agents ID - you could pass that on to your script and use it rather than what you get from get_player_agent_no (this should also set the animation for bots with the item)
Python:
ti_on_init_item               = -50.0 # Item mesh has been created.
    # trigger param #1 = agent_id who has this item equipped (-1 if none)
2. use a ti_on_agent_spawn trigger for the mission templates you're using, [compare the spawned agents ID to yours and if it's the same,] set the animation.
 
点赞 0
后退
顶部 底部