Frictional Games Forum (read-only)

Full Version: Player dies instantly when walking into area
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, what I've scripted is when enemy (rock worm) and player is in same area I want the player to die. Instead, when player enters one of these areas he dies immediately instead. The script I did is below. Can someone explain what I did wrong?

//The steps for the worm
void DoWormStep()
{
int lCurrentWormStep = GetLocalVarInt("WormStep");

AddLocalVarInt("WormStep", 1);
int lWormStep = GetLocalVarInt("WormStep");

CheckPlayerWormVariable();

if(lWormStep!=9){
SetLocalVarInt("WormFinished", 3);
}else if (lWormStep!=32){
SetLocalVarInt("WormFinished", 4);
}else{
SetLocalVarInt("WormFinished", 2);
}
}
//The steps for the player
void DoPlayerStep()
{
int lCurrentPlayerStep = GetLocalVarInt("PlayerStep");

CheckPlayerWormVariable();

AddLocalVarInt("PlayerStep", 1);
int lPlayerStep = GetLocalVarInt("PlayerStep");
}

//This checks if player and worm is in the same area. If so, kill the player
void CheckPlayerWormVariable()
{
string sCurrentPlayerLocation = GetLocalVarString("CurrentPlayerLocation");
string sCurrentEnemyLocation = GetLocalVarString("CurrentEnemyLocation");

if(sCurrentEnemyLocation==sCurrentPlayerLocation)
{
FadeOut(0.2f);
PlayGuiSound("worm_attack", 1.0f);

AddPlayerHealth(-200);
CheckPoint("checkpoint","PlayerStartArea_1", "ContinueAgain", "Hints", "DeathByWorm");
}

int lRoomIndex = 0;
for(int i=0; i<52; ++i)
{
if(sCurrentPlayerLocation=="AreaCheckPlayer_" + (i+1))
{
lRoomIndex = i;
break;
}
}
}
GivePlayerDamage(100, "bloodsplat", false, true);

Try that in stead of : AddPlayerHealth(-200);
Wink
Code:
string sCurrentPlayerLocation = GetLocalVarString("CurrentPlayerLocation");
string sCurrentEnemyLocation = GetLocalVarString("CurrentEnemyLocation");

These two are getting nothing from that variables cause they don't exist.
So they are equal and the condition to kill the player is true.
Since I'm not fully sure how localvarstring works, how do I make them NOT equal? My guess is this?

AddLocalVarString("CurrentPlayerLocation", sCurrentEnemyLocation);

And if this is correct, where do I put it?
I don't think so, you should read some tutorials on scripting and variables first.
Then you'll see your error. I think there's something in the wiki.
I can't find any solution to my problem. I just can't. I have tried and I have tried and I have tried. I just don't know how to make them unequal. My best idea was this below.

void TrackPlayerLocation(string &in asParent, string &in asChild, int alState)
string sEntity = asParent;
if(asParent=="Player")
{
SetLocalVarString("CurrentPlayerLocation", asChild);
}
else
{
sEntity = "Enemy ("+sEntity+")";
SetLocalVarString("CurrentEnemyLocation", asChild);
}
}

You guys might just want me to keep trying, but to be honest, I really don't feel like it. My rage level is almost level 99 at the moment.
Nah, listen, if you just want the worm to kill the player on contact, just declare a collide callback.
Worm with player.

PHP Code:
AddEntityCollideCallback"Worm""Player""WormPlayerCollide"true); 

PHP Code:
function WormPlayerCollide string &in pstring &in cint s )
SetPlayerHealth( -); } 

That should work.
Alright, appearntly, the rock worm that ain't named with an angle, like x,y or z, is impossible to use. I have been using that thing all along. Changed it to a angle worm, worked perfectly. I don't know why, just so weird. But I'm glad it's working finally.