Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Help the newbie scripter? (https://forums.graalonline.com/forums/showthread.php?t=19790)

haunter 12-28-2001 10:28 AM

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

AlexH 12-28-2001 10:30 AM

if (keydown(whatever)) {
whatever you want it to do
}

Falcor 12-28-2001 11:06 AM

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)

haunter 12-28-2001 11:13 AM

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

kittygirl765 12-28-2001 11:32 AM

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 =)

Python523 12-28-2001 12:43 PM

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

Androk2k1 12-28-2001 10:43 PM

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;
}
}

kittygirl765 12-28-2001 10:53 PM

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 =)

haunter 12-29-2001 12:41 AM

0o0o00o k, thanx everyone! I shall try these things now!

haunter 12-29-2001 12:44 AM

Hmmm... nope, none of those worked... =(

kittygirl765 12-29-2001 12:49 AM

All these scripts work perfectly for me =)

Ohh, remember that keydown(6) is the 'A', or lift key =)

GrowlZP2P 12-29-2001 02:56 AM

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?

haunter 12-29-2001 03:38 AM

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

haunter 12-29-2001 03:41 AM

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;}

??

GrowlZP2P 12-29-2001 03:50 AM

Aww, you didn't regard my huge walkthrough? :D

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. :D )

haunter 12-29-2001 03:57 AM

Quote:

Originally posted by GrowlZP2P
Aww, you didn't regard my huge walkthrough? :D

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

GrowlZP2P 12-29-2001 04:00 AM

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.

haunter 12-29-2001 04:47 AM

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

Faheria_GP2 12-30-2001 08:43 AM

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


All times are GMT +2. The time now is 05:00 AM.

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