Jump to content

Help in writing code - Miscellaneous issues


Nebula

Recommended Posts

I figured out the objects and recipes, but writing code to implement it was too complicated for me. Help me write code for mod.

 

I need to ensure that the equipped item on the character gives a permanent little effect of reducing stress, or a slight increase in mood. Is there anyone who can help me do this?

Edited by Nebula
Link to comment
Share on other sites

9 hours ago, Nebula said:

I figured out the objects and recipes, but writing code to implement it was too complicated for me. Help me write code for mod.

 

I need to ensure that the equipped item on the character gives a permanent little effect of reducing stress, or a slight increase in mood. Is there anyone who can help me do this?

Yeah, this should be pretty easy.

 

Playing a game right now, though, so I can probably post an example in the morning.

Link to comment
Share on other sites

Sorry took so long! Here's what I got, I haven't tried it and it's been a minute since I've messed with PZ coding so I might be off a bit:

 

local function conEff()
	local player = getPlayer();
	local hItem = player:getClothingItem_Head();
	
	if hItem then
	local nItem = hItem:getName();
		if nItem == "Item name 1" then
			player:getStats():setStress(0);
		elseif nItem == "Item name 2" then
			player:getBodyDamage():setUnhappynessLevel(0);
		end
	end
end

Events.OnPlayerUpdate.Add(conEff);

With this code I'm assuming you have something equippable to the head? or is it something carried?

 

Let me know if it doesn't work.

Link to comment
Share on other sites

  • 4 weeks later...

But still.
Is it possible for community members to help with the code?


I need to equip the item from the inventory on the head of the character, provided that the item  is not clothing.
The item must give a constant effect of improved mood, or reduced stress.


Sample code written tommysticks does not work. :(
Help me please!

Edited by Nebula
Link to comment
Share on other sites

You'd have to fake the head slot and possibly trick the game into marking the item as equipped in the inventory panel. 

 

Much easier would be doing something that the player holds, such as a Spiffo plush:

 

 

--half-assed, bastardized Lua-pseudocode hybrid

blarg = {}

 

local function blarg.OnPlayerUpdate()

 

if getPlayer():getPrimaryHand() == "ItemName" then

-- do my effect

end

 

end 

 

Events.OnPlayerUpdate.add(blarg.OnPlayerUpdate()

 

@Connall might be able to look at getting the head slot to work, though. Most of the in-game functions for it are just a dead end, but they're there.

 

Link to comment
Share on other sites

Thank you, but that's not what I need.
Similar to what I need - implemented by Nolan Armor Mod. But in a lot of code I could not figure out how he does it.

Can someone on the basis of his code do what I need. I turned to Nolan directly, but he did not answer me.

Link to comment
Share on other sites

  • 3 weeks later...

I want to see by clicking. To see for myself ... to understand ... keys meaning "UnhappynessLevel"

 

 if keynum == 88 then Ulvl = player:getBodyDamage():getUnhappynessLevel() and player:Say(Ulvl);
end

 

but I get this error: attempted index: getBodyDamage of non-table: null

 

what does this mean and what am I doing wrong? Show it as it should.

 

And another question:
local - only acts within the function being performed, or within the condition?

And yes ... I could change Nolan's code myself. I begin to understand superficially what and how. But I still need your help ...

 

Excuse me, I am already a grandfather and this is given to me with great difficulty. But I'm trying.

Edited by Nebula
Link to comment
Share on other sites

36 minutes ago, Nebula said:

but I get this error: attempted index: getBodyDamage of non-table: null

it means the player variable is set to nil, not a IsoPlayer object, some line of code above your example is failing to set the variable.

 

37 minutes ago, Nebula said:

local - only acts within the function being performed, or within the condition?

Within the scope (or condition in this case)

function test()
  if true then
    local x = "OK"
  end
  print(tostring(x))
end

x() -- prints 'nil'

local is bound within any 'if' statement, as well as for/while/repeat loops, and 'do' blocks

 

Link to comment
Share on other sites

Thank you! Everything worked out!

Another question...
How to reduce the received value in a variable up to 3 characters after the point?...
or up to one character after the point ... or generally get the value of an integer without signs after the dot ...

 

And further...
How to get the value of the lunar phase, or the numbers of the lunar day, if such exists at all ...

 

erPInWm.jpg

 

Thanks to everyone who helps!
I sincerely thank you!

Edited by Nebula
Link to comment
Share on other sites

10 minutes ago, Nebula said:

How to reduce the received value in a variable up to 3 characters after the point?

oddly enough, lua doesn't have a simple rounding function. There might be a basic one available through PZ's java API but I'm unsure on that one. At any rate you can use:

local x = 0.12345678
x = tonumber(string.format("%.3f", x))
print(x) -- prints 0.123

 

Link to comment
Share on other sites

Ok. but how to get a whole (without a point) number?

3f - Mean how many characters after the dot?

 

How to get the value of the lunar phase, or the numbers of the lunar day? if such exists at all ...

 

Edited by Nebula
Link to comment
Share on other sites

  • 3 weeks later...

Fenris_Wolf -  Please help!

 

Again I have a problem ...

 

You need to read the value from the "Effect" field

The field is here

 

    WorkingAmulets = "ATTalismanCross";
    GlobalAmulets[WorkingAmulets] = {};
        GlobalAmulets[WorkingAmulets]["Location"] = getText("IGUI_Neck");
         GlobalAmulets[WorkingAmulets]["Effect"] = "Unhappy";

 

 

Here I am trying to read it ... but again it returns value - nothing (nil)

 

Preflight lines are in bold red

 

 function ATEffectAmulets(item, player,effect)
 if (NeckEquip == "true") then

if (GlobalAmulets[item:getType()]["Effect"] ~= nil) then end
elseif (GlobalAmulets[item:getType()]["Effect"] == "Unhappy") then UnhappyAmulets(item, player);

end    
end

 

What am I doing wrong?

 

 

Link to comment
Share on other sites

17 minutes ago, Nebula said:

WorkingAmulets = "ATTalismanCross";
    GlobalAmulets[WorkingAmulets] = {};
        GlobalAmulets[WorkingAmulets]["Location"] = getText("IGUI_Neck");
         GlobalAmulets[WorkingAmulets]["Effect"] = "Unhappy";

this part looks fine

 

Your text highlighted in red looks to be the problem

18 minutes ago, Nebula said:

function ATEffectAmulets(item, player,effect)
 if (NeckEquip == "true") then

if (GlobalAmulets[item:getType()]["Effect"] ~= nil) then end
elseif (GlobalAmulets[item:getType()]["Effect"] == "Unhappy") then UnhappyAmulets(item, player);

end    
end

I'm assuming the 2 red lines are meant to part of the same 'if statement'?  In which case you need to remove the 'end' from the first red line

function ATEffectAmulets(item, player,effect)
   if (NeckEquip == "true") then
      if (GlobalAmulets[item:getType()]["Effect"] ~= nil) then 
      elseif (GlobalAmulets[item:getType()]["Effect"] == "Unhappy") then 
         UnhappyAmulets(item, player);
      end
   end
end

 

Link to comment
Share on other sites

Stiff! I've been fighting this mistake for 5 evenings. I tried everything that I can ... The problem is as always on the surface.
I thank you cordially!

 

I'm going to sleep ... in Russia 12 nights already, in the morning to work ...

Edited by Nebula
Link to comment
Share on other sites

Before going to bed I decided to check the corrected code in the game.
Sadness, trouble ... the problem has remained.

Gives
:

function: ATEffectAmulets -- file: amulets.lua line # 146
java.lang.RuntimeException: attempted index: Effect of non-table: null

 

If comment line 146
then it starts issuing the same error on line 147

 

146      if (GlobalAmulets[item:getType()]["Effect"] ~= nil) then
147     if (GlobalAmulets[item:getType()]["Effect"] == "Unhappy") then

 

Maybe I'm somehow wrong trying to read the value from the field?

Link to comment
Share on other sites

But he's recorded right here?

 

WorkingAmulets = "ATTalismanCross";
    GlobalAmulets[WorkingAmulets] = {};
        GlobalAmulets[WorkingAmulets]["Location"] = getText("IGUI_Neck");
         GlobalAmulets[WorkingAmulets]["Effect"] = "Unhappy";

Link to comment
Share on other sites

its not the green line, it would be this one

GlobalAmulets[WorkingAmulets] = {};

 

I'd suggest changing the function a bit:

 

function ATEffectAmulets(item, player,effect)
   if (NeckEquip == "true") then
      local atable =  GlobalAmulets[item:getType()]
      if not atable then
          print("ERROR (not in table): item type " .. item:getType())
          print("table contains:")
          for key, value in pairs(GlobalAmulets) do print(key) end
      elseif (atable.Effect == "Unhappy") then 
         UnhappyAmulets(item, player);
      end
   end
end

then check the console messages, you'll beable to see the item type, and exactly whats in the table

 

Its hard to really say whats going on though without actually seeing the whole code

Link to comment
Share on other sites

I think I'm beginning to understand ... in part :)
Can you provide your code with comments? It will help me very well!

 

That's what I do not understand at all.

local atable =  GlobalAmulets[item:getType()]
      if not atable then
for key, value in pairs(GlobalAmulets) do print(key) end
      elseif (atable.Effect == "Unhappy") then 


Thank you again, you are one of the few who help beginners! :)
Now I'm definitely sleep ... tomorrow I'll come.

Edited by Nebula
Link to comment
Share on other sites

  • 1 month later...

Solved the problem by going from the other side, reading the name of the equipment item and prescribing the conditions specifically for him with the help of -

player:getInventory():getItemFromType(player:getModData().NeckAmulets):getDisplayName();

 

But it's inconvenient ... I had to create a bunch of additional code.
Also I understood why the method of reading table elements does not work.
elements of the table need to read by looping through them.
But my knowledge is still not enough for this implementation.

 

At the moment, there is the following question.
How to make the text in the Tooltip.txt be added to the value from the LUA variable?

Edited by Nebula
Link to comment
Share on other sites

How in LUA to intercept the event - when the character wakes up?

It is the moment of waking up (on an alarm clock) and separately when he wakes up, in a panic and himself.

Edited by Nebula
Link to comment
Share on other sites

  • 1 month later...

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