Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-13-2009, 06:59 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Names in an array

Okay I haven't scripted much in GS2, infact the majority of the scripting I've done on Graal has been before the NPC Server so I am rusty (actually I think the last time I actually scripted I was using QBasic so rusty is an understatement).

Now that my situation has been explained, I'll ask my question; I'm doing my best to script a quest (rather simplistic one) that requires a player to do the work. At this point I want to store a list of titles, first names, and last names which will get randomly paired together the first time you talk to a certain NPC so a player can't just PM an FAQ to get this name for the second part of the quest. I'm really only looking for help on how to store a list of names, in QBasic you could easily store your names in an array and used a loop function to recall them. I'm wondering if there is a similar way in GS2?
__________________
Save Classic!
Reply With Quote
  #2  
Old 02-13-2009, 07:06 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
PHP Code:
this.arrayWithNames = { "Foo""Bar""Baz" };
echo(
"My name is" SPC randomstring(this.arrayWithnames) @ "!"); 
Then you could just have a second array with surnames and randomly pair them together upon onCreated().
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 02-13-2009, 07:17 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
this.arrayWithNames = { "Foo""Bar""Baz" };
echo(
"My name is" SPC randomstring(this.arrayWithnames) @ "!"); 
Then you could just have a second array with surnames and randomly pair them together upon onCreated().
and to make it apply to the NPC:

PHP Code:
function onCreated() {
  
this.firstNames = { "Foo""Bar""Baz" };
  
this.lastNames = { "Foo""Bar""Baz" };

  
this.nick randomstring(this.firstNamesSPC randomstring(this.lastNames);

And you would put that script in the NPC itself
Reply With Quote
  #4  
Old 02-13-2009, 07:28 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
GS2 is so neat, I didn't know you could assign multiple values to this.variables (and text values? Things sure have changed since I was last scripting). So basically this is the new way to create arrays?

Oh and thanks!
__________________
Save Classic!
Reply With Quote
  #5  
Old 02-13-2009, 07:39 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
Yo're welcome, and yes :]
New GS2 incorporates a lot more flexible and powerful features than the old scripting engine. It's really quite interesting and fun :]

Any other questions, feel free to ask
Reply With Quote
  #6  
Old 02-13-2009, 07:43 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Okay I have another question, if nobody minds if I reuse this thread; I have an NPC that I want to move to certain points in a level, but I don't want it moving off the path. The following is a rough interpretation of my path.
HTML Code:
--------OO------
--------OO------
--OO----OO------
--OO----OO------
--OOOOOOOOOOOO--
--OOOOOOOOOOOO--
------------OO--
------------OO--
I don't know if it came out properly formatted, but basically I would like the NPC to follow the "O"s and stay off the "-'s, and then walk back towards the start. I've read about the move function, is that the most efficient way of doing this (plotting out his course)?
__________________
Save Classic!
Reply With Quote
  #7  
Old 02-13-2009, 07:48 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by maximus_asinus View Post
HTML Code:
--------OO------
--------OO------
--OO----OO------
--OO----OO------
--OOOOOOOOOOOO--
--OOOOOOOOOOOO--
------------OO--
------------OO--
I don't know if it came out properly formatted, but basically I would like the NPC to follow the "O"s and stay off the "-'s, and then walk back towards the start. I've read about the move function, is that the most efficient way of doing this (plotting out his course)?
The most efficient way, would probably be to script an A* movement system.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 02-13-2009, 07:57 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by xXziroXx View Post
The most efficient way, would probably be to script an A* movement system.
could you elaborate please?
__________________
Save Classic!
Reply With Quote
  #9  
Old 02-13-2009, 08:08 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by maximus_asinus View Post
could you elaborate please?
http://www.policyalmanac.org/games/aStarTutorial.htm

Should show the basics of an A* path finding algorithm.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #10  
Old 02-13-2009, 08:23 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
OR instead of making a pathfinding algorithm, you could map out nodes and use those instead

Name:  path.png
Views: 145
Size:  1.9 KB

The problem with A* path finding is that it will not always do well over distances with (quite) detailed terrain (many blocking tiles).
__________________
Reply With Quote
  #11  
Old 02-13-2009, 08:35 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Chompy View Post
OR instead of making a pathfinding algorithm, you could map out nodes and use those instead

Attachment 47391

The problem with A* path finding is that it will not always do well over distances with (quite) detailed terrain (many blocking tiles).
I did what you're describing, but since the algorithm was suggested I'll attempt to create that (even if I don't use it, it'll be good practice).
__________________
Save Classic!
Reply With Quote
  #12  
Old 02-13-2009, 08:37 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Chompy View Post
OR instead of making a pathfinding algorithm, you could map out nodes and use those instead
I did that on Mythic (remember the dude walking around in the town?), but it was so boring
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #13  
Old 02-13-2009, 11:00 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by xXziroXx View Post
I did that on Mythic (remember the dude walking around in the town?), but it was so boring
Nodes are better to use when doing big distances, because a path finding algorithm uses long time on long distances.

The path finder I made for my tactics engine is based on the A* path finding algorithm, just slightly different.
__________________
Reply With Quote
  #14  
Old 02-17-2009, 09:07 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,731
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
reviving this thread for questions relating to A*.

I'm working on a script right now (only in testing phase, mostly consists of comment lines planning out what I'm doing). I've done what the tutorial you provided tells me; divided the area into a grid --I'm using 2x2 grid, the size of block.png-- checking clockwise starting from the right and only looking at the up/down - left/right squares. When the NPC finds a square that fits the criteria (in my case a grid that has 4 of the specific tiles I'm looking for) it'll move towards that square, and mark the previous square checked so it won't get stuck in a loop (while I'm on this subject, how do I add variables to an array without clearing the previous?) I'm using replacestring to keep track of this, and I don't believe I need to). My question; is there a more efficient way of checking what tiles are around me other than:

"Grid 1 check... to the right - [one x away, one y away], [two x away, two y] [away, one x away, two y away], and two x away, and one y away]" - if return negative then
"Grid 2 check... below -[one x away, one y away], [two x away, two y] [away, one x away, two y away], and two x away, and one y away]" SO ON AND SO FORTH.

I am writing a function for each grid check, so I am writing for different things. Can I condense this?
__________________
Save Classic!
Reply With Quote
  #15  
Old 02-17-2009, 09:08 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
A* between nodes

edit:sorry, this isn't exactly on-topic.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.