Page 1 of 1

Set target_name of Player

Posted: Fri Jan 20, 2017 1:12 am
by decompile
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"
}

Re: Set target_name of Player

Posted: Fri Jan 20, 2017 1:16 am
by L'In20Cible
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

Re: Set target_name of Player

Posted: Fri Jan 20, 2017 1:27 am
by decompile
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

Re: Set target_name of Player

Posted: Fri Jan 20, 2017 1:30 am
by L'In20Cible
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)

Re: Set target_name of Player

Posted: Fri Jan 20, 2017 1:31 am
by decompile
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

Re: Set target_name of Player

Posted: Fri Jan 20, 2017 1:36 am
by L'In20Cible
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: