Scripts / Scripting Help: Chatty NPC's and Triggering a response.

Author
Message
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 15:43 Edited at: 1st Dec 2015 15:46
HI guys, I wonder if you can help me out. The game I am trying to make requires you to investigate the whereabouts of a missing person by talking to NPC's in a chain and I'm trying to figure out how to do that.

For the chatting part I've found a script on these boards which looks like it would work ....



... that should in theory allow me to have a short conversation, however the next NPC in the chain I need to have a standard non-chatty neutral AI unless I have spoken to the first.

The way I thought of doing it was to have two almost identical NPC's on the same spot, one with a normal AI spawned at the start, the other with a chat AI not spawned at the start, then at the end the chat script I could destroy one and spawn the other.

Is this possible? If so what code would be needed and where would it go in the above script?

Or is there an easier way to do it? If so could somebody explain how?
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 1st Dec 2015 16:54 Edited at: 1st Dec 2015 16:57
I think creating multiple almost identical entities is unneccessary complicated. Haven't tested your script so not 100 % sure, but I would try to add something like this to the main function:

And in the next script:
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 17:02
OK thanks for the reply, i'm really sorry but I don't have a clue with LUA scripting, I have no idea what those lines of code you gave do, what I add to them (the parts marked in green) or where to put them, could you elaborate please?
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 17:35 Edited at: 1st Dec 2015 17:48
Would this be right?

My first character would have the following script ...



and my second character would have this script ...



Is that correct?
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 1st Dec 2015 21:25
The script follows a bit different logic than mine and it seems like there is a part of it missing. Is this based on another script? Can you post a link to the original one?

Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 22:05 Edited at: 1st Dec 2015 22:09
It was form another thread here, I can't remember where now, but I just can't get it working it was error after error no matter what I changed, I doubt it worked in the first place, so I gave up.

However I got something else working instead. No chat options, but the NPC says a few lines, then activates the flag and tells you to go to someone else who will now talk to you, he activates another flag and a hidden winzone spawns.

Makes a pretty decent story driven game

First NPC gets this:


Second NPC gets this:


Winzone gets this:


Although your advice didn't help with the original script, it REALY helped me work the new script out big time, very much appreciated!
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 1st Dec 2015 22:16 Edited at: 1st Dec 2015 22:17
Nice to hear you got it to work. If you want to learn more about Lua, I recommend this:

http://www.lua.org/pil/contents.html

First 5 chapters should be enough to get you started.
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 22:33
Cool, something to read at work tomorrow!

Seriously though, I haven't a clue about LUA, i'm just taking bits and pieces of scripts I find and patching them together hoping they work, sometimes they do and sometimes they don't, but every time I learn something new
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 1st Dec 2015 22:39 Edited at: 2nd Dec 2015 10:12
I'm actually quite pleased about the hidden winzone part, it's a really simple script, only a couple of extra lines added to the original winzone script, but it's something that has bugged me for a while and something I can see on the forum that has bugged a few people.

It seems t be impossible to make a winzone spawn on an action, and most threads I've seen on the subject try to do it with some complicated script that uses lots of entities and multiple scripts and even then it doesn't work how they want.

I was taking a break from the chat script and looking at ways to spawn a winzone at the end of the story, trying to get a hide command to work, at the same time I was looking at your flag command, and a light came on in my head. Instead of hiding the winzone I just put its commands inside an if flag function so it's basically not active unless the flag is active, something so simple yet so elusive lol
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 3rd Dec 2015 07:59 Edited at: 3rd Dec 2015 07:59
Well that all worked quite well, I've even added some that us if flags to have one conversation then send you to another person who sends you back to the same character for a different conversation

Only one snag I've hit though, once you have had the conversation if you move away and come back it repeats the conversation, this is obviously because of the time reset function in there to reset the conversation when you move away, however if I remove that you still get the last line of the conversation whenever you're in range.

Now I thought to get around this by adding another if flag and using SwitchScript to change them to ai_neutral once the conversation ends, but for some reason I can't get it to work. Whenever I add the line SwitchScript(e,ai_neutral) it just bombs out telling me there is no call to the function ai_neutral_main

Any ideas what i'm doing wrong?
(see code below)



hiredgunz48
9
Years of Service
User Offline
Joined: 9th Sep 2015
Location: Seattle, Washington
Posted: 3rd Dec 2015 23:25 Edited at: 3rd Dec 2015 23:46
I don't know if this will work for you, but it's what I came up with for my "fallout" type game with chatty characters, and you can skip the timers altogether. I was inspired by another script I'm sure, but don't remember which, so I'm not sure who to share credit with! This script allows you to fill the screen with several different text screens with one character, then stops the convo from reappearing after moving away from them after it's done.



You may want to move the function "gen_text" to your default.lua or somewhere else, as adding the function to several characters is redundant.

I haven't tried it yet, but you might be also able to use the "SwitchScript(e,str)" command to give the 1st character a new convo script that will only activate after the first convo is done, then setting a value for a second character's finished conversation that sends you back to the first person, and makes the first person's second convo active.





Windows 10 64bit, Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz, 3301 Mhz, 4 Core(s), NVIDIA GeForce GTX 960 2 gig GDDR5, 16 gigs ram
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 4th Dec 2015 07:50 Edited at: 4th Dec 2015 07:58
Quote: "
I haven't tried it yet, but you might be also able to use the "SwitchScript(e,str)" command to give the 1st character a new convo script that will only activate after the first convo is done"


That's exactly what i'm trying to do, but every time I use SwitchScript in my script I get the error message stating "there is no call to the function ai_neutral_main", that's the bit I need help with, the convo side of it works fine, I just can't get it to switch to a new script.

On a side note, it's funny you showed me a script usiing text panels instead of prompt. I'd literally just finished rewriting my story scripts to use text panels instead of prompt, removed the timer and added scripting to trigger the convo by pressing E, when I checked here

And even weirder, I just noticed your pictures, the character you use is identical to one I use and the position in the room he's in is almost identical, right down to the filing cabinet too lol
Moshroom
9
Years of Service
User Offline
Joined: 18th Jul 2015
Location: Finland
Posted: 4th Dec 2015 09:41
Try to changes this:

To this:
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 4th Dec 2015 09:59 Edited at: 4th Dec 2015 12:27
I think I have a final draft for my script now, it seems to do all I need it to do.

Basically, you move up to the character, press E and get a text panel and activates a flag, you press E to close the panel and when you press E again it detects the flag and displays the next text panel, activates a different flag and deactivates the first flag.

By changing/adding/deleting the flags in the script I can manipulate it to move back and forth between different characters and they will all have a default unflagged conversation panel before and after you read their flagged conversation panels.



and because it uses flags you can use it to activate/use other entities by just putting the code in the main part of the items scrip inside an if flag command as below:



Here's how it looks in a winzone script:



If the winsome flag is 0 then the winzone script will do nothing, effectively being hidden, if the flag is 1 then it will operate as a normal winzone.
hiredgunz48
9
Years of Service
User Offline
Joined: 9th Sep 2015
Location: Seattle, Washington
Posted: 4th Dec 2015 16:15 Edited at: 4th Dec 2015 16:26
Quote: "And even weirder, I just noticed your pictures, the character you use is identical to one I use and the position in the room he's in is almost identical, right down to the filing cabinet too lol"


That is weird

Do you happen to be a fallout player too?

Oh, you might want to use GetScancode() == 18 instead of checking for "e" or "E" as it gets the keypress no matter whether it's caps or not.. otherwise, if you hit the caps lock, the convos and anything using the "e" key stops working when the caps key is on.

Otherwise, looks good!
Windows 10 64bit, Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz, 3301 Mhz, 4 Core(s), NVIDIA GeForce GTX 960 2 gig GDDR5, 16 gigs ram
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 4th Dec 2015 16:32 Edited at: 5th Dec 2015 02:13
Quote: "

Try to changes this:

+ Code Snippet







1

SwithScript(e,ai-neutral)


To this:

+ Code Snippet


1

SwithScript(e,ai_neutral)


"


Sorry Moshroom that's won't fix it, because the typo isn't in the script i'm using, it's only a typo in my code snippet (I typed it fast at work), still having issues with switching.
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 4th Dec 2015 16:39
Quote: "
That is weird

Do you happen to be a fallout player too?

"



I played the first halo to death, got bored in an hour in the second one, hated the third one in minutes, never bothered with the off-shoots/add-ons and am refusing to touch the fourth one

Quote: "
Oh, you might want to use GetScancode() == 18 instead of checking for "e" or "E" as it gets the keypress no matter whether it's caps or not.. otherwise, if you hit the caps lock, the convos and anything using the "e" key stops working when the caps key is on.

Otherwise, looks good!
"


Thanks for the tip.

So if I understand correctly, I replace all instances of:



with:




is that right?
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Dec 2015 20:31 Edited at: 5th Dec 2015 20:33

yes

Quote: "That's exactly what i'm trying to do, but every time I use SwitchScript in my script I get the error message stating "there is no call to the function ai_neutral_main", that's the bit I need help with, the convo side of it works fine, I just can't get it to switch to a new script."

SwitchScript(e,str)
requires the script name to be set as a string (i'm assuming you already did this to get the error but your example above isnt in string format so i'm just clarifying for anyone else who may read this)
2ndly the command requires the code be in the same script page/file or it is linked using include/require
i.e.

or
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 5th Dec 2015 23:05

Yeah my syntax was right, I just didn't know that you had to call the function before applying the command, thanks i'll look into it tomorrow.

Login to post a reply

Server time is: 2024-12-22 10:30:35
Your offset time is: 2024-12-22 10:30:35