Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Raelyn's Big Book of Scripting Questions. (https://forums.graalonline.com/forums/showthread.php?t=85091)

Raelyn 04-27-2009 02:51 AM

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. :confused:

Tigairius 04-27-2009 03:19 AM

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

Raelyn 04-27-2009 03:38 AM

Quote:

Originally Posted by Tigairius (Post 1487087)
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?

Tigairius 04-27-2009 03:39 AM

Quote:

Originally Posted by Raelyn (Post 1487088)
adding +1 to all movements and detections?

this

Raelyn 04-27-2009 04:51 AM

Quote:

Originally Posted by Tigairius (Post 1487089)
this

Thanks, and thanks also for the keypressed help, must do more testing now! :)

Raelyn 04-29-2009 02:17 AM

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.

Novice 04-29-2009 02:48 AM

Quote:

Originally Posted by Raelyn (Post 1487534)
post

Why GS1? GS2 can easily be used instead.

Raelyn 04-29-2009 02:55 AM

Quote:

Originally Posted by Novice (Post 1487540)
Why GS1? GS2 can easily be used instead.

Because I don't know GS2 yet, and because I am silly? :)

Novice 04-29-2009 03:08 AM

Quote:

Originally Posted by Raelyn (Post 1487541)
Because I don't know GS2 yet, and because I am silly? :)

You silly goose.

Raelyn 04-29-2009 03:10 AM

Quote:

Originally Posted by Novice (Post 1487544)
You silly goose.

So what do you think of my silly scripts? :o

Pelikano 04-29-2009 11:47 AM

People hate reading GS1 xD

Skyld 04-29-2009 12:37 PM

Quote:

Originally Posted by Raelyn (Post 1487541)
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.

Codein 04-29-2009 01:43 PM

Quote:

Originally Posted by Skyld (Post 1487589)
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.

Raelyn 04-29-2009 01:51 PM

Quote:

Originally Posted by Pelikano (Post 1487585)
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?

Chompy 04-29-2009 02:29 PM

Quote:

Originally Posted by Raelyn (Post 1487596)
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




All times are GMT +2. The time now is 03:08 AM.

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