nickTs
Junior Member
Posts: 12
Threads: 3
Joined: Sep 2010
Reputation:
0
|
Scripts won't work
I've been refraining from posting a thread thinking I could figure this out myself. Well, as you can see it isn't going well. So, there's a couple things (for now) I need help with.
Playing a single sound or sequence of sounds when I enter a certain area. I've been able to get the sound to play just by setting it in the editor, so I know the files are good, but once I try to set it to play when a specific Area is entered it doesn't seem to work.
Spawning an enemy. Similar to above. I can simply place it in the editor and it will spawn just fine once the map loads, but when I try to set it to an Area it will either cut my frame rate in half and not work or just simply do nothing. Specifically, I'm trying to make an enemy spawn, walk a short path, and disappear.
I've tried digging through the default maps/scripts, reading the Wiki pages, searching the forum and even though I have directly copied from scripts (with appropriate renaming) that seemed to work perfectly for others, it won't work for me.
So, if anyone could help me with my issues it would be very much appreciated. If not, here's to hoping for an editor update with automatic scripting.
|
|
09-17-2010, 07:56 AM |
|
Deruu
Junior Member
Posts: 6
Threads: 0
Joined: Sep 2010
Reputation:
0
|
RE: Scripts won't work
I cooked up a simple example map that does pretty much everything you asked for(plus some bonus lever action). I commented the code a bit to give you a fair idea of what's going on, I'd be glad to explain it here however if you've got any problems with it.
The lever disables the enemy encounter that's triggered as soon as you step into the room.
Download:
http://solidfiles.com/d/458a/download/
|
|
09-17-2010, 10:00 AM |
|
MulleDK19
Senior Member
Posts: 545
Threads: 21
Joined: Jun 2009
Reputation:
10
|
RE: Scripts won't work
(09-17-2010, 07:56 AM)nickTs Wrote: I've been refraining from posting a thread thinking I could figure this out myself. Well, as you can see it isn't going well. So, there's a couple things (for now) I need help with.
Playing a single sound or sequence of sounds when I enter a certain area. I've been able to get the sound to play just by setting it in the editor, so I know the files are good, but once I try to set it to play when a specific Area is entered it doesn't seem to work.
Spawning an enemy. Similar to above. I can simply place it in the editor and it will spawn just fine once the map loads, but when I try to set it to an Area it will either cut my frame rate in half and not work or just simply do nothing. Specifically, I'm trying to make an enemy spawn, walk a short path, and disappear.
I've tried digging through the default maps/scripts, reading the Wiki pages, searching the forum and even though I have directly copied from scripts (with appropriate renaming) that seemed to work perfectly for others, it won't work for me.
So, if anyone could help me with my issues it would be very much appreciated. If not, here's to hoping for an editor update with automatic scripting.
Post your script.
|
|
09-17-2010, 10:51 AM |
|
nickTs
Junior Member
Posts: 12
Threads: 3
Joined: Sep 2010
Reputation:
0
|
RE: Scripts won't work
(09-17-2010, 10:51 AM)MulleDK19 Wrote: Post your script.
void OnStart()
{
AddUseItemCallback("useexit", "doorkey_1", "keydoor_1", "UseKey",true);
AddEntityCollideCallback("Player", "mgrowl1area", "CollideCallback", true, 1);
AddEntityCollideCallback("Player", "GruntScare1area", "CollideCallback", true, 1);
}
void CollideCallback(string &in parent, string &in child, int state)
{
if(child == "mgrowl1area")
{
AddTimer("monster_growl_01.snt", 0, "TimedSoundSequence");
} else if(child == "GruntScare1area")
{
SetEntityActive("GruntScare1", true);
AddEnemyPatrolNode("GruntScare1", "GruntScare1Node1", 0, "");
AddEnemyPatrolNode("GruntScare1", "GruntScare1Node2", 0, "");
AddEntityCollideCallback("GruntScare1", "GruntScare1gone",
} else if(child == "GruntScare1gone")
{
FadeEnemyToSmoke("GruntScare1", false);
}
}
void TimedSoundSequence(string &in timer)
{
PlaySoundAtEntity("", timer, "mgrowl1pos", 0, false);
}
This is what I'm trying right now. All of this, except for the key script, is from the example that Deruu posted, but with appropriate renames and light trimming. When I try to run the map I get a crash and error "main (29,2):ERR :Expected expression value." The weird part is that the script worked perfectly in the example map, but maybe I'm missing something obvious or accidentally changed something I wasn't supposed to. I've been staring at scripts for a while now, the lines are starting to blur together.
Edit: Line 29 in the full script is } else if(child == "GruntScare1gone")
|
|
09-17-2010, 11:42 AM |
|
jens
Frictional Games
Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation:
202
|
RE: Scripts won't work
please post the full script, becuase it seems to be a simple error, but as line 29 is not in the part you posted and also because the error on 29 could be caused by a missing character in another place it is easier to see the whole thing.
|
|
09-17-2010, 11:53 AM |
|
jens
Frictional Games
Posts: 4,093
Threads: 199
Joined: Apr 2006
Reputation:
202
|
RE: Scripts won't work
ah, you have AddEntityCollideCallback("GruntScare1", "GruntScare1gone",
that should be
AddEntityCollideCallback("GruntScare1", "GruntScare1gone", 1, true);
I suppose
|
|
09-17-2010, 11:56 AM |
|
MulleDK19
Senior Member
Posts: 545
Threads: 21
Joined: Jun 2009
Reputation:
10
|
RE: Scripts won't work
(09-17-2010, 11:56 AM)jens Wrote: ah, you have AddEntityCollideCallback("GruntScare1", "GruntScare1gone",
that should be
AddEntityCollideCallback("GruntScare1", "GruntScare1gone", 1, true);
I suppose
AddEntityCollideCallback("GruntScare1", "GruntScare1gone", "Function", true, 1);
|
|
09-17-2010, 12:02 PM |
|
nickTs
Junior Member
Posts: 12
Threads: 3
Joined: Sep 2010
Reputation:
0
|
RE: Scripts won't work
(09-17-2010, 12:02 PM)MulleDK19 Wrote: AddEntityCollideCallback("GruntScare1", "GruntScare1gone", "Function", true, 1);
Adding this let the map and script load, but the grunt pauses at node1 then continues to pace between the two. Do I need to add more than one node if I want him to walk in a straight line?
The sound played fine, though it didn't seem to come from the direction of the Area I placed.
I took node2 out and now the grunt just walks to node1 and stands there. I also moved the sound area far to my right, but it still sounds like it's being played right where I stand only quieter.
(09-17-2010, 11:53 AM)jens Wrote: please post the full script
void UseKey(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
RemoveItem(asItem);
}
void OnStart()
{
AddUseItemCallback("useexit", "doorkey_1", "keydoor_1", "UseKey",true);
AddEntityCollideCallback("Player", "mgrowl1area", "CollideCallback", true, 1);
AddEntityCollideCallback("Player", "GruntScare1area", "CollideCallback", true, 1);
}
void CollideCallback(string &in parent, string &in child, int state)
{
if(child == "mgrowl1area")
{
AddTimer("monster_growl_01.snt", 0, "TimedSoundSequence");
} else if(child == "GruntScare1area")
{
SetEntityActive("GruntScare1", true);
AddEnemyPatrolNode("GruntScare1", "GruntScare1Node1", 0, "");
AddEntityCollideCallback("GruntScare1", "GruntScare1gone", "Function", true, 1);
} else if(child == "GruntScare1gone")
{
FadeEnemyToSmoke("GruntScare1", false);
}
}
void TimedSoundSequence(string &in timer)
{
PlaySoundAtEntity("", timer, "mgrowl1pos", 0, false);
}
(This post was last modified: 09-17-2010, 12:45 PM by nickTs.)
|
|
09-17-2010, 12:14 PM |
|
Deruu
Junior Member
Posts: 6
Threads: 0
Joined: Sep 2010
Reputation:
0
|
RE: Scripts won't work
You'll need more than two nodes for the enemy to navigate our map properly. They are not just used for scripting, they are also used to tell the enemies how to get around obstacles(the engine does this automatically, just place a few nodes around the map like I did in my example and it should be fine. Just don't overdo it, if I'm not mistaken enemies do deviate from the nodes a bit to pursue the player).
I see that you have removed the second patrol node from the script, this is what's causing the grunt to stand still once it reaches the node. Re-add the second one, then to prevent the grunt from walking between the two patrol nodes use another area in the path of his second patrol node to make him disappear before he reaches it.
It would be nice to have a callback added when enemies reach a node, *hint hint*@devs
|
|
09-17-2010, 01:08 PM |
|
nickTs
Junior Member
Posts: 12
Threads: 3
Joined: Sep 2010
Reputation:
0
|
RE: Scripts won't work
(09-17-2010, 01:08 PM)Deruu Wrote: You'll need more than two nodes for the enemy to navigate our map properly. They are not just used for scripting, they are also used to tell the enemies how to get around obstacles(the engine does this automatically, just place a few nodes around the map like I did in my example and it should be fine. Just don't overdo it, if I'm not mistaken enemies do deviate from the nodes a bit to pursue the player).
I see that you have removed the second patrol node from the script, this is what's causing the grunt to stand still once it reaches the node. Re-add the second one, then to prevent the grunt from walking between the two patrol nodes use another area in the path of his second patrol node to make him disappear before he reaches it.
It would be nice to have a callback added when enemies reach a node, *hint hint*@devs
I took the second node out because I figured it was unnecessary since I only wanted him to walk a straight line.
Anyway, I did like you said and added the second node, dropped some path nodes in, and I made sure he would hit the disappear area before reaching the second node by stretching it and moving it further away from the second node. With all that and changing the pause time from 4 to 0, he still moves to node1, pauses, and paces. I don't understand why this isn't working right when it seemed to work fine in your example map.
|
|
09-18-2010, 12:13 PM |
|
|