Jump to content

Recommended Posts

Hi

I'd like to lock a function behind the name of the player using it, as a means to prank my friend.

Essentially the function should only trigger if the player's username is as written. I'm looking for the function to trigger when he's using the custom character himself.

I tried these (separately)

if UserToPlayer('namehere') then

if UserToPlayer() == 'namehere' then

if UserToPlayer = ('namehere') then

but none of these seem to work. 

I tried ThePlayer but apparently this one prints random strings of numbers as a means to identify players, but it changes every game.

is there some obvious thing I'm missing?

 

Link to comment
https://forums.kleientertainment.com/forums/topic/104448-player-name-check/
Share on other sites

If you just want to call a function when a certain player joins, you can do this:

AddPlayerPostInit(function(inst)
	if inst.name == 'somename' then
		-- do something
	end
end)

You can check the same variable, inst.name, whenever you're doing something where you have an instance of a player.

On 4/2/2019 at 12:47 AM, Ultroman said:

If you just want to call a function when a certain player joins, you can do this:

AddPlayerPostInit(function(inst)
	if inst.name == 'somename' then
		-- do something
	end
end)

You can check the same variable, inst.name, whenever you're doing something where you have an instance of a player.

Could this apply/adapt to detect other player name who playing a custom character?
Like when this script put into a custom character and when a player with not the name set in the script playing this custom character, will do something or change stats? (´・ω・`)

46 minutes ago, Nicodesu said:

Could this apply/adapt to detect other player name who playing a custom character?
Like when this script put into a custom character and when a player with not the name set in the script playing this custom character, will do something or change stats? (´・ω・`)

You can use ~= instead of == to make the statement be a NOT statement instead of EQUAL TO, so for example if your character's prefab is somename, you can do this:

AddPrefabPostInit("somename", function(inst)
    if not TheWorld.ismastersim then -- This has to be GLOBAL.TheWorld.ismastersim ONLY IF you haven't defined TheWorld as global via any means.
        return
    end

    -- If a player plays your modded character, and their (Steam user)name is NOT "allowedname", then this code will run.
    -- If they're named "allowedname", then nothing happens.
    if inst.name ~= "allowedname" then
        --do something
    end

end)

 

19 hours ago, Baguettes said:

You can use ~= instead of == to make the statement be a NOT statement instead of EQUAL TO, so for example if your character's prefab is somename, you can do this:

AddPrefabPostInit("somename", function(inst)
    if not TheWorld.ismastersim then -- This has to be GLOBAL.TheWorld.ismastersim ONLY IF you haven't defined TheWorld as global via any means.
        return
    end

    -- If a player plays your modded character, and their (Steam user)name is NOT "allowedname", then this code will run.
    -- If they're named "allowedname", then nothing happens.
    if inst.name ~= "allowedname" then
        --do something
    end

end)

 

Ah, oki, appreciate the help, will give it a try... and, where me put this? modmain, me presume? (´・ω・`)

EDIT - Got a bit confuse with the steam user name, has it need to be the name when using to login or the name that shows on the steam page? Since the script gave effect either wrong name or correct name. or if there a way to detect KU_xxxxx in game instead to lessen the confusion?

Edited by Nicodesu
Added something again?
8 hours ago, Nicodesu said:

Ah, oki, appreciate the help, will give it a try... and, where me put this? modmain, me presume? (´・ω・`)

EDIT - Got a bit confuse with the steam user name, has it need to be the name when using to login or the name that shows on the steam page? Since the script gave effect either wrong name or correct name. or if there a way to detect KU_xxxxx in game instead to lessen the confusion?

inst.name is the name shown in-game, if you want the KUID you can use inst.userid instead. userid usually holds KUID.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...