Jump to content

Recommended Posts

1674406331_2023-04-20190244.thumb.png.cf95b8f9c200ef15a0b0e18c6cb3469d.png

I have added a level component to the player and stated that on the screen, the level can increase the attack range of the spear, but due to an error in the red circle, how to write it to represent the player himself or a specific individual creature I want to specify

'owner' doesn't exist in 'modispear' functions scope. The way you're trying to increase spears range is wrong too. 'AddPrefabPostInit' runs on entity creation so it would not dynamically change the range with the players level.

A better way of doing that would be to use 'AddPlayerPostInit' and listen to the 'onequip', 'onunequip' events and then check whether the player has a spear equipped and changing THEIR range instead of the weapon.
You can do that with 'inst.components.combat:SetRange(range)'

On 4/23/2023 at 9:50 PM, -t- said:

'owner' doesn't exist in 'modispear' functions scope. The way you're trying to increase spears range is wrong too. 'AddPrefabPostInit' runs on entity creation so it would not dynamically change the range with the players level.

A better way of doing that would be to use 'AddPlayerPostInit' and listen to the 'onequip', 'onunequip' events and then check whether the player has a spear equipped and changing THEIR range instead of the weapon.
You can do that with 'inst.components.combat:SetRange(range)'

Thank you for reminding me. Regarding the attack distance setting, I used inst: DoPeriodicTask (0.5), which constantly changes the attack distance of the spear. I forgot to write it here. However, compared to equipping the spear, I prefer to implement my code by detecting variable changes. Is there a way to pass player parameters without using any functions related to the player? For example, constantly searching for all creatures in the picture and then locking in creatures with player tags, but I don't know how to write

In this situation inst:DoPeriodicTask(0.5) won't actually change your spears range because, as I said  before you're using AddPrefabPostInit which only runs once.

I don't exactly understand what you're trying to achieve with searching for `player` creatures, but you could probably use TheSim:FindEntities() or FindEntity. There is also a table of all connected players called AllPlayers.

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...