![]() |
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... |
if (keydown(whatever)) {
whatever you want it to do } |
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)
|
Quote:
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... |
Quote:
|
Quote:
|
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; } } |
Quote:
|
0o0o00o k, thanx everyone! I shall try these things now!
|
Hmmm... nope, none of those worked... =(
|
All these scripts work perfectly for me =)
Ohh, remember that keydown(6) is the 'A', or lift key =) |
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? |
Quote:
|
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;} ?? |
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 ) |
Quote:
|
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. |
Quote:
|
Quote:
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.