Page 1 of 3
Medic
Posted: Sun Apr 03, 2005 3:59 pm
by MPowell1944
I am trying to create a medic mod where 1 player touches and holds the usekey on another player and heals that player. This is what I have so far, but I know that it isn't right as it looks as if the player istouching and healing himself. This idea is from the 33rdSS MEDIC! server. The medic idea works well on there. I am trying to duplicate it. This is what I have so far. I even tested the useheld with just 1 player and it didn't fullheal me. No idea why. Can you folks look at this and tell me what is wrong. I really want this script to work. medic thread simply checks player health and places healthpack on arm to signify that player needs health. medic2 thread is the one where the healing takes place.
Thanks.
Code: Select all
medic:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
if($player[local.i].health < 100)
{
$player[local.i] attachmodel models/items/item_100_healthbox.tik "Bip01 R UpperArm"
}
else
{
$player[local.i] removeattachedmodel "Bip01 R UpperArm"
}
}
wait .1
}
end
medic2:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
if($player[local.i] isTouching $player[local.i] && $player[local.i].useheld == 1)
{
$player[local.i] fullheal
}
}
wait .1
}
end
Re: Medic
Posted: Sun Apr 03, 2005 4:19 pm
by Rookie One.pl
That's the bastard:
Code: Select all
if($player[local.i] isTouching $player[local.i] && $player[local.i].useheld == 1)
Human translation of the above: if some player is touching himself and is holding use.
You need a double for loop.
Posted: Sun Apr 03, 2005 4:29 pm
by MPowell1944
I know. I am trying to define the player needing health as something other than local.i
That way I can do $player[local.i] isTouching $player[local.m]
Posted: Sun Apr 03, 2005 5:57 pm
by Rookie One.pl
Code: Select all
medic:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
if($player[local.i].health < 100)
{
if ($player[local.i].hasmodel != 1)
$player[local.i] attachmodel models/items/item_100_healthbox.tik "Bip01 R UpperArm"
}
else
{
if ($player[local.i].hasmodel == 1)
$player[local.i] removeattachedmodel "Bip01 R UpperArm"
}
}
waitframe
}
end
medic2:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
for (local.j = 1; local.j <= $player.size; local.j++)
{
if($player[local.i] isTouching $player[local.i] && $player[local.i].useheld == 1)
$player[local.j] fullheal
}
}
wait .1
}
end
Posted: Sun Apr 03, 2005 6:07 pm
by Deutsche Dogge
Wouldn't it be good to add this to medic2 to ease the workload of the 2 for loops?
Code: Select all
medic2:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
for (local.j = 1; local.j <= $player.size; local.j++)
{
if($player[local.i] isTouching $player[local.i] && $player[local.i].useheld == 1)
$player[local.j] fullheal
wait .1 <----------------------
}
wait .1 <---------------------
}
wait .1
}
end
Posted: Sun Apr 03, 2005 7:17 pm
by Rookie One.pl
Oh, if you want it so badly,

you can. But you'd be better using waitframes as 2 waits of 0.1 will cause a delay of 0.2, which is quite noticeable (in fact, even a delay of 0.1 is noticeable

).
Posted: Sun Apr 03, 2005 9:32 pm
by Grassy
Code: Select all
medic2:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
for (local.j = 1; local.j <= $player.size; local.j++)
{
if($player[local.i] isTouching $player[local.i] && $player[local.i].useheld == 1)
$player[local.j] fullheal
}
}
wait .1
}
end
Thats still not looking for a player with the healthbox, local.j needs to look for a level variable assigned to the injured player.
Grassy
Posted: Sun Apr 03, 2005 10:05 pm
by Rookie One.pl
Yeah, you're right, Grassy:
Code: Select all
medic:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
if($player[local.i].health < 100)
{
if ($player[local.i].hasmodel != 1)
{
$player[local.i].hasmodel = 1
$player[local.i] attachmodel models/items/item_100_healthbox.tik "Bip01 R UpperArm"
}
}
else
{
if ($player[local.i].hasmodel == 1)
$player[local.i] removeattachedmodel "Bip01 R UpperArm"
}
}
waitframe
}
end
medic2:
while(1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
for (local.j = 1; local.j <= $player.size; local.j++)
{
if($player[local.i] isTouching $player[local.j] && $player[local.i].useheld == 1 && $player[local.j].hasmodel == 1)
$player[local.j] fullheal
}
}
waitframe
}
end
Posted: Mon Apr 04, 2005 4:17 am
by MPowell1944
Wouldnt it be local.j isTouching local.i since the player [local.j] has to be touching the person needing health [local.i] ?
I can't test this by myself. Can someone test this to see if it works.
Posted: Mon Apr 04, 2005 4:51 am
by MPowell1944
I tested your script and i was able to heal myself.
Posted: Mon Apr 04, 2005 7:03 am
by bdbodger
Well I would wait until the players health is a bit lower than just below 100% . There are other ways to do it too like vector_length or vector_within instead of istouching
health_thread:
while(1)
{
for(local.i=1;local.i<=$player.size;local.i++)
{
if($player[local.i].health < 70 && $player[local.i].hasmodel != 1)
$player[local.i] thread waitheal
}
waitframe
}
end
//----------------------------------------------
waitheal:
self.hasmodel = 1
self attachmodel models/items/item_100_healthbox.tik "Bip01 R UpperArm"
while(self.health < 70)
{
for(local.i=1;local.i<=$player.size;local.i++)
{
if($player[local.i] == self)
continue
if(vector_within $player[local.i].origin self.origin 100 && $player[local.i].useheld == 1)
{
self fullheal
break
}
}
waitframe
}
self.hasmodel = 0
self removeattachedmodel "Bip01 R UpperArm"
end
Posted: Tue Apr 05, 2005 1:27 am
by MPowell1944
Ok that works good BD thankyou. However. 2 problems. Because there is no dmteam check on the 2 players, spectators and other teams can heal players.
That and when a player dies, his dead body can be healed b/c it isnt checking for while isAlive. Can those 2 things be fixed in that script.
Posted: Tue Apr 05, 2005 7:56 am
by Grassy
Ok I think this might do what you want.
Hmmm no it needs more dmteam checking.. Ok that looks better (I think

)
Grassy
Code: Select all
health_thread:
while(1)
{
for(local.i=1;local.i<=$player.size;local.i++)
{
if($player[local.i].health < 70 && $player[local.i].hasmodel != 1)
$player[local.i] thread waitheal
}
waitframe
}
end
waitheal:
self.hasmodel = 1
self attachmodel models/items/item_100_healthbox.tik "Bip01 R UpperArm"
while(self.health < 70 )
{
for(local.i=1;local.i<=$player.size;local.i++)
{
if($player[local.i] == self && isAlive self)
continue
if(vector_within $player[local.i].origin self.origin 100 && $player[local.i].useheld == 1 && $player[local.i].dmteam == self.dmteam)
{
self fullheal
break
}
}
waitframe
}
self.hasmodel = 0
self removeattachedmodel "Bip01 R UpperArm"
end
Posted: Tue Apr 05, 2005 10:38 am
by bdbodger
if($player[local.i] == self && isAlive self)
continue
well not quite right if both are not true then it keeps reading the thread instead of skiping to the next loop in the for loop better to split it so that it breaks out of the while loop and ends the thread
if($player[local.i] == self )
continue
if !(isalive self )
break
at least I think it breaks out of the while loop and not just out of the for loop if it doesn't break out of the while loop maybe add to it like this
while(self.health < 70 && isalive self)
Posted: Tue Apr 05, 2005 11:09 am
by MPowell1944
Yeah, it didn't. lol. Lemme try the double if statement.
edit
Yeah, that did the trick.