Jump to content

Retrieving stategraph info as a client


Recommended Posts

I'm working on a client-only mod that requires it to know when the player is changing states, but it's giving me some trouble for the client version.

Ideally I would have liked to just listened for the "newstate" event, but that would only work for host. So I was just going to be lazy and check every tick for inst.sg:InNewState(), but it seems I can't even do that, as inst.sg always comes back as nil. And there aren't any replica versions of sg to pull from.

Are there any ways around this? Or am I just missing something simple?

Link to comment
Share on other sites

I see a few things in combat_replica.lua that hint that it might be possible, but it seems somewhat contradictory.

in the CanAttack() function, 

if self.inst.components.combat ~= nil then
        return self.inst.components.combat:CanAttack(target)
    elseif self.classified ~= nil then
        if not self:IsValidTarget(target) then
            return false, true
        elseif not self.classified.canattack:value()
            or (self._laststartattacktime ~= nil and
                GetTime() - self._laststartattacktime < self.classified.minattackperiod:value())
            or (self.inst.sg ~= nil and
                self.inst.sg:HasStateTag("busy") or
                self.inst:HasTag("busy"))
            then
            -- V2C: client can't check "hit" state tag, but players don't need that anyway
            return false
        end
	--...
	--AND THEN A WHOLE BUNCH MORE UNRELATED STUFF AFTER THAT-

There is a single check for (self.inst.sg:HasStateTagBusy) 

The "if self.inst.components.combat ~= nil then / else" makes me believe that this is being run for clients, but there is a note right below it saying "client can't check "hit" state tag, but players don't need that anyway" Which really throws me off, because why would they be able to check for a busy tag if they can't check for a hit tag? Unless thats what the "sg ~= nil" check is for. It seems like it's just all over the place, and I can't tell if they're able to make the check or not.

The dev note seems to suggest that referencing your own stategraph as a client just isn't possible, if they aren't able to get tags. I hope that's not the case. If it is, I guess the second best option for me is to reference the clients AnimState so I can check animation names instead of state names. and make a table sorting through every animation in the game... oh boy

Link to comment
Share on other sites

From my recollection of the stategraphs and replicas the client state graph self applies a busy tag on many states but doesn't do the same for being hit.

The check for the component existing is for the case of a client being the same as the host (hosting a room without caverns enabled).

 

If you're just wanting to tell the client that their server-side state graph changed then perhaps you might find a net variable to be useful that either contains the string of the current state, or an index thereof to shorten the network payload.

Link to comment
Share on other sites

1 hour ago, CarlZalph said:

From my recollection of the stategraphs and replicas the client state graph self applies a busy tag on many states but doesn't do the same for being hit.

The check for the component existing is for the case of a client being the same as the host (hosting a room without caverns enabled).

 

If you're just wanting to tell the client that their server-side state graph changed then perhaps you might find a net variable to be useful that either contains the string of the current state, or an index thereof to shorten the network payload.

Huh, I didn't know that about replica stategraphs.

But how would that work with a client-only mod? I thought net variables were for hosts to deliver data to clients, but if this is client-only, then joining an un-modded server would result in that host not having the net variables to send, right? I use netvars from time to time but my understanding of them is very minimal, especially since this is my first client-only mod

Link to comment
Share on other sites

55 minutes ago, pickleplayer said:

Huh, I didn't know that about replica stategraphs.

But how would that work with a client-only mod? I thought net variables were for hosts to deliver data to clients, but if this is client-only, then joining an un-modded server would result in that host not having the net variables to send, right? I use netvars from time to time but my understanding of them is very minimal, especially since this is my first client-only mod

Yeah, net variables are used to pass information to the client and RPCs are for the client to pass information to the server.

Since this is all on the client only, then you'll be missing out on server-only state changes.

I believe the replica stategraph is used only when the server-client is the same.

 

I don't believe clients ever get information about the stategraph in a full client-server setup.

I know I tried looking for a way to hook animation changes but it was a bit hairy.

I'll look back into this some time later.

Link to comment
Share on other sites

On 1/19/2018 at 7:03 PM, CarlZalph said:

Yeah, net variables are used to pass information to the client and RPCs are for the client to pass information to the server.

Since this is all on the client only, then you'll be missing out on server-only state changes.

I believe the replica stategraph is used only when the server-client is the same.

 

I don't believe clients ever get information about the stategraph in a full client-server setup.

I know I tried looking for a way to hook animation changes but it was a bit hairy.

I'll look back into this some time later.

 

Ah, that's unfortunate. I think this problem may be a little out of my league, but thank you very much for the information. I would be interested to hear if you ever do find a solution, but as for now, listening for anim changes seems to have solved my problem. It's just... a very stupid way to do it.

Well, I guess my original plan wasn't much better. But at least that one didn't need to run every frame. 

Link to comment
Share on other sites

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
 Share

×
  • Create New...