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
  #1  
Old 05-24-2009, 03:24 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
2 questions (server warp & putnpc2)

Okay. Firstly, I've made an NPC that when the player says /serverlist, a GUI window pops up. with a long list of servers. The player can select one, click connect, and will warp to that server.

Everything works just fine. Except for the fact that i don't know how to make serverwarp read a var.
Currently it's: serverwarp this.selectedserverconnect;
though i've tried serverwarp @ this.selectedserverconnect; and a few more.
I just need the format.


Also, in regards to putnpc2. This has drivin me crazy.
Offline, I used putnpc to place a custom NPC (like, lets say it puts a bomb script that lays a bomb, that puts a few randomly sized explosions, in random areas within a certain area. I would put something like:
PHP Code:
if(weaponfired&&playerbombs>0){
if(
playerdir=0){
play put.wav;putnpc custombombimg.png,custombomb.txt,playerx+0.5,playery-1;
playerbombs-=1;
}
if(
playerdir=1){
play put.wav;putnpc custombombimg.png,custombomb.txt,playerx-1.5,playery+1;
playerbombs-=1;
}
if(
playerdir=2){
play put.wav;putnpc custombombimg.png,custombomb.txt,playerx+0.5,playery+2.5;
playerbombs-=1;
}
if(
playerdir=3){
play put.wav;putnpc custombombimg.png,custombomb.txt,playerx+2.5,playery+1;
playerbombs-=1;

Or whatever. The problem is, I've had -no- luck translating this to use putnpc2


I started with rescripting it online in GS2. Though as I kept searching every available resource I could find for what I was doing wrong, and as my frustration grew, I eventually started rescripting it in GS1 (So I can get what I got in GS1, then once I have everything else set up, I could try attempting to convert it back to GS2.) Still had no luck of course.

So could anyone please explain to me the correct format of putnpc2?
(I.e. the format for putnpc (in GS1) is: putnpc image.png, script.txt, x, y; )
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 05-24-2009, 04:11 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
You should really indent your code, it helps us (and you) read the script easier,.

Basically the GS2 equivalent is:

PHP Code:
function onWeaponFired()
{

  
play("put.wav");
  
player.bombs--;

  if (
player.dir == 0) {
    
temp.putnpc2(player.0.5player.1"");
    
temp.i.join("classname");
  }
  else if (
player.dir == 1) {
    
temp.putnpc2(player.1.5player.1"");
    
temp.i.join("classname");
  }
  else if (
player.dir == 2) {
    
temp.putnpc2(player.0.5player.2.5"");
    
temp.i.join("classname");
  }
  else if (
player.dir == 3) {
    
temp.putnpc2(player.2.5player.1"");
    
temp.i.join("classname");
  }


Now all you have to do is add the script for the bomb inside the class from the .txt file.

Also, it should be:
serverwarp(this.selectedserverconnect);
Reply With Quote
  #3  
Old 05-24-2009, 04:15 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Stryke is correct, but I would do something like

PHP Code:
temp.npc putnpc2(player.1.5 vecx(player.dir) * 2player.vecy(player.dir) * 2"");
npc.join("classname"); 
though you'd have to play with the coordinates.

As far as the script, you create a new class called 'classname' or whatever you specify it as in the other script, and put in your script as (for example)

PHP Code:
function onCreated() {
  
setimg("bomb.png");
  
  for (
temp.30--) {
    
sleep(1);
  }
  
  
putexplosion(2this.xthis.y);
  
destroy();

When you use putnpc2, you create a new NPC. I'll explain the rest in comments.

PHP Code:
putnpc2(3232""); // third param is the script, you can also do
putnpc2(3232"this.x = 10;"); // or any other script you want, but it's really annoying to script like that, and is considered bad practice.

// normally, you should join a class; there are a few ways to do this.
putnpc2(3232"join classname;"); // this isn't preferred since it's using GS1

  // the following class joining examples are all GS2
  
putnpc2(3232"join(\"classname\");"); // notice the confusing escape slashes; the other ones are much easier.
  
  // or ...
  
with (putnpc2(3232"")) {
    
join("classname");
  }
  
  
// or ...
  
  
temp.npc putnpc(3232"");
  
npc.join("classname"); // I prefer this way, because it keeps the stuff in scope, which means you can do
  
npc.dropper player.account// this

  
// Since NPCs are objects, you can access them from the laying script.

echo(npc.x); // would echo 32
echo("Chat:" SPC npc.chat); // would echo "Chat:" because there is no chat. If there was chat, it would be "Chat: Hello, world!" or whatever the chat is

// you can also perform functions on the npc or call events
npc.warpto("level.name"3029);
npc.chat "Hello, world!";
npc.trigger("Test"); // calls the event "onTest()" in the script.
npc.destroy(); // removes the NPC; make sure to do this when done with it, or within the class (which is preferred) 
__________________

Last edited by cbk1994; 05-24-2009 at 04:22 AM.. Reason: explaining putnpc2 better
Reply With Quote
  #4  
Old 05-24-2009, 04:20 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Why do:
for (temp.i = 3; i > 0; i --) {
sleep(1);
}

instead of just doing sleep(3)?
Reply With Quote
  #5  
Old 05-24-2009, 04:44 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by DustyPorViva View Post
Why do:
for (temp.i = 3; i > 0; i --) {
sleep(1);
}

instead of just doing sleep(3)?
Probably just left out a countdown (this.chat = temp.i)
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #6  
Old 05-24-2009, 05:02 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Thanks you guys. I'll try that out.

Quote:
Originally Posted by DustyPorViva View Post
Why do:
for (temp.i = 3; i > 0; i --) {
sleep(1);
}

instead of just doing sleep(3)?
Isn't the for (temp.i = 3; i > 0; i --) {} thing an array? (correct me if i'm wrong but i think thats what its called)
I've seen these alot. and apparently it can be very useful in certain script.
Could someone explain how this works? Its always seemed very confusing to me. reading how "for" works in the offline editor helps a little, but what's it checking? and what exactly is that script doing?

i would guess it's checking if temp.i = 3. or is it setting it to 3? then telling it it's greater than 0 then subtracting 1?

or, by looking at Dusty's comment, is it producing three one second sleeps?
then once temp.i == 0, it tells it to stop telling it to sleep.. or something?

and where's it pulling the initial value for temp.i from anyway?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 05-24-2009, 05:59 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
Why do:
for (temp.i = 3; i > 0; i --) {
sleep(1);
}

instead of just doing sleep(3)?
You're right, I did mean to add a count-down, but I wasn't thinking.
Quote:
Originally Posted by Jiroxys7 View Post
Isn't the for (temp.i = 3; i > 0; i --) {} thing an array? (correct me if i'm wrong but i think thats what its called)
It's called a for loop.
Quote:
I've seen these alot. and apparently it can be very useful in certain script.
Could someone explain how this works? Its always seemed very confusing to me. reading how "for" works in the offline editor helps a little, but what's it checking? and what exactly is that script doing?

i would guess it's checking if temp.i = 3. or is it setting it to 3? then telling it it's greater than 0 then subtracting 1?

or, by looking at Dusty's comment, is it producing three one second sleeps?
then once temp.i == 0, it tells it to stop telling it to sleep.. or something?

and where's it pulling the initial value for temp.i from anyway?
Let's say you have something like
PHP Code:
for (temp.010++) {
  echo(
i);
  
sleep(1);

It's going to output this in RC, with a one second delay between each number.
Quote:
0
1
2
3
4
5
6
7
8
9
What it does is loop through something a certain number of times.

PHP Code:
function countTo(numberdelay) {
  for (
temp.0number++) {
    echo(
i);
    
sleep(delay);
  }

would let you count to any number.

PHP Code:
temp.0;

for (
temp.05++) {
  
+= int(random(15));
  
sleep(0.5);

Here's what this would be doing in English.

Quote:
SET v TO 0
START FOR LOOP
SET n TO 0
SET v to 2
SLEEP .5 SECONDS
SET n TO 1
SET v to 3
SLEEP .5 SECONDS
SET n to 2
SET v to 6
SLEEP .5 SECONDS

[and all the way to 4]
Here's the basic structure.

PHP Code:
for (variable startvariable (inequalitymax/minvariable change) {
  
// code to be executed

so

PHP Code:
for (temp.30--) {
  echo(
x);

would say that x starts at 3. It would then execute the code in the middle by outputting '3'. Then, x is decreased to 2. It checks if 2 is more than 0, which it is, so it keeps going and executes the code. x now equals 1, which is more than 0, so it goes again. x now equals 0, which is not more than 0, so it breaks out of the for loop.


Another, different type of for loop is like a foreach loop in other languages. It's done like this:

PHP Code:
for (variable : array) {
  echo(
variable);

Arrays are defined like this

PHP Code:
temp.array = {"one""two""three""hello""world"}; 
which means you can also do

PHP Code:
for (variable : {"one""two""three""hello""world"}) {
  echo(
variable);

however, you need to specify a variable

PHP Code:
for (temp.number : array) {
  echo(
number);

would output

Quote:
one
two
three
hello
world
Be sure not to get the two types of for loops mixed up. The for each loop does the same thing as

PHP Code:
temp.array = {"one""two""three""hello""world"};

for (
temp.0< array.size(); ++) {
  
temp.variable = array[i];

heh, long post
__________________
Reply With Quote
  #8  
Old 05-24-2009, 08:24 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Ah, I understand it now! Much thanks for the explaination Chris

Edit:
Okay, as for the putnpc2 thing, i'm still having trouble.
I got:

PHP Code:
function onWeaponFired() 
{
if(
player.bombs>0){ 

  
play("put.wav"); 
  
player.bombs--; 

  if (
player.dir == 0) { 
    
with(putnpc2(player.0.5player.1"")){
    
join("firebomb"); 
   }
  }
  else if (
player.dir == 1) { 
    
with(putnpc2(player.1.5player.1"")){
    
join("firebomb"); 
   }
  } 
  else if (
player.dir == 2) { 
    
with(putnpc2(player.0.5player.2.5"")){
    
join("firebomb"); 
   }
  } 
  else if (
player.dir == 3) { 
    
with(putnpc2(player.2.5player.1"")){
    
join("firebomb"); 
   }
  } 

 }

Since using the other way didnt work. Clientsiding only plays the wav, and nonclientsiding won't trigger the onWeaponfired function.
So i'm still stuck in the same place
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #9  
Old 05-24-2009, 08:42 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
onWeaponFired() and play() are both clientside functions.

PHP Code:
function onActionServerSide(cmd) {
  if (
cmd == "dropFireBomb") {
    
player.bombs --;
    
    
// you can add back your long list here if you want
    
temp.npc putnpc2(player.1.5 vecx(player.dir) * 2player.vecy(player.dir) * 2"");
    
npc.join("firebomb");  
  }
}
//#CLIENTSIDE
function onWeaponFired() {
  if (
player.bombs <= 0) {
    return;
  }
  
  
triggerserver("gui"name"dropFireBomb");
  
play("put.wav");
  
freezeplayer(1);

__________________
Reply With Quote
  #10  
Old 05-24-2009, 08:03 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
awesome, it works now

quick question though. that's the purpose of the "gui" in triggerserver?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #11  
Old 05-24-2009, 09:06 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Jiroxys7 View Post
awesome, it works now

quick question though. that's the purpose of the "gui" in triggerserver?
It specifies that you're triggering a Weapon/GUI-Script. You can also use "weapon", but "gui" is shorter.

"npc" is the other form that is used, and that is to trigger DB NPCs.
__________________
Reply With Quote
  #12  
Old 05-24-2009, 11:49 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
alright. and yet another question if i might add, I fixed one of my other weapons. When fired, it creates an npc char that moves across the screen shooting arrows. then, once it has moved a certain amount, it calls its movement finished thing, then is told to destroy(); itself. The problem is, after that,if i use the update level command or reconnect, the npc will reappear. like it never actually got deleted. Do i need to destroy(); serverside or something?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #13  
Old 05-25-2009, 12:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Jiroxys7 View Post
alright. and yet another question if i might add, I fixed one of my other weapons. When fired, it creates an npc char that moves across the screen shooting arrows. then, once it has moved a certain amount, it calls its movement finished thing, then is told to destroy(); itself. The problem is, after that,if i use the update level command or reconnect, the npc will reappear. like it never actually got deleted. Do i need to destroy(); serverside or something?
Can you post the code that is placing the NPC?
__________________
Reply With Quote
  #14  
Old 05-25-2009, 12:57 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Jiroxys7 View Post
Do i need to destroy(); serverside or something?
Yup. If you don't destroy() it serverside, then it won't get removed from the level.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #15  
Old 05-25-2009, 01:05 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by napo_p2p View Post
Yup. If you don't destroy() it serverside, then it won't get removed from the level.
That's correct. You can use triggeraction to trigger the location the NPC is at (or started at if you're moving clientside).

Sorry I didn't see that, I think you edited your post.

EDIT: Nevermind, you didn't edit it, I quoted you.
__________________
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:39 PM.


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