Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPC Troubles :( (https://forums.graalonline.com/forums/showthread.php?t=56711)

fowlplay4 12-28-2004 07:54 AM

NPC Troubles :(
 
Hello all

I am trying to make a pair of staff boots where i can set the speed but when i try to test them it turns them on but my speed does not increase nor can i walk on and through obstacles. Check it out and help pls ^^
Quote:

NPC Scriptundefined

// NPC made by Jerret
//#CLIENTSIDE

if (weaponfired) {
if (this.inuse=0) {
this.inuse=1;
timeout = 0.05;
setplayerprop #c,Boots On
} else {
this.inuse=0;
timeout = 0;
setplayerprop #c,Boots Off
}
}
if (this.inuse==1 && timeout) {
if (keydown(0)) playery -= strtofloat(this.bootspeed);
if (keydown(1)) playerx -= strtofloat(this.bootspeed);
if (keydown(2)) playery += strtofloat(this.bootspeed);
if (keydown(3)) playerx += strtofloat(this.bootspeed);
timeout = 0.05
}
if (timeout) {timeout = 0.05}
if (playerchats) {
tokenize #c;
if (tokenscount==3){
if (strequals(#t(0),/boots)&&strequals(#t(1),speed)) {
this.bootspeed = strtofloat(#t(2))
}
}
}
if (playerchats) {
if (strequals(#c,/boots on)) {
this.inuse==1;
timeout=.05;
}
if (strequals(#c,/boots off)) {
this.inuse==0;
}}

falco10291029 12-28-2004 08:21 AM

get rid of the strtofloat() around the this.bootspeed, it's a variable, not a string.

ZeroTrack 12-28-2004 08:40 AM

frist of yes get rid of those strtofloats, second get rid of that pointless timeout , thrid u need to set the var first , nothing is setting the var when the script is active, with all the corrections is should look like this
PHP Code:

//#CLIENTSIDE
if (weaponfired) {
  if (
this.inuse=0) {
    
this.inuse=1;
    
timeout 0.05;
    
this.bootspeed=1;
    
setplayerprop #c,Boots On;
  
} else {
    
this.inuse=0;
    
setplayerprop #c,Boots Off;
  
}
}
if (
this.inuse==&& timeout) {
  if (
keydown(0)) playery -= this.bootspeed;
  if (
keydown(1)) playerx -= this.bootspeed;
  if (
keydown(2)) playery += this.bootspeed;
  if (
keydown(3)) playerx += this.bootspeed;
  
timeout 0.05;
}
if (
playerchats) {
  
tokenize #c;
  
if (tokenscount==3){
    if (
strequals(#t(0),/boots)&&strequals(#t(1),speed)) {
      
this.bootspeed strtofloat(#t(2));
    
}
  }
}
if (
playerchats) {
  if (
strequals(#c,/boots on)) {
    
this.inuse==1;
    
timeout=.05;
  }
  if (
strequals(#c,/boots off)) {
    
this.inuse==0;
  }



fowlplay4 12-28-2004 08:49 AM

Thank you :)

Kaimetsu 12-28-2004 09:42 AM

KSI-GS!

Velox Cruentus 01-01-2005 02:39 PM

This is a slightly more complex way to do that. It shows a lot more techniques of manupilating strings/variables. Either way works just fine.

NPC Code:

//#CLIENTSIDE
if (created) this.speed = 0.5;
if (weaponfired) {
this.inuse = ( this.inuse + 1 ) % 2;
tokenize Off On;
setplayerprop #c,Boots #t(this.inuse);
timeout = 0.05;
}
if (timeout && this.inuse == 1){
this.x = (keydown(3) - keydown(1));
this.y = (keydown(2) - keydown(0));
playerx += this.x * this.speed;
playery += this.y * this.speed;
timeout = 0.05;
}
if (playerchats){
if (strequals(#e(0,6,#c),/boots)){
tokenize #c;
setstring this.list,off,on;
if (strtofloat(#t(1)) > 0){
this.speed = strtofloat(#t(1));
} else if (lindexof(#t(1),this.list) > -1){
this.inuse = lindexof(#t(1),this.list);
timeout = 0.05;
}
}
}


Sildae 01-04-2005 10:49 PM

I am not really good with gscript, and I have not used it for years, so I have a few questions. I have made a few changes to your code, could you explain to me why you did not write it that way?
Quote:

Originally Posted by Velox Cruentus
NPC Code:

//#CLIENTSIDE
if (created)
this.speed = 0.5;

if (weaponfired) {
timeout = 0.05 - timeout;
tokenize Off On;
setplayerprop #c,Boots #t(timeout * 20);
}

if (timeout) {
for (direction = 0; direction < 4; direction ++) {
playerx += keydown(direction) * vecx(direction) * this.speed;
playery += keydown(direction) * vecy(direction) * this.speed;
}
timeout = 0.05;
}

if (playerchats) {
if (startswith(/boots, #c)) {
newSpeed = strtofloat(#e(7,-1,#c));
if (newSpeed > 0) {
this.speed = newSpeed;
} else {
index = indexof(#e(7,-1,#c), off on);
if (index in {0, 4})
timeout = 0.05 * (index / 4);
}

}
}



Evil_Trunks 01-04-2005 10:56 PM

your version of his script appears to be just as good

I would have used vecx and vecy myself, if I was making this. His version of that part seems to be more efficient though.

I would say the biggest difference between the way you coded it, and the way he coded it, is that when I read his, I can understand what each line does easier. It took me a little longer to understand why you used certain things the way you did.

Edit: many things edited in this post

Velox Cruentus 01-05-2005 01:30 AM

Well, first off, it's a lot more effiecient:
PHP Code:

this.= (keydown(3) - keydown(1));
this.= (keydown(2) - keydown(0));
playerx += this.this.speed;
playery += this.this.speed

PHP Code:

for (direction 0direction 4direction ++) {
  
playerx += keydown(direction) * vecx(direction) * this.speed;
  
playery += keydown(direction) * vecy(direction) * this.speed;


Basically here, you're saying "Go by there! Then by here! ... ...", where they can cancel out... 5 right + 5 left = 0 movement. Thus, if you press the right and left movement, you would't move at all... It would prevent calculating one side, then calculating the next.

Other then that, the rest doesn't change much at all...Other then you declared a variable where I didn't. And I used tokenize. Differant ways to proceed.


All times are GMT +2. The time now is 08:35 PM.

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