Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Names in an array (https://forums.graalonline.com/forums/showthread.php?t=84185)

maximus_asinus 02-13-2009 06:59 PM

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?

xXziroXx 02-13-2009 07:06 PM

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().

thatdwarf 02-13-2009 07:17 PM

Quote:

Originally Posted by xXziroXx (Post 1466101)
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

maximus_asinus 02-13-2009 07:28 PM

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!

thatdwarf 02-13-2009 07:39 PM

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 :D

maximus_asinus 02-13-2009 07:43 PM

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)?

xXziroXx 02-13-2009 07:48 PM

Quote:

Originally Posted by maximus_asinus (Post 1466114)
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.

maximus_asinus 02-13-2009 07:57 PM

Quote:

Originally Posted by xXziroXx (Post 1466117)
The most efficient way, would probably be to script an A* movement system.

could you elaborate please? :noob:

xXziroXx 02-13-2009 08:08 PM

Quote:

Originally Posted by maximus_asinus (Post 1466120)
could you elaborate please? :noob:

http://www.policyalmanac.org/games/aStarTutorial.htm

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

Chompy 02-13-2009 08:23 PM

1 Attachment(s)
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).

maximus_asinus 02-13-2009 08:35 PM

Quote:

Originally Posted by Chompy (Post 1466131)
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).

xXziroXx 02-13-2009 08:37 PM

Quote:

Originally Posted by Chompy (Post 1466131)
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 :(

Chompy 02-13-2009 11:00 PM

Quote:

Originally Posted by xXziroXx (Post 1466136)
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. :p

The path finder I made for my tactics engine is based on the A* path finding algorithm, just slightly different.

maximus_asinus 02-17-2009 09:07 PM

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?

DustyPorViva 02-17-2009 09:08 PM

A* between nodes :)

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

Chompy 02-17-2009 09:30 PM

Video: http://forums.graalonline.com/forums...0&postcount=68
Screenshots: http://forums.graalonline.com/forums...3&postcount=71

Above shows the tactics engine I made, which uses a concept quite/very similar to the A* concept. (Tweaked for obstacles and 4 direction movement, instead of diagonal).

Working with the A* concept is quite fun, and can be challenging when it comes to fixing bugs/weird paths :)


All times are GMT +2. The time now is 12:39 PM.

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