Jump to content

Need help script please


Xilandro

Recommended Posts

I've spent whole night to figure out everything by myself, but nothing, so I'm seriously stuck. So i'm sorry, but i really need some help =(

 

script is attached to DummyItem

And when the dummyItem is added to someone's inventory - script is started and "Job is Done" hud element appears on screen and fade away after few seconds.

The problem is... it don't fade.

I've tried almost everything i know, tried also different blocktypes (OnAdd, Gamemode, OnAdd+Gamemode) all three script types and nothing helps.

Template script:

scn aaNamePlaceholder


float Timer
int iAlpha
ref rContainer


Begin Gamemode


set rContainer to GetContainer


if rContainer != Player


        SetUIFloat "HUDMainMenu\confirm\alpha" 255
        SetUIFloat "HUDMainMenu\confirm\visible" 1
        set Timer to 4
endif
    if Timer > 0
        if Timer < 3
            set iAlpha to Timer * 85


            SetUIFloat "HUDMainMenu\confirm\alpha" iAlpha
        endif
        set Timer to Timer + GetSecondsPassed
    elseif Timer
        set Timer to 0
        SetUIFloat "HUDMainMenu\confirm\visible" 0
    endif
end

I will appreciate any kind of help, from simple advice and pointing on my mistakes to fully working scripts.

And once again sorry.

Link to comment
Share on other sites

I see a few issues...

 

Your setup runs each time, that is a nono.

 

The first time your script runs, Timer will be 4. So Timer > 0 is true and Timer <3 is false. Therefore the only but of code that will run is Set Timer to Timer + GetSecondsPassed which will make Timer more than 4. Now repeat and the same thing happens. Timer just gets bigger and bigger and nothing else happens.

 

I think you want Timer to be Timer minus GetSecondsPassed.

 

Also, elseif Timer will never execute because Timer is a float and that if statement can only be true if Timer is zero - which it will never be (it might be 0.00000123 or -0.00000123, but not actually 0.0). Just remove the Timer part and that bit of code (just else, not elseif Timer)will run as soon as Timer is negative, or after 4 seconds.

scn aaNamePlaceholder


float Timer
int iAlpha
Short DoOnce
ref rContainer

Begin Gamemode

If DoOnce == 0
  set rContainer to GetContainer
  if rContainer != Player
        SetUIFloat "HUDMainMenu\confirm\alpha" 255
        SetUIFloat "HUDMainMenu\confirm\visible" 1
        set Timer to 4
        Set DoOnce to 1
  endif
endif

    if Timer > 0
        if Timer < 3
            set iAlpha to Timer * 85
            SetUIFloat "HUDMainMenu\confirm\alpha" iAlpha
        endif
        set Timer to Timer - GetSecondsPassed
    else
        set Timer to 0
        SetUIFloat "HUDMainMenu\confirm\visible" 0
    endif
end
Edited by pkleiss
Link to comment
Share on other sites

Thank you very very much good sir, now everything works as it should!

 

 

 


I think you want Timer to be Timer minus GetSecondsPassed.

 

Well, it didn't work last time. Now i understand why.

 

maybe because of this:

 

elseif Timer will never execute because Timer is a float and that if statement can only be true if Timer is zero - which it will never be

 

 

Your setup runs each time, that is a nono.

Okay =)

Link to comment
Share on other sites

 

 

Also, elseif Timer will never execute because Timer is a float and that if statement can only be true if Timer is zero - which it will never be (it might be 0.00000123 or -0.00000123, but not actually 0.0). Just remove the Timer part and that bit of code (just else, not elseif Timer)will run as soon as Timer is negative, or after 4 seconds.

Actually, a float can be an absolute zero. I suggest leaving the elseif Timer, otherwise the nested statements will execute on every iteration.

Link to comment
Share on other sites

 

Actually, a float can be an absolute zero. I suggest leaving the elseif Timer, otherwise the nested statements will execute on every iteration.

I will try it as well.

Link to comment
Share on other sites

 

Actually, a float can be an absolute zero. I suggest leaving the elseif Timer, otherwise the nested statements will execute on every iteration.

Sorry, but you are wrong on both counts...

 

In practice, the likelihood of a float being 0.0 is practically zero. If you don't believe me, test it yourself by dumping a predefined float decremented by GetSedcondsPassed (like Timer) to a console file (use the scof command). You will see that Timer will never ever be 0.0 except upon initialization.

 

Also, the nested statement won't keep repeating as the final test looks for Timer being negative and then sets it back to zero. A value of zero will not trigger the first test which evaluates true only if Timer is positive, not zero.

 

The only thing suspect about that script is the use of rContainer, which may be unnecessary. I can't imagine that it will ever evaluate as true unless the OP placed the script on the player himself - which I doubt.

Link to comment
Share on other sites

Well, i can't tweak fade time correctly if timer is not in seconds but in milliseconds. So i need to say "good bye cool idea with fade time"

So now script looks like this. And it works for me. I hope everything is correct.

float Timer
int iAlpha
Short DoOnce
ref rContainer

Begin Gamemode

If DoOnce == 0
  set rContainer to GetContainer
  if rContainer != Player

        SetUIFloat "HUDMainMenu\Indicator\visible" 1
        set Timer to 0.1
        Set DoOnce to 1
  endif
endif

    if Timer > 0
        set Timer to Timer - GetSecondsPassed
    else
        set Timer to 0
        SetUIFloat "HUDMainMenu\Indicator\visible" 0
    removeme
    endif

end

and seems like "else" is better in this case. With "elseif timer" i have some delays, and if my fps is below 25 - script don't work correctly at all - "confirm" appears with even bigger delays (once per second and so on)

Edited by Xilandro
Link to comment
Share on other sites

 

 

Actually, a float can be an absolute zero. I suggest leaving the elseif Timer, otherwise the nested statements will execute on every iteration.

Sorry, but you are wrong on both counts...

 

In practice, the likelihood of a float being 0.0 is practically zero. If you don't believe me, test it yourself by dumping a predefined float decremented by GetSedcondsPassed (like Timer) to a console file (use the scof command). You will see that Timer will never ever be 0.0 except upon initialization.

 

Also, the nested statement won't keep repeating as the final test looks for Timer being negative and then sets it back to zero. A value of zero will not trigger the first test which evaluates true only if Timer is positive, not zero.

 

A float can be equal to absolute zero when it wasn't set to any value, or when it set to zero.

 

Look at the relevant parts of that segment again:

if Timer > 0
	set Timer to Timer - GetSecondsPassed
else
	set Timer to 0
endif

The else part will continue to execute on every iteration, since it is true while Timer <= 0.

elseif Timer should be used instead, since, in this case, it will only be true for a single frame, when Timer < 0.

 

 

 

 

Well, i can't tweak fade time correctly if timer is not in seconds but in milliseconds. So i need to say "good bye cool idea with fade time"

When you set Timer to 4, it means 4 seconds, not 4 milliseconds. It should work. If it doesn't, it's probably not because of the timer.

Link to comment
Share on other sites

When you set Timer to 4, it means 4 seconds, not 4 milliseconds. It should work. If it doesn't, it's probably not because of the timer.

 

 

Oh god.. sorry, not milliseconds. Decisecond. i set the timer to 1 decisecond (set Timer to 0.1) and tried to set fade, and failed.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...