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!
Removing health off player?
-
- Member
- Posts: 214
- Joined: Thu Nov 17, 2011 06:31
- Location: California, USA
Sure, give me a minute to root it out.
EDIT: Right, this is what I have.
At the beginning of the environment.cpp near enough, I have this...
EDIT: Right, this is what I have.
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);
}
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.
-
- Member
- Posts: 214
- Joined: Thu Nov 17, 2011 06:31
- Location: California, USA
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?owen_a wrote:Code: Select all
... Sleep(2000); ...
And to get time differences you can also use dtime, which is passed to ServerEnvironment::step.
hope this helps --jn
-
- Member
- Posts: 214
- Joined: Thu Nov 17, 2011 06:31
- Location: California, USA
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...
I think it should be possible to do what you want totally in LUA as a mod. Give me a few minutes...
-
- Member
- Posts: 214
- Joined: Thu Nov 17, 2011 06:31
- Location: California, USA
Who is online
Users browsing this forum: No registered users and 8 guests