problem with actor coordinates and radiation

luppolo
Scavenger
Posts: 37
Joined: 04 Nov 2016, 21:58

problem with actor coordinates and radiation

Postby luppolo » 26 May 2017, 19:19

i want to raise the radiation sickness when the player hasn't moved, this is the code i'm using

Code: Select all

function on_game_start()
   RegisterScriptCallback("actor_on_update",actor_on_update)
end

local oldT
local oldX
local oldZ

function actor_on_update()
   local t = time_global()
   
   local p    = db.actor:position()

   if not (oldT) then
      oldT = 0
   end
   
   if not (oldX) then
      oldX = p.x
      oldZ = p.z
      return
   end

   if (t < oldT) then
      return
   end
   
   printf("update %s %s", oldX, oldZ)
   
   if(p.x == oldX) then
      printf("X unchanged")
      if(p.z == oldZ) then
         printf("Z unchanged")
         db.actor.radiation = db.actor.radiation + 0.000001
         printf("radiation %s",db.actor.radiation)
      end
   end
   
   oldT = t + 500
   oldX = p.x
   oldZ = p.z
end


it works but has two odd problems as you can see from the console log

Code: Select all

update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.0040950002148747
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.0081910006701946
update 115.58994293213 65.61003112793
update 115.58995056152 65.61003112793
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.016383001580834
update 115.58994293213 65.61003112793
update 115.58995056152 65.61003112793
update 115.58994293213 65.61003112793
update 115.58995056152 65.61003112793
X unchanged
Z unchanged
radiation 0.032767005264759
update 115.58995056152 65.61003112793
update 115.58994293213 65.61003112793
X unchanged
update 115.58994293213 65.610038757324
X unchanged
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.065535008907318
update 115.58994293213 65.61003112793
update 115.58995056152 65.61003112793
X unchanged
Z unchanged
radiation 0.13107101619244
update 115.58995056152 65.61003112793
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.26214301586151
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 0.52428704500198
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
update 115.58995056152 65.61003112793
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1
update 115.58994293213 65.61003112793
X unchanged
Z unchanged
radiation 1

  • despite standing still without movement either by keyboard/mouse or being pushed around by npc/physics objects, on some ticks db.actor:position() returns different values from the previous ones, this happens regardless of the maps/spots i tried
  • db.actor.radiation = db.actor.radiation + 0.000001 somehow doubles the value
why does this happen?

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1371
Joined: 26 May 2012, 22:26

Re: problem with actor coordinates and radiation

Postby Alundaio » 26 May 2017, 20:02

Probably just physics, like gravity, so floating point of Y axis won't be entirely identical. You might want to add some kind of epsilon when comparing old position to new position.
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

luppolo
Scavenger
Posts: 37
Joined: 04 Nov 2016, 21:58

Re: problem with actor coordinates and radiation

Postby luppolo » 26 May 2017, 20:51

ok, but what about the radiation thing?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests