Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Save NPCs

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Mon Sep 12, 2005 3:16 pm    Post subject: Save NPCs Reply with quote

ATTN: PHC
These are the scripts you requested. I've tested them and they seem to work!

http://castleparadox.com/gamelist-display.php?game=600

These scripts allow you to save the state of all of the NPCs on a map and load them later. Very useful if you want to make a custom menu, for example.

Code:
## SaveNPCs/LoadNPCs
## A handy pair of scripts by Adam Perry!
##   This file and the accompanying sample RPG are distributed free of warranty
## and have been made available to all. They are public domain, but wouldn't it
## be nice if you credited me when you used it? I think so.
##   I waive all rights to these files, though, so if you want to pretend you
## wrote these scripts, that's up to you. I hope you find them useful!

include, plotscr.hsd

define script (autonumber, savenpcs, none)
define script (autonumber, loadnpcs, none)

script, savenpcs (
 variable (ctr)               #outer loop variable
 variable (ctr2)            #inner loop variable
 variable (ref)               #records npc reference no.
 variable (pointer)            #points to the top unused variable

 pointer:=1024               #start at the very top

 for (ctr,0,35) do (            #loop through all npcs
  for (ctr2,0,npccopycount(ctr)--1) do (   #loop through all instances of that npc
   ref:=npc reference(ctr,ctr2)
   write global(pointer,ctr)         #record npc information
   write global(pointer--1,npcx(ref))
   write global(pointer--2,npcy(ref))
   write global(pointer--3,npcdirection(ref))
   pointer:=pointer--4
  )
 )
 writeglobal(pointer,-1)         #an "end-of-stack" marker
)

script, loadnpcs (
 variable (ctr)
 variable (ctr2)
 variable (npcs)
 variable (pointer)

 pointer:=1024

 for (ctr,0,35) do (            #first, destroy all npcs
  npcs:=npccopycount(ctr)
  for (ctr2,0,npcs--1) do (destroynpc(ctr))
 )

 while (readglobal(pointer) <> -1) do (      #loop until all npcs are loaded
  create npc (readglobal(pointer),readglobal(pointer--1),readglobal(pointer--2),readglobal(pointer--3))
  pointer:=pointer--4
  if (pointer<<224) then          #this line keeps it from crashing if savenpcs was never called
   (writeglobal(pointer,-1))
 )
)

#### Helpful example scripts follow. Delete these before putting the others in your game.

define script (1,switchmaps,none)
define script (2,unswitch,none)

script, switchmaps (
 savenpcs
 teleporttomap(2,5,5)
)

script, unswitch (
 teleporttomap(1,5,5)
 loadnpcs
 #but it's generally a better idea to use loadnpcs while the screen is blacked out.
 #I could've put a fade here but I didn't.
)

_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
The Wobbler




Joined: 06 Feb 2003
Posts: 2221

PostPosted: Mon Sep 12, 2005 9:33 pm    Post subject: Reply with quote

Note from Castle Paradox Administration:
This content has been removed by the user. Contact the original author and link them to this post if you wish to view the original content. Only the author can remove the tags hiding this content.
Back to top
View user's profile Send private message
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Tue Sep 13, 2005 6:20 am    Post subject: Reply with quote

That's really weird because loadnpcs doesn't mess with their speed.

NPC locations are saved in savefiles, though, so why are you using loadnpcs in the load script? Is it because the "Save" option is in the menu map?

Troubleshooting ideas:

* Try making an NPC pushable and pushing it around after you load a game to make sure that it's their speed stat that's at zero.

* Try making it load into the menu instead of directly to the map and see if it still bugs up.

* Try putting two "loadnpcs" in a row in the loadscript.

* If that doesn't work, try "loadnpcs, savenpcs, loadnpcs" instead.

Let me know if any of this works for you and I may get a better idea of what's going on. Failing that, I may need to see the RPG file myself.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
The Wobbler




Joined: 06 Feb 2003
Posts: 2221

PostPosted: Tue Sep 13, 2005 10:47 am    Post subject: Reply with quote

Note from Castle Paradox Administration:
This content has been removed by the user. Contact the original author and link them to this post if you wish to view the original content. Only the author can remove the tags hiding this content.
Back to top
View user's profile Send private message
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Tue Sep 13, 2005 11:07 am    Post subject: Reply with quote

Oh, that makes sense. The NPCs must have been suspended.

Awesome, good to hear it's working for you.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group