Medic

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Medic

Post 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
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Re: Medic

Post 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.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post 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]
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
Deutsche Dogge
First Lieutenant
Posts: 183
Joined: Wed May 07, 2003 11:50 pm
Location: Quebec
Contact:

Post 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
Image
Click sig to visit the alternation modding community
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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 :P).
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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
An ambiguous question will get a similar answer...
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post 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
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post 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.
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post by MPowell1944 »

I tested your script and i was able to heal myself.
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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
Image
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post 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.
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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 
An ambiguous question will get a similar answer...
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post 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)
Image
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post by MPowell1944 »

Yeah, it didn't. lol. Lemme try the double if statement.

edit

Yeah, that did the trick.
Post Reply