Set target_name of Player

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Set target_name of Player

Postby decompile » Fri Jan 20, 2017 1:12 am

Hey,

I tried to set the "target_name" of a user hooked via the Player instance.

Im getting the attribute, cant set error.

Is there another way to do it, since on some maps the mappers can easily change the target_name of a player, either to use it with filters or anything else.

Code: Select all

{
    "OnStartTouch" "!activator,AddOutput,targetname player_LVL4_2,1,-1"
    "StartDisabled" "0"
    "classname" "trigger_multiple"
    "filtername" "filter_LVL4_2"
    "hammerid" "126635"
    "model" "*83"
    "origin" "-3012 544 240"
    "spawnflags" "1"
    "wait" "0.000000000000001"
}
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Set target_name of Player

Postby L'In20Cible » Fri Jan 20, 2017 1:16 am

The attribute target_name should be available for all entities. I will look into why it raise an error. What is the complete code you are using? In any case, you can use the following to set it:

Syntax: Select all

player.set_keyvalue_string('targetname', '<name>')


EDIT: I just tested the following:

Syntax: Select all

from players.entity import Player

player = Player(1)
print(player.target_name)
player.target_name = 'test'
print(player.target_name)

And here was the result:

Syntax: Select all

# >>>
# >>> test
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Set target_name of Player

Postby decompile » Fri Jan 20, 2017 1:27 am

L'In20Cible wrote:The attribute target_name should be available for all entities. I will look into why it raise an error. What is the complete code you are using? In any case, you can use the following to set it:

Syntax: Select all

player.set_keyvalue_string('targetname', '<name>')


EDIT: I just tested the following:

Syntax: Select all

from players.entity import Player

player = Player(1)
print(player.target_name)
player.target_name = 'test'
print(player.target_name)

And here was the result:

Syntax: Select all

# >>>
# >>> test


Aww, Im just gonna blame it on the late time..

Thank you, it works.

My mistake was, that I was trying to change it with a @property from my own player class which just returned the target_name instead of using it from the Player class.

BTW: Can I multiply a Vector by a specific amount? Lets say I get the base velocity of a player, and I want to multiply it by 1.2x, can I do it better than multiplying each x y z and making it a new vector? Sorry for my grammar
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Set target_name of Player

Postby L'In20Cible » Fri Jan 20, 2017 1:30 am

decompile wrote:BTW: Can I multiply a Vector by a specific amount? Lets say I get the base velocity of a player, and I want to multiply it by 1.2x, can I do it better than multiplying each x y z and making it a new vector? Sorry for my grammar
Please, create one question per thread; makes it easier for user searches. :wink:

To answer your question, yes. And this is as easy as doing:

Syntax: Select all

from mathlib import Vector

vector = Vector(1, 1, 1)
print(vector * 2)
# >>> Vector(2.0, 2.0, 2.0)
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Set target_name of Player

Postby decompile » Fri Jan 20, 2017 1:31 am

Thanks, good to know then.

Didnt know if I should spam threads with one question each, or do it as some other forums with making a "mega" help thread for an user. lol :P
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Set target_name of Player

Postby L'In20Cible » Fri Jan 20, 2017 1:36 am

Example of how messy a thread with multiple unrelated questions can get: viewtopic.php?f=20&t=1019#p6564

Fun fact, it's your own thread. :tongue:

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 38 guests