Removing health off player?

owen_a
New member
 
Posts: 8
Joined: Sat Mar 17, 2012 08:29

Removing health off player?

by owen_a » Tue Mar 20, 2012 17:18

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!
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Tue Mar 20, 2012 19:51

Can you post the whole function that code is in and what file it is in?
 

owen_a
New member
 
Posts: 8
Joined: Sat Mar 17, 2012 08:29

by owen_a » Fri Mar 23, 2012 16:50

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;
    }
}
Last edited by owen_a on Fri Mar 23, 2012 16:55, edited 1 time in total.
 

owen_a
New member
 
Posts: 8
Joined: Sat Mar 17, 2012 08:29

by owen_a » Sat Mar 24, 2012 11:31

Well... Anyone?
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sat Mar 24, 2012 18:43

Why are you setting the pointer to (0)?
 

jn
Member
 
Posts: 106
Joined: Tue Jan 03, 2012 19:15

by jn » Sun Mar 25, 2012 10:17

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
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sun Mar 25, 2012 16:16

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

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sun Mar 25, 2012 17:12

 


Return to Minetest Problems

Who is online

Users browsing this forum: No registered users and 9 guests

cron