Gamelist Review List Song List Watched Journals Forum IRC Gamelist Song List Review List Forum Articles IRC Log Out Add Game Edit Games Add Reviews Edit Reviews Add Songs Edit Songs Log Out Edit Games Edit Reviews Edit Songs Sign Up Log In My Journal My Game Journals Watched Journals All Journals Journal Settings All Journals About Us Staff FAQ
Castle Paradox
Title Bar
Log In Box
 
______  
[more]
    1) Discontinued game by FnrrfYgmSchnish
    2) 8-Bit Graphics Set by FnrrfYgmSchnish
    3) Spoonweaver by Spoon Weaver
    4) Bok's Expedition by FnrrfYgmSchnish
    5) Vore Day RPG by Ronin Catholic
Script dump

 
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Tue Oct 25, 2005 4:46 pm    Post subject: Script dump Reply with quote

This looks like a nice place to dump random scripts so I don't lose them. Ignore new posts to this thread as you probably don't care.

One time usable npcs which respawn when reentering a map (map autorun script):
Code:

script, respawn enemies, begin
  variable (i)
  for (i, 0, 35) do (   #change to npc id range
    alter npc (i, 11, 960 + i)
    set tag (1960 + i, 0)
  )
end

_________________
"It is so great it is insanely great."


Last edited by TMC on Mon Mar 06, 2006 7:30 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Wed Nov 16, 2005 4:20 am    Post subject: Heaps Reply with quote

From http://www.castleparadox.com/ohr/viewtopic.php?t=3870

Code:
global variable (
1, current counter
2, stack ptr
3, num elements
)

define constant (
100, STACK BASE
120, HEAP BASE
)

#example of your master loop
script, master, begin
  while (1) do (
    while (read global (HEAP BASE) == current counter) do (
      #process element at read global (HEAP BASE + 1)
      delete heap root ()
    )
    wait
    current counter := (current counter + 1), mod, 1000
  )
end


#inserts values into the heap, deals with the stack, and returns a ptr to
#an element to fill with data
script, new element, run timer, begin
  variable (element ptr, live time)

  # find a free element

  stack ptr -= 1
  if (stack ptr << 0) then () #throw an error?
  element ptr := read global (STACK BASE + stack ptr)

  live time := run timer -- current counter
  if (live time << 0) then (live time += 1000)


  # insert into heap (at the bottom)

  variable (cur ptr, parent ptr)

  write global (HEAP BASE + num elements * 2, run timer)
  write global (HEAP BASE + num elements * 2 + 1, element ptr)
  cur ptr := num elements
  num elements += 1


  # sort heap from bottom up

  while (cur ptr) do (   #until reach root
    # find parent
    parent ptr := (cur ptr -- 1) / 2

    live parent := read global (HEAP BASE + parent ptr * 2) -- current counter
    if (live parent << 0) then (live parent += 1000)
 
    if (live parent >> live time) then (
      live time := live parent
      heap swap (HEAP BASE + parent ptr * 2, HEAP BASE + heap ptr * 2)
      cur ptr := parent ptr
    ) else (cur ptr := 0)  #jump out of loop

  )

  return (element ptr)
end

# after pulling a reference off the heap and processing the element, call this is it is done
script, delete heap root, begin

  #stick it on the stack
  write global (STACK BASE + stack ptr, read global (HEAP BASE + 1))
  stack ptr += 1

  #put last heap node at the root
  num elements -= 1
  write global (HEAP BASE, read global (HEAP BASE + num elements * 2))
  write global (HEAP BASE + 1, read global (HEAP BASE + num elements * 2 + 1))


  #sort heap from top down

  variable (cur ptr, child1, child2, live1, live2, live parent)
  cur ptr := 0
  live parent := read global (HEAP BASE) -- current counter
  if (live parent << 0) then (live parent += 1000)

  while (cur ptr * 2 << num elements) do (  #has children


    child1 := cur ptr * 2 + 1
    child2 := child1 + 1

    #if more than 1 child, find the lowest life
    if (child2 <= num elements) then (

      live1 := read global (HEAP BASE + child1 * 2) -- current counter
      if (live1 << 0) then (live1 += 1000)
      live2 := read global (HEAP BASE + child2 * 2) -- current counter
      if (live2 << 0) then (live2 += 1000)

      if (live1 >> live2) then (child1 := child2, live1 := live2)

    )

    if (live parent >> live1) then (
      heap swap (HEAP BASE + child1 * 2, HEAP BASE + cur ptr * 2)
      cur ptr := child1
      live parent := live1
    ) else (cur ptr := 999)  #quit

  )
end

script, heap swap, ptr1, ptr2, begin
  variable (temp)
  temp := read global (ptr1)
  write global (ptr1, read global(ptr2))
  write global (ptr2, temp)
  temp := read global (ptr1 + 1)
  write global (ptr1 + 1, read global(ptr2 + 1))
  write global (ptr2 + 1, temp)
end
 

_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
jabbercat
Composer




Joined: 04 Sep 2003
Posts: 823
Location: Oxford

PostPosted: Wed Nov 16, 2005 8:41 am    Post subject: Reply with quote

....What?!?!
Back to top
View user's profile Send private message MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Wed Nov 16, 2005 2:21 pm    Post subject: Reply with quote

omg jabber has infiltrated my journal

PS: maybe I can use heaps in Pheoret? In the AI maybe
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
jabbercat
Composer




Joined: 04 Sep 2003
Posts: 823
Location: Oxford

PostPosted: Wed Nov 16, 2005 3:21 pm    Post subject: Reply with quote

Yes. Big grin
Back to top
View user's profile Send private message MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Mar 06, 2006 7:32 pm    Post subject: Reply with quote

Script for Slime. Fill in/change blanks

Code:
script, check have all souls, begin

 variable (i, check)
 check := 0
 for (i, 0, 24 - 1) do (  # change 24 to number of spells in first list
  if (read spell (0, 0, i)) else (
   i := 999
   check := 999
  )
 )
 for (i, 0 + check, 24 - 1) do (  # change 24 to number of spells in second list
  if (read spell (0, 1, i)) else (
   i := 999
   check := 999
  )
 )
 for (i, 0 + check, 24 - 1) do (  # change 24 to number of spells in third list
  if (read spell (0, 2, i)) else (
   i := 999
   check := 999
  )
 )
 for (i, 0 + check, 24 - 1) do (  # change 24 to number of spells in fourth list
  if (read spell (0, 3, i)) else (
   i := 999
   check := 999
  )
 )
 if (check) then (
  show text box (  )  # door is locked
 ) else (
  show text box (  )  # secret unlocked
 )
end

_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sat Dec 05, 2009 1:35 am    Post subject: Reply with quote

Rain script, for the_dude's 48 hour contest game

Suffers the old camera update delay problem.

Code:
global variable (
 3000, rain parent
 3001, old camera x
 3002, old camera y
)

#the timer ID used by the rain script
define constant (15, rain timer)

plotscript, start rain, begin

 variable (x, y, sl)

 # initialise

 rain parent := create container

 for (x, 0, 320, 80) do (
   for (y, 0, 240, 80) do (
     sl := load large enemy sprite(0, 0)  #change this
     place sprite (sl, x, y)
     set parent (sl, rain parent)
   )
 )

 old camera x := camera pixel x
 old camera y := camera pixel y

 set timer (rain timer, 1, 1, @update rain)
 
end

script, update rain, begin

 variable (x, y, sl)

 # rain effect

 # loop through all slices
 sl := first child (rain parent)
 while (sl) do (
   x := slice x (sl) + 2 -- camera pixel x + old camera x
   if (x >> 320) then (x -= 320 + 80)
   if (x <= -80) then (x += 320 + 80)
   y := slice y (sl) + 2 -- camera pixel y + old camera y
   if (y >> 240) then (y -= 240 + 80)
   if (x <= -80) then (y += 240 + 80)
   place sprite (sl, x, y)
   sl := next sibling (sl)
 )

 old camera x := camera pixel x
 old camera y := camera pixel y

 set timer (rain timer, 1, 1, @update rain)

end

plotscript, stop rain, begin

 stop timer (rain timer)

 # delete rain slices
 
 free slice (rain parent)

end

_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1

 
You cannot 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


All games, songs, and images © their respective owners.
Terms of Service
©2008 Castle Paradox