[Solved] Add player name as property of added LuaEntity

User avatar
ratmix
Member
 
Posts: 125
Joined: Mon May 01, 2017 19:45
In-game: ratmix

[Solved] Add player name as property of added LuaEntity

by ratmix » Tue Feb 12, 2019 19:04

I am trying to modify the Ranged Weapons mod by davidthecreator - CC-BY-SA 3.0 (awesome mod BTW). I would like the shooter to get credit for the shot when another player is hit. Bullets are added as entities and then "punch" the player on impact. I have tried adding the shooter's name as static data like this:

Code: Select all
local staticdata = minetest.serialize({shooter = user:get_player_name()})
local obj = minetest.add_entity(pos, "rangedweapons:deagleshot", staticdata)

The "punch" is done within the LuaEntity's on_step function. However, I can't seem to insert the shooter as the puncher...

Code: Select all
obj:punch(self.shooter:get_player_by_name(), 1.0, {
                  full_punch_interval = 1.0,
                  damage_groups= {fleshy = damage, knockback=18},
               }, nil)

The shooter in this example returns as a nil value, so obviously I am doing something wrong. Is there a way to attach the player's name as a property of an added LuaEntity and then then use that name to specify the puncher within on_step?
Last edited by ratmix on Thu Feb 14, 2019 07:48, edited 1 time in total.
Mintest server ratmix.com:30000
Ratmix Chat
 

User avatar
ratmix
Member
 
Posts: 125
Joined: Mon May 01, 2017 19:45
In-game: ratmix

[Solved] Re: Add player name as property of added LuaEntity

by ratmix » Thu Feb 14, 2019 07:46

I was able to attach an owner name like this...
Code: Select all
local obj = minetest.add_entity(pos, "rangedweapons:deagleshot", staticdata)
   local entity = obj:get_luaentity()
   entity.owner = user:get_player_name()

And then retrieve the user/owner in the on_step function with...
Code: Select all
local owner = minetest.get_player_by_name(self.owner)


EDIT
For any who wants to make these changes, they are more thoroughly documented here.
Mintest server ratmix.com:30000
Ratmix Chat
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 1 guest