Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #31  
Old 04-27-2009, 02:51 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
I've been doing a lot of work offline with GS1 since I haven't had a stable internet connection for the past week, and I am trying to do something like:

PHP Code:
if (keydown(C)){
   
ShowCharPane();

And it's not working.

I have tried keydown, keydown2, and keypressed in as many ways as I could imagine, and none of them worked. The only thing I could get is (keypressed) to respond, but it responds on EVERY key and when I try to specify with #k, #K etc, it doesn't work. I even tried stuff like:

PHP Code:
if (keypressed)
   if (
strequals(#K,C)){
      
ShowCharPane();
   }

I am not really sure if there is just some strange graal wierdness going on with assigning custom keys.. It doesn't seem like it should be THIS hard...

ALSO;

I have an NPC with setshape 1,32,32; and I would like to somehow make the script read it's x,y in the CENTER of the NPC, not the top left corner, but I am not sure the easiest way how. I tried something like:

this.npcx = x+1;

and then using the new vars for the movement like:

x = this.npcx += .03;

While this SEEMS to make sense to me, it doesn't work, which is causing silly graphical errors with my onwall detection, so the mob is being blocked by the tree, it's image is being drawn on top of the tree, mmm, I could just show the image at x,y -1, but it would have to be looped in everytime, which seems like a silly thing to do since we are already moving the whole NPC too?

Very confused.
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #32  
Old 04-27-2009, 03:19 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Well, in GS1, for the keypressed thing, use :
PHP Code:
if (keypressed) {
   if (
strequals(#p(1),C)){
      
ShowCharPane();
   }

You could also do:
PHP Code:
if (keydown2(keycode(c), true)) { 
Like in a timeout or in the keypressed event.

to replicate these in gs2, do:

PHP Code:
function onKeyPressed(codekey) {
  switch (
key) {
    case 
"C":
      
ShowCharPane();
    break;
  }

or
PHP Code:
if (keydown2(getKeyCode("C"), true)) { 
As far as finding the center of the npc, you will always have to add the offset of +1 if the width/height is 32
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #33  
Old 04-27-2009, 03:38 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by Tigairius View Post
Well, in GS1, for the keypressed thing, use :
PHP Code:
if (keypressed) {
   if (
strequals(#p(1),C)){
      
ShowCharPane();
   }

You could also do:
PHP Code:
if (keydown2(keycode(c), true)) { 
Like in a timeout or in the keypressed event.

to replicate these in gs2, do:

PHP Code:
function onKeyPressed(codekey) {
  switch (
key) {
    case 
"C":
      
ShowCharPane();
    break;
  }

or
PHP Code:
if (keydown2(getKeyCode("C"), true)) { 
As far as finding the center of the npc, you will always have to add the offset of +1 if the width/height is 32
Adding the offset as in showing the NPC -1? Or adding +1 to all movements and detections?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #34  
Old 04-27-2009, 03:39 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Raelyn View Post
adding +1 to all movements and detections?
this
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #35  
Old 04-27-2009, 04:51 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by Tigairius View Post
this
Thanks, and thanks also for the keypressed help, must do more testing now!
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #36  
Old 04-29-2009, 02:17 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Ok, I've wrote 2 scripts while I did not have internet access, but now I have it back and I am going to try and get them to work on my server, but I wanted to post here first and get critique on the scripting itself (to better improve my noob self) and advice on the best way to upload it to work, like not sure how the various parts will be read by the server, since offline it all works in 2 weapons.

They are both still works in progress, so any pointers/changes/improvements would be appreciated!

Anyway, have a look, this first one is a basic baddy:

PHP Code:
//scripted(poorly) by Raelyn


if (created){
  
timeout .05;
  
setshape 1,32,32;
  
NpcStats();
}

if (
wa**** || waspelt){
  
NpcWa****();
  if (
this.cur_hp =< 0){
    
NpcDeath();
  }
}

if (
timeout){
  
NpcChase();
  
message #v(this.cur_hp)/#v(this.max_hp);
  
timeout .05;
}

if ((
x+1) > playerx && (x-1) < playerx && (y+1) > playery && (y-1) < playery){
  
hitplayer ,0,x,y;
}

function 
NpcDeath(){
  
clientr.cur_exp += 10;
  
message dead!;
  
destroy;
}

function 
NpcWa****(){
  
this.cur_hp -= 1;
  
message #v(this.cur_hp)/#v(this.max_hp);
  
timeout .5;
}

function 
NpcStats(){
  
this.cur_hp 5;
  
this.max_hp 5;
}


// NPC chases the player until wall
function NpcChase(){
  if (
playerx>x){
    
+= .3;
    if (
onwall(x+1,y+1)){
      
-= .3;
    }

  }
  else
    
-= .3;
  if (
onwall(x+1,y+1)){
    
x+= .3;
  }
  if (
playery>y){
    
y+= .3;
    if (
onwall(x+1,y+1)){
      
y-= .3;
    }
  }
  else
    
y-= .3;
  if (
onwall(x+1,y+1)){
    
y+= .3;
  }

And this one is the whole player system I have thus far..

PHP Code:
//scripted(poorly) by Raelyn

// index key
//
// 0411  - help interface
// 0412  - help interface
// 0001 - level up
// 0002 - exp display
// 205  - hud head
// 202  - hud background
// 200  - hud current hp
// 2001 - hud hp /
// 2002 - hud max hp
// 201  - hud current mp
// 2011 - hud mp /
// 2012 - hud max mp


// initialize the stuff
if (created){
  
SetStats();
  
UpdateGui();
  
ThisLevel();
  
removetiledefs;
  
addtiledef2 raelyn_tiles_sand.png,scripting,0,0;
  
addtiledef2 raelyn_tiles_sand-trailmark.png,scripting,0,32;
  
addtiledef2 raelyn_tiles_sand-footprint.png,scripting,0,48;
  
timeout .05;
}

if (
playerhurt){
  
clientr.cur_hp clientr.cur_hp 1;
  
UpdateGui();
}

if (
clientr.cur_hp 1){
  
message Dead!;
}

if (
keypressed){
  if (
strequals(#p(1),C)){
    
message woot;
  }
}

if (
timeout){
  
UpdateGui();
  
timeout .05;
}


// chat commands
if (playerchats){
  if (
strequals(#c,/setstats)){
    
SetStats();
  }
  if (
strequals(#c,/help)){
    
Help();
  }
  if (
strequals(#c,/updategui)){
    
UpdateGui();
  }
  if (
strequals(#c,/levelup)){
    
LevelUp();
    
UpdateGui();
  }
  if (
strequals(#c,/sethead)){
    
sethead head25.png;
    
UpdateGui();
  }

}

// stuff for this level
function ThisLevel(){
  
showimg 2022,raelyn_desert_trailmarker.png,35,24;
  
changeimgvis 2022,1;
}

// in-game help
function Help(){
  
showtext 0411,400,400,tempus sans itc,,The available commands are:;
  
changeimgvis 0411,4;
  
sleep 2;
  
showtext 0411,,,,,;
  
showtext 0412,400,400,tempus sans itc,,/help, /setstats, /updategui, /sethead, /levelup;
  
changeimgvis 0412,4;
  
sleep 2;
  
showtext 0412,,,,,;
}

// leveling up the player
function LevelUp(){
  
clientr.max_exp += clientr.max_exp 1;
  
clientr.str += clientr.str 100 *10;
  
clientr.end += clientr.end 100 *10;
  
clientr.dex += clientr.dex 100 *10;
  
clientr.int += clientr.int 100 *10;
  
clientr.max_hp clientr.end 2;
  
clientr.cur_hp clientr.max_hp;
  
clientr.max_mp clientr.int;
  
clientr.cur_mp clientr.max_mp;
  
showtext 0001,playerx,playery-2,tempus sans itc,,Level up!;
  
UpdateGui();
  
sleep 2;
  
showtext 0001,,,,,;
}

// setting up newb stats
function SetStats(){
  
clientr.cur_exp 0;
  
clientr.max_exp 10;
  
clientr.str 10;
  
clientr.end 10;
  
clientr.dex 10;
  
clientr.int 10;
  
clientr.max_hp clientr.end 2;
  
clientr.cur_hp clientr.max_hp;
  
clientr.max_mp clientr.int;
  
clientr.cur_mp clientr.max_mp;
}


// refreshing the interface
function UpdateGui(){
  
disableselectweapons;
  
disablemap;
  
showstats 1024;

  if (
clientr.cur_exp => clientr.max_exp){
    
LevelUp();

  }

  
showtext 0002,100,100,tempus sans itc,,Exp#v(clientr.cur_exp) / #v(clientr.max_exp);
  
changeimgvis 00025;

  
showimg 205,#3,12,12;
  
changeimgpart 205,0,62,32,32;
  
changeimgvis 205,6;
  
showimg 202,raelyn_hud.png,10,10;
  
changeimgpart 202,0,0,140,36;
  
changeimgvis 202,5;

  if (
clientr.cur_hp == clientr.max_hp){
    
showimg 206,raelyn_hud.png,46,12;
    
changeimgpart 206,0,36,100,16;
    
changeimgvis 206,6;
  } else {
    
showimg 206,raelyn_hud.png,46,12;
    
changeimgpart 206,0,36,(clientr.cur_hp 100) / clientr.max_hp,16;
    
changeimgvis 206,6;
  }
  
showimg 207,raelyn_hud.png,46,29;
  
changeimgpart 207,0,36,100,16;
  
changeimgvis 207,6;

  
showtext 200,50,11,tempus sans itc,,#v(int(clientr.cur_hp));
  
showtext 2001,90,11,tempus sans itc,,/;
  
showtext 2002,100,11,tempus sans itc,,#v(int(clientr.max_hp));
  
changeimgvis 200,7;
  
changeimgzoom 200,.75;
  
changeimgvis 2001,7;
  
changeimgzoom 2001,.75;
  
changeimgvis 2002,7;
  
changeimgzoom 2002,.75;

  
showtext 201,50,28,tempus sans itc,,#v(int(clientr.cur_mp));
  
showtext 2011,90,28,tempus sans itc,,/;
  
showtext 2012,100,28,tempus sans itc,,#v(int(clientr.max_mp));
  
changeimgvis 201,7;
  
changeimgzoom 201,.75;
  
changeimgvis 2011,7;
  
changeimgzoom 2011,.75;
  
changeimgvis 2012,7;
  
changeimgzoom 2012,.75;

Be gentle, please.
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #37  
Old 04-29-2009, 02:48 AM
Novice Novice is offline
Developer
Join Date: Dec 2008
Posts: 90
Novice is an unknown quantity at this point
Send a message via MSN to Novice
Quote:
Originally Posted by Raelyn View Post
post
Why GS1? GS2 can easily be used instead.
Reply With Quote
  #38  
Old 04-29-2009, 02:55 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by Novice View Post
Why GS1? GS2 can easily be used instead.
Because I don't know GS2 yet, and because I am silly?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #39  
Old 04-29-2009, 03:08 AM
Novice Novice is offline
Developer
Join Date: Dec 2008
Posts: 90
Novice is an unknown quantity at this point
Send a message via MSN to Novice
Quote:
Originally Posted by Raelyn View Post
Because I don't know GS2 yet, and because I am silly?
You silly goose.
Reply With Quote
  #40  
Old 04-29-2009, 03:10 AM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by Novice View Post
You silly goose.
So what do you think of my silly scripts? :o
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #41  
Old 04-29-2009, 11:47 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
People hate reading GS1 xD
Reply With Quote
  #42  
Old 04-29-2009, 12:37 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Raelyn View Post
Because I don't know GS2 yet, and because I am silly?
Learn GScript2. Old GScript is not worth so much as a moment of your time, and basically, GScript2 is better in absolutely every way.
Reply With Quote
  #43  
Old 04-29-2009, 01:43 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Skyld View Post
Learn GScript2. Old GScript is not worth so much as a moment of your time, and basically, GScript2 is better in absolutely every way.
Agreed.
Reply With Quote
  #44  
Old 04-29-2009, 01:51 PM
Raelyn Raelyn is offline
the Professional.
Raelyn's Avatar
Join Date: Sep 2003
Location: Zormite
Posts: 964
Raelyn will become famous soon enough
Quote:
Originally Posted by Pelikano View Post
People hate reading GS1 xD
Well that's lame. :/

Do classes operate like global functions? Like, if I put all my functions into classes, I can call them up in any scripts on the server?
__________________
*Don't let the door hit you on the way out.*
Reply With Quote
  #45  
Old 04-29-2009, 02:29 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 Raelyn View Post
Well that's lame. :/

Do classes operate like global functions? Like, if I put all my functions into classes, I can call them up in any scripts on the server?
You'd have to join that class to use it's content.

Lets say this is a class called fibonacci:

PHP Code:
function fib(n) {
  return (((
1+5^0.5)/2)^- ((1-5^0.5)/2)^n)/(5^0.5)


To use that function, I would have to do:

PHP Code:
function onCreated() {
  
join("fibonacci");

  echo(
fib(7)); // 13

__________________
Reply With Quote
Reply


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 07:08 AM.


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