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 12-28-2001, 10:28 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Help the newbie scripter?

Hi, I need some help, I'm trying to make an NPC weapon that when you hold down a button then it does something, but I'm stuck, can push me off a cliff that's in the right direction please? here's what I have so far, for the example I made it put leaps at the player's X and Y

---------------------------------------------------------------------------------

// NPC made by Shadowless Warrior
if (playerenters) {
}
if (playertouchsme) {toweapons automatic test;

}

if (keydown(6)) {timeout=0.5;}
else {timeout=0;}

if (timeout) {putleaps 0,playerx,playery;timeout=0.5;}

simple I know, but scripting confuses me...
Reply With Quote
  #2  
Old 12-28-2001, 10:30 AM
AlexH AlexH is offline
Have A Drink On Me
AlexH's Avatar
Join Date: Jun 2001
Location: Somewhere In Time
Posts: 7,442
AlexH is on a distinguished road
Send a message via AIM to AlexH Send a message via MSN to AlexH
if (keydown(whatever)) {
whatever you want it to do
}
__________________
QUICK LOOK BUSY JESUS IS COMING!
Reply With Quote
  #3  
Old 12-28-2001, 11:06 AM
Falcor Falcor is offline
Darth Cucumber
Falcor's Avatar
Join Date: Mar 2001
Location: At School
Posts: 2,874
Falcor is on a distinguished road
Send a message via ICQ to Falcor Send a message via AIM to Falcor Send a message via MSN to Falcor Send a message via Yahoo to Falcor
keydown must be in a timeout loop (For some strange reason.. I think it should be called just like playerchats is called but who am I to say)
__________________

subliminal message: 1+1=3
Reply With Quote
  #4  
Old 12-28-2001, 11:13 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Quote:
Originally posted by Falcor
keydown must be in a timeout loop (For some strange reason.. I think it should be called just like playerchats is called but who am I to say)

Kinda like this?

-------------------------------------------------------
// NPC made by Shadowless Warrior

if (playerenters) {
toweapons automatic test;
}
if (isweapon) {
timeout=0.5;
}
if (timeout) {
if (keydown(6)) {
putleaps 0,playerx,playery;
}
timeout=0.5;
}

-------------------------------------------

this wont do anything though...
Reply With Quote
  #5  
Old 12-28-2001, 11:32 AM
kittygirl765 kittygirl765 is offline
tapatapatapa
kittygirl765's Avatar
Join Date: Dec 2001
Location: Caught in a tree
Posts: 70
kittygirl765 is on a distinguished road
Send a message via ICQ to kittygirl765
Quote:
Originally posted by haunter



Kinda like this?

-------------------------------------------------------
// NPC made by Shadowless Warrior

if (playerenters) {
toweapons automatic test;
}
if (isweapon) {
timeout=0.5;
}
if (timeout) {
if (keydown(6)) {
putleaps 0,playerx,playery;
}
timeout=0.5;
}

-------------------------------------------

this wont do anything though...
try making timeout equal to 0.05 =)
__________________
I <3 UN
I <3 Shadow Strip Entertainment City Shangri-La
I <3 gscript2
Reply With Quote
  #6  
Old 12-28-2001, 12:43 PM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Quote:
Originally posted by kittygirl765


try making timeout equal to 0.05 =)
it doesn't matter is it's .05 or .5, it's not much of a difference
Reply With Quote
  #7  
Old 12-28-2001, 10:43 PM
Androk2k1 Androk2k1 is offline
Banned
Androk2k1's Avatar
Join Date: Dec 2001
Posts: 1,336
Androk2k1 is on a distinguished road
Try This:

--- Code Start ---
// NPC made by Shadowless Warrior

if (playerenters) {
toweapons Test;
}
if (keydown(6)) {
while (keydown(6)) {
putleaps 0,playerx,playery;
sleep .5;
}
}
Reply With Quote
  #8  
Old 12-28-2001, 10:53 PM
kittygirl765 kittygirl765 is offline
tapatapatapa
kittygirl765's Avatar
Join Date: Dec 2001
Location: Caught in a tree
Posts: 70
kittygirl765 is on a distinguished road
Send a message via ICQ to kittygirl765
Quote:
Originally posted by Python523

it doesn't matter is it's .05 or .5, it's not much of a difference
It doesn't seem like a big difference, but it really is b/c changing the timeout from 500 ms to 50 ms is, liek, 10 times faster in scanning the keydown =)
__________________
I <3 UN
I <3 Shadow Strip Entertainment City Shangri-La
I <3 gscript2
Reply With Quote
  #9  
Old 12-29-2001, 12:41 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
0o0o00o k, thanx everyone! I shall try these things now!
Reply With Quote
  #10  
Old 12-29-2001, 12:44 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Hmmm... nope, none of those worked... =(
Reply With Quote
  #11  
Old 12-29-2001, 12:49 AM
kittygirl765 kittygirl765 is offline
tapatapatapa
kittygirl765's Avatar
Join Date: Dec 2001
Location: Caught in a tree
Posts: 70
kittygirl765 is on a distinguished road
Send a message via ICQ to kittygirl765
All these scripts work perfectly for me =)

Ohh, remember that keydown(6) is the 'A', or lift key =)
__________________
I <3 UN
I <3 Shadow Strip Entertainment City Shangri-La
I <3 gscript2
Reply With Quote
  #12  
Old 12-29-2001, 02:56 AM
GrowlZP2P GrowlZP2P is offline
Registered User
Join Date: Dec 2001
Location: Corpadverticus, which in case you don't know is the recently-formed and Blockbuster Video-sponsored Tenth Circle of Hell
Posts: 57
GrowlZP2P is on a distinguished road
Send a message via AIM to GrowlZP2P Send a message via Yahoo to GrowlZP2P
I find keydowns work best in a while loop. This example is commented through for you:

if (playerenters){
// Sets image to shoes.gif
setimg shoes.gif;
}
if (playertouchsme){
// Adds weapon to player weapons
toweapons Skip Wall Boots;
}
if (weaponfired && !working){
sleep 0.05;
set working;
// Sets flag to make system work.
// For some strange reason Graal
// requires a sleep command if
// you're turning flags on and off.
}
if (weaponfired && working){
sleep 0.05;
unset working;
// Unsets flag; disables NPC
}
while (working){
// Oh boy, long bit... if a movement key
// is pressed, the player moves faster
// than normal and can walk through
// walls.
if (keydown(0)){
players[0].y=players[0].y-1;
}
if (keydown(1)){
players[0].x=players[0].x-1;
}
if (keydown(2)){
players[0].y=players[0].y+1;
}
if (keydown(3)){
players[0].x=players[0].x+1;
}
sleep 0.05;
// To keep the loop stable and running,
// a sleep 0.05 or sleep 0.1 should always
// be added at the end of any while
// statement
}

Just as a little background here, remember the longest a Graal script can reasonably pause for is 0.05 of a second, or 1/20 of a second. Smaller increments force the while loop to do 10,000 operations in roughly .1 of a second, slowing down your Graal program and also freezing the script, as while-s without a sleep command can only run 10,000 times.

Or here's your NPC back edited accordingly:

if (playerenters) {
setimg shoes.gif;
// or you can replace this with whatever image
// you want it to be
}
if (playertouchsme) {toweapons automatic test;
}
while (isweapon){
if (keydown(6)){
putleaps 0,playerx,playery;timeout=0.5;
}
sleep 0.05;
}

Your NPC will now put grass explosions at your player's co-ordinates while the player has the weapon and while the key for lifting items is pressed. See?
__________________


AIM: GrowlZ1010 | Y! IM: GrowlZ1010 | MSN: [email protected] | Email: [email protected]

- I use obscenely long words to befuddle my adversaries, therefore I am -

Current Favorite Quote: Real programmers don't document. If it was hard to write, it should be hard
to understand.
Reply With Quote
  #13  
Old 12-29-2001, 03:38 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Quote:
Originally posted by kittygirl765
All these scripts work perfectly for me =)

Ohh, remember that keydown(6) is the 'A', or lift key =)
i thought 6 was D
Reply With Quote
  #14  
Old 12-29-2001, 03:41 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
K, Thanks pixie Lady, and everyone else, that was the problem.... i was pressing the wronf button... -_- now, i want it just to work when its in the display unnder the current D weapon, would i put

if (keydown && playerprop #w, weaponname) {do blah blah;}

??
Reply With Quote
  #15  
Old 12-29-2001, 03:50 AM
GrowlZP2P GrowlZP2P is offline
Registered User
Join Date: Dec 2001
Location: Corpadverticus, which in case you don't know is the recently-formed and Blockbuster Video-sponsored Tenth Circle of Hell
Posts: 57
GrowlZP2P is on a distinguished road
Send a message via AIM to GrowlZP2P Send a message via Yahoo to GrowlZP2P
Aww, you didn't regard my huge walkthrough?

if (playerenters) {
}
if (playertouchsme) {toweapons automatic test;
}
while (strequals(#w,automatic test) && isweapon){
if (keydown(4)){
putleaps 0,playerx,playery;
}
sleep 0.05;
}

Should work..

(EDIT: The timeout statement was no longer needed with the addition of the while. If that makes any sense. )
__________________


AIM: GrowlZ1010 | Y! IM: GrowlZ1010 | MSN: [email protected] | Email: [email protected]

- I use obscenely long words to befuddle my adversaries, therefore I am -

Current Favorite Quote: Real programmers don't document. If it was hard to write, it should be hard
to understand.
Reply With Quote
  #16  
Old 12-29-2001, 03:57 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Quote:
Originally posted by GrowlZP2P
Aww, you didn't regard my huge walkthrough?

if (playerenters) {
}
if (playertouchsme) {toweapons automatic test;
}
while (strequals(#w,automatic test) && isweapon){
if (keydown(4)){
putleaps 0,playerx,playery;timeout=0.5;
}
sleep 0.05;
}

Should work..
0o0oo ok thanx, i was think playerprop not strequals...
Reply With Quote
  #17  
Old 12-29-2001, 04:00 AM
GrowlZP2P GrowlZP2P is offline
Registered User
Join Date: Dec 2001
Location: Corpadverticus, which in case you don't know is the recently-formed and Blockbuster Video-sponsored Tenth Circle of Hell
Posts: 57
GrowlZP2P is on a distinguished road
Send a message via AIM to GrowlZP2P Send a message via Yahoo to GrowlZP2P
Think strequals.®

Oh, btw, that script you have there is a bit.. crud.. you can take out the timeout section, it's not needed. Just keep the sleep bit.
__________________


AIM: GrowlZ1010 | Y! IM: GrowlZ1010 | MSN: [email protected] | Email: [email protected]

- I use obscenely long words to befuddle my adversaries, therefore I am -

Current Favorite Quote: Real programmers don't document. If it was hard to write, it should be hard
to understand.
Reply With Quote
  #18  
Old 12-29-2001, 04:47 AM
haunter haunter is offline
Registered User
haunter's Avatar
Join Date: Mar 2001
Posts: 7,989
haunter is on a distinguished road
Quote:
Originally posted by GrowlZP2P
Think strequals.®

Oh, btw, that script you have there is a bit.. crud.. you can take out the timeout section, it's not needed. Just keep the sleep bit.
Yeah i was wondering why u put a timeout there... thanx everyone i learned sum stuff >;D
Reply With Quote
  #19  
Old 12-30-2001, 08:43 AM
Faheria_GP2 Faheria_GP2 is offline
Banned
Faheria_GP2's Avatar
Join Date: Oct 2001
Posts: 1,177
Faheria_GP2 is on a distinguished road
Quote:
Originally posted by Falcor
keydown must be in a timeout loop (For some strange reason.. I think it should be called just like playerchats is called but who am I to say)
wrong! babylon has keydown() in a "playerendsreading"...

so :P @ falados
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 01:44 AM.


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