Page 1 of 1

Removing health off player?

PostPosted: Tue Mar 20, 2012 17:18
by owen_a
Hello,

I'm creating something which counts down from 15 seconds if a player is underwater, and then once that time is over, it deducts -1 off there health until they come back up to surface or die. The only problem I'm facing is getting it to link from one file to the environment file. For example...

I have.... ServerRemotePlayer *srp = (0); srp->setHP(srp->getHP() - 1);

But this throws out an error when linking with .player.obj'.

Any ideas?

Thanks!

PostPosted: Tue Mar 20, 2012 19:51
by randomproof
Can you post the whole function that code is in and what file it is in?

PostPosted: Fri Mar 23, 2012 16:50
by owen_a
Sure, give me a minute to root it out.

EDIT: Right, this is what I have.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
// Water resistance
                if(lplayer->in_water_stable || lplayer->in_water)
                {
                    f32 max_down = 2.0*BS;
                    if(speed.Y < -max_down) speed.Y = -max_down;

                    f32 max = 2.5*BS;
                    if(speed.getLength() > max)
                    {
                        speed = speed / speed.getLength() * max;
                    }

                    // Start timer for 15 seconds until drowning
                    StartUnderwaterTimer();
                }

                lplayer->setSpeed(speed);
            }


At the beginning of the environment.cpp near enough, I have this...

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
void StartUnderwaterTimer ()
{
    unsigned int x_minutes=0;
    unsigned int x_seconds=0;
    unsigned int x_milliseconds=0;
    unsigned int totaltime=0,count_down_time_in_secs=0,time_left=0;

    clock_t x_startTime,x_countTime;
    count_down_time_in_secs=15;  // 15 is 15 seconds, 1 minute is 60, 1 hour is 3600

    // Start The Clock
    x_startTime=clock();

    // update timer
    time_left=count_down_time_in_secs-x_seconds;

    while (time_left>0)
    {
        x_countTime=clock(); // update timer difference
        x_milliseconds=x_countTime-x_startTime;
        x_seconds=(x_milliseconds/(CLOCKS_PER_SEC))-(x_minutes*60);
 
        time_left=count_down_time_in_secs-x_seconds; // subtract to get difference
    }

    if (time_left == 0)
    {
begin:
        ServerRemotePlayer *srp = (0); srp->setHP(srp->getHP() - 1);
        Sleep(2000);
        goto begin;
    }
}

PostPosted: Sat Mar 24, 2012 11:31
by owen_a
Well... Anyone?

PostPosted: Sat Mar 24, 2012 18:43
by randomproof
Why are you setting the pointer to (0)?

PostPosted: Sun Mar 25, 2012 10:17
by jn
owen_a wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
...
        Sleep(2000);
...

First off, you should use sleep_ms from porting, Sleep is Windows-specific, AFAIK. And second, do you really want to block the server thread for two full seconds?
And to get time differences you can also use dtime, which is passed to ServerEnvironment::step.

hope this helps --jn

PostPosted: Sun Mar 25, 2012 16:16
by randomproof
I think you have completely taken the wrong strategy here. All of your code should be run from the ServerEnvironment::step function like jn said and you should not be calling sleep at all (it will cause the whole server to stop for those 2 seconds).

I think it should be possible to do what you want totally in LUA as a mod. Give me a few minutes...

PostPosted: Sun Mar 25, 2012 17:12
by randomproof