(Hopefully) Simply script help...

Mapping support for the Source engine.
User avatar
Posts: 324

(Hopefully) Simply script help...

Post by insane3004 » 31 Jul 2016, 05:46

Real quick... Thank you to those that were patient with me when dealing with the script for the hud about a month or so back...
Unfortunately the script would cause custom finales to break and eventually I scrapped the finale for something else... Though the script will be useful for later...


So... I am hoping this won't take long or take the combined effort of five or so people to get to work...
I simply need a script that checks who is currently alive and dead, and launches a specific relay based on that info...

I am guessing the best way to handle this is to have each survivor assigned to a number (1,4,9,16)... Those that are alive are added to a variable, and a switch function with each possibility of combinations with a relay specifically for that configuration of alive players... And several functions for certain areas...
So basically my way of having survivor dialogue that accounts for living members...

The problem... I don't know how to check for living players... I am hoping that is all I need, I should hopefully be able to piece the rest together...
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 628

Re: (Hopefully) Simply script help...

Post by Roflmahwafflz » 31 Jul 2016, 06:23

I believe VSLIB has functions that allow you to check for players being alive or dead, I have never scripted for source engine games before so I dont quite know how to set it up or any of the caveats. But heres a pretty cool page to check out:
http://l4d2scripters.github.io/vslib/do ... layer.html

I believe you can download an older version of VSLIB that still works with the non-beta l4d2 (i.e the current release) because if I remember correctly the latest version of vslib relies upon beta L4D2. AFAIK youd just pack VSLIB in your VPK when you release it.
You... I know you.

User avatar
Posts: 324

Re: (Hopefully) Simply script help...

Post by insane3004 » 31 Jul 2016, 08:20

After much trial and error... I have something that works...

It is ugly as all sin and probably horribly inefficient... But it works for now...
Nick <- Entities.FindByModel(null, "models/survivors/survivor_gambler.mdl");
Coach <- Entities.FindByModel(null, "models/survivors/survivor_coach.mdl");
Ellis <- Entities.FindByModel(null, "models/survivors/survivor_mechanic.mdl");
Rochelle <- Entities.FindByModel(null, "models/survivors/survivor_producer.mdl");

totalhealth1 <- Nick.GetHealth();
totalhealth2 <- Coach.GetHealth();
totalhealth3 <- Ellis.GetHealth();
totalhealth4 <- Rochelle.GetHealth();

NickAlive <- null;
CoachAlive <- null;
EllisAlive <- null;
RochelleAlive <- null;

if(totalhealth1 > 1)
{
Msg("Nick is aliver\n");
NickAlive <- 1;
}
else
{
Msg("Nick is dead\n");
NickAlive <- 0;
}
if(totalhealth2 > 2)
{
Msg("Coach is aliver\n");
CoachAlive <- 4;
}
else
{
Msg("Coach is dead\n");
CoachAlive <- 0;
}
if(totalhealth3 > 1)
{
Msg("Ellis is aliver\n");
EllisAlive <- 9;
}
else
{
Msg("Ellis is dead\n");
EllisAlive <- 0;
}
if(totalhealth4 > 1)
{
Msg("Rochelle is aliver\n");
RochelleAlive <- 16;
}
else
{
Msg("Rochelle is dead\n");
RochelleAlive <- 0;
}

BodyCount <- NickAlive + EllisAlive + CoachAlive + RochelleAlive;
if(BodyCount == 0)
{
Say(null, "Everyone is Dead", false);
}
else if(BodyCount == 1)
{
Say(null, "Nick", false);
}
else if(BodyCount == 4)
{
Say(null, "Coach", false);
}
else if(BodyCount == 9)
{
Say(null, "Ellis", false);
}
else if(BodyCount == 16)
{
Say(null, "Rochelle", false);
}
else if(BodyCount == 30)
{
Say(null, "Nick, Coach, Ellis, Rochelle", false);
}
else if(BodyCount == 29)
{
Say(null, "Coach, Ellis, Rochelle", false);
}
else if(BodyCount == 26)
{
Say(null, "Nick, Ellis, Rochelle", false);
}
else if(BodyCount == 25)
{
Say(null, "Ellis, Rochelle", false);
}
else if(BodyCount == 21)
{
Say(null, "Nick, Coach, Rochelle", false);
}
else if(BodyCount == 20)
{
Say(null, "Coach, Rochelle", false);
}
else if(BodyCount == 17)
{
Say(null, "Nick, Rochelle", false);
}
else if(BodyCount == 14)
{
Say(null, "Nick, Coach, Ellis", false);
}
else if(BodyCount == 13)
{
Say(null, "Coach, Ellis", false);
}
else if(BodyCount == 10)
{
Say(null, "Nick, Ellis", false);
}
else if(BodyCount == 5)
{
Say(null, "Nick, Coach", false);
}


Ofcourse the messages are for testing...
Any suggestions on cleaning it up since it is atleast functional now?...
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 175

Re: (Hopefully) Simply script help...

Post by Rayman1103 » 31 Jul 2016, 19:35

I did some re-coding. It could probably be cleaned up some more, depending on how exactly you're firing the outputs to make the living survivors speak.

Couple things I changed with the code:

- Changed the survivor entities to use FindByName instead of FindByModel.
- Changed how to check if a survivor is alive, now it will work flawlessly. Before it could say someone is dead if they have only 1 HP.
- Changed BodyCount so the value changes directly depending on which survivors are alive.
- Also changed the values used for each individual survivor. They now use a bitfield.
- Changed the if statements that checked BodyCount, to use a switch statement instead.

Code: Select all
Nick <- Entities.FindByName(null, "!nick");
Coach <- Entities.FindByName(null, "!coach");
Ellis <- Entities.FindByName(null, "!ellis");
Rochelle <- Entities.FindByName(null, "!rochelle");

BodyCount <- 0;

if ((Nick) && (!Nick.IsDead() && !Nick.IsDying()))
{
   Msg("Nick is alive\n");
   BodyCount += 1;
}
else
{
   Msg("Nick is dead\n");
}
if ((Coach) && (!Coach.IsDead() && !Coach.IsDying()))
{
   Msg("Coach is alive\n");
   BodyCount += 2;
}
else
{
   Msg("Coach is dead\n");
}
if ((Ellis) && (!Ellis.IsDead() && !Ellis.IsDying()))
{
   Msg("Ellis is alive\n");
   BodyCount += 4;
}
else
{
   Msg("Ellis is dead\n");
}
if ((Rochelle) && (!Rochelle.IsDead() && !Rochelle.IsDying()))
{
   Msg("Rochelle is alive\n");
   BodyCount += 8;
}
else
{
   Msg("Rochelle is dead\n");
}

switch ( BodyCount )
{
   case 0:
   {
      Say(null, "Everyone is Dead", false);
      break;
   }
   case 1:
   {
      Say(null, "Nick", false);
      break;
   }
   case 2:
   {
      Say(null, "Coach", false);
      break;
   }
   case 4:
   {
      Say(null, "Ellis", false);
      break;
   }
   case 8:
   {
      Say(null, "Rochelle", false);
      break;
   }
   case 15:
   {   
      Say(null, "Nick, Coach, Ellis, Rochelle", false);
      break;
   }
   case 14:
   {   
      Say(null, "Coach, Ellis, Rochelle", false);
      break;
   }
   case 13:
   {   
      Say(null, "Nick, Ellis, Rochelle", false);
      break;
   }
   case 12:
   {   
      Say(null, "Ellis, Rochelle", false);
      break;
   }
   case 11:
   {   
      Say(null, "Nick, Coach, Rochelle", false);
      break;
   }
   case 10:
   {   
      Say(null, "Coach, Rochelle", false);
      break;
   }
   case 9:
   {   
      Say(null, "Nick, Rochelle", false);
      break;
   }
   case 7:
   {   
      Say(null, "Nick, Coach, Ellis", false);
      break;
   }
   case 6:
   {   
      Say(null, "Coach, Ellis", false);
      break;
   }
   case 5:
   {   
      Say(null, "Nick, Ellis", false);
      break;
   }
   case 3:
   {   
      Say(null, "Nick, Coach", false);
      break;
   }
   default:
      break;
}

User avatar
Posts: 324

Re: (Hopefully) Simply script help...

Post by insane3004 » 01 Aug 2016, 00:40

That will do Rayman... Much appreciation as usual... ~^w^~
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 324

Re: (Hopefully) Simply script help...

Post by insane3004 » 13 Aug 2016, 21:07

Okay... Last one needed... I hope anyway...

With the radiation damage in the second chapter of the campaign... The bots have a nasty issue of eating all the medkits... After some searching I found a convar that prevents this... "sb_temp_health_consider_factor 1"...

But with it being accessed through convar... I am not 100% sure what to do...
If there a way to launch it through a function much like anything else, or is it much more involved?...
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 175

Re: (Hopefully) Simply script help...

Post by Rayman1103 » 14 Aug 2016, 13:49

You can place the following code in a function or should also be able to RunScriptCode it:

Convars.SetValue( "sb_temp_health_consider_factor", "1" );

Let me know if that helps.

User avatar
Posts: 324

Re: (Hopefully) Simply script help...

Post by insane3004 » 14 Aug 2016, 14:02

That appears to have worked... Much appreciation as always Rayman... c:
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 324

Re: (Hopefully) Simply script help...

Post by insane3004 » 03 Mar 2017, 16:21

Nvm... Bot is gone... >.>
"..."

The Neverglades
End of the Line
Haunting Grounds - Sawrunner

User avatar
Posts: 1

Re: (Hopefully) Simply script help...

Post by CardNilos8 » 21 Apr 2017, 23:33

I have no idea of it. Stick RPG 2


Return to Source SDK