Jump to content

Possible to mod entityscript.lua function?


Recommended Posts

29 minutes ago, Serpens said:

When do I have to add this Pristine? Is this only necessary if my code is running at client AND server?

Only in prefabs, right before the TheWorld.ismastersim check.

It tells the game "up to here, stuff is the same in both server and client". But nobody knows exactly what it does, since it's on the C side.

So as long as you aren't making a new prefab, don't use it.

Using it repeatedly on an entity may cause unexpected behaviour.

31 minutes ago, Serpens said:

I can see if it runs on both, if I just add print statements all over my code and compare the logfile from server and from client. And if something is in both, I should consider using Pristine, right?

Use it like all prefab files use it. Don't use it anywhere else.

When in doubt, don't.

32 minutes ago, Serpens said:

Or is there a better way to force clients to show an HUD icon, wehn code is running only on the server (I have the inst:HasTag("player") , but HUD is nil on server side of course) ?

Remember the net variable example I gave you?

You can trigger dirty events on clients and they can react to them. In this case, the reaction is "show the icon".

Link to comment
Share on other sites

1 hour ago, DarkXero said:

Remember the net variable example I gave you?

You can trigger dirty events on clients and they can react to them. In this case, the reaction is "show the icon".

Thank you very much :)

Ah yes it works ! First I thought it would be only for using a variable only, but it is the whole dirtyevent that is called at clientside, great :)

Link to comment
Share on other sites

Pristine is required for deterministic code that does not require syncing, without it all the code will run on server and constantly sync position and other data that can be done on client with the same result

Edited by IvanX
Link to comment
Share on other sites

The server log of my dedicated server often shows the following error message:
Error decoding lua RPC sender
(I think it could be a little more precise :D )

The only RPC thing I have in my home base mod is:

AddModRPCHandler(GLOBAL.KnownModIndex:GetModActualName("Home Base Bonus"), "HomeBaseMod_handler", function(player, inst)
	if player and inst and mytype(inst) == "table" then
		UpdateNewWetTag(inst)
	end
end)

local function EntityScriptPostConstruct(self) 
    local _GetIsWet = self.GetIsWet 
    self.GetIsWet = function(inst,...) 
        
        if GLOBAL.TheWorld.state.wetness==0 or GLOBAL.TheWorld.state.wetness==nil then -- if no wetness, nothing can be wet. works at server and client
            return _GetIsWet(inst,...)
        end
        local replica = inst.replica.inventoryitem or inst.replica.moisture -- items and character have their own thing
        if replica ~= nil or inst==nil then --  replica and hastag do work at server and at client.    inst:IsInLimbo() --V2C: faster than checking tag, but only valid on mastersim
            return _GetIsWet(inst,...)
        end
        if inst:HasTag("wet") then return inst:HasTag("wet") end -- things that are always wet
        
        local RPC = GetModRPC(GLOBAL.KnownModIndex:GetModActualName("Home Base Bonus"), "HomeBaseMod_handler") -- makes the server call UpdateNewWetTag to get the newest wet status of this object
		SendModRPCToServer(RPC, inst)
        
        return inst:HasTag("IsNewWet")
    end
end

AddGlobalClassPostConstruct("entityscript","EntityScript", EntityScriptPostConstruct)

I don't know where there could be an error.

 

edit:

the error occures when the GetIsWet function is called, so this code has to be the problem...
I also replaced "mytype" with "type" and replaced GLOBAL.KnownModIndex:GetModActualName("Home Base Bonus") with a normal string, but still the error...

edit2:
I think because of this bug, all evergreens are shown as not wet, because the UpdateNewWetTag is not called for them...
I'm quite sure this worked some days ago.. don't know why it does not now...
@DarkXerodo you know what the problem could be?
 

Edited by Serpens
Link to comment
Share on other sites

@DarkXeroCould it be a problem with the namespace? After testing around with various copies of my mod, I now get the error:
[00:04:34]: Invalid RPC namespace:     workshop-738448215    1   
Changing the unique_name in the script to a one I never used before brings me back to the Error decoding lua RPC sender error...

Link to comment
Share on other sites

3 hours ago, Serpens said:

mytype(inst) == "table"

The lua function is "type". It returns the type of the value you give it. I don't know what "mytype" is.

2 hours ago, Serpens said:

Could it be a problem with the namespace?

That's if you use that function GetModActualName. Just use "HomeBaseBonusMod", that will be unique enough.

Link to comment
Share on other sites

I found out the issue.
It is this:
 

AddModRPCHandler(GLOBAL.KnownModIndex:GetModActualName("Home Base Bonus"), "HomeBaseMod_handler", function(player, inst)
	if player and inst and type(inst) == "table" then
		UpdateNewWetTag(inst)
	end
end)

If I remove the "UpdateNewWetTag(inst)", then I get no decoding error.
And when I don't remove it, but change the UpdateGetNewWetTag function to just do nothing and return, the error is still gone.

Edited by Serpens
Link to comment
Share on other sites

Solved the "error decoding" issue... The problem was:
To find out, if the object is "NewWet", I had to find out the externalheat. But in the externalheat function I called inst.GetIsWet(), which produced a loop, that throwed the error message...

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