Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   My ungodly amount of questions thread. (https://forums.graalonline.com/forums/showthread.php?t=134257954)

Engine 02-09-2010 10:31 PM

My ungodly amount of questions thread.
 
Instead of creating a new thread for every possible problem I come across, I have decided that it would be a better idea just to keep all my questions in one thread.

Right now I'm currently attempting to make it so every time I press 'f' fire comes out in the direction the player is facing and then disappears 2 seconds later. I cannot figure out why it's not working correctly. Can anyone try to walk me through what I'm doing wrong?


Weapon
PHP Code:

//#CLIENTSIDE
function onKeyPressed() {
  if(
params[1] = "f"){
    
player.attr[12] = "enginetest7.gani";
    
scheduleevent("2","ClearFire""");
 }
}
function 
onClearFire(){
player.attr[12] = NULL;
findimg(200).destroy();



Gani
PHP Code:

//#CLIENTSIDE
function onCreated(){

  
with(findimg(200){
    
emitter.delaymin 0.01;
    
emitter.delaymax 0.01;
    
emitter.nrofparticles 1;
    
emitter.particle.image "g4_animation_fire.gif";
    
emitter.particle.alpha 0.99;
    
emitter.particle.lifetime 0.5;
    
emitter.particle.speed 10;
    
emitter.particle.spin 2;
    
emitter.particle.red 1;
    
emitter.particle.green .4;
    
emitter.particle.blue .4;
  }
  
this.showtime=timevar2 2;
  
setTimer(0.05);
}

function 
onTimeout(){
  
showimg(200);
  if(
this.showtime >timevar2){
    
this.fireangles= {-4.7,-3.1,-1.6,0};
    
=player.x;
    
player.y;
    for(
i=0;i<4;i++){
      if(
player.dir=i){
      
findimg(200).emitter.particle.angle this.fireangles[i]+random(-.5,.5);
    }
  }
  
setTimer(0.05);
  } 


Edit: I removed //#CLIENTSIDE from the gani, I assume I don't need it twice. I forgot I had it in there from when I was testing it as a class.

DrakilorP2P 02-09-2010 11:11 PM

Not sure about the weapon script, but I found some errors in the gani script after trying a few things.

PHP Code:

//onCreated doesn't seem to work when you're putting ganis in player.attr[].
function onPlayerEnters() {
  
with (findimg(200)) { //There was a missing parenthesis here.
    
attachtoowner true//Follow the player.
    
emitter.delaymin 0.01;
    
emitter.delaymax 0.01;
    
emitter.nrofparticles 1;
    
emitter.particle.image "g4_animation_fire.gif";
    
emitter.particle.alpha 0.99;
    
emitter.particle.lifetime 0.5;
    
emitter.particle.speed 10;
    
emitter.particle.spin 2;
    
emitter.particle.red 1;
    
emitter.particle.green .4;
    
emitter.particle.blue .4;
  }

  
this.showtime=timevar2 2;
  
setTimer(0.05);
}

function 
onTimeout() {
  
//showimg(200); //What?
  
  
if(this.showtime timevar2) {
    
this.fireangles= {-4.7,-3.1,-1.6,0};
    
    
//Doesn't do anything I think.
    //x = player.x;
    //y = player.y;
    
    //Shorter version of the below.
    
findimg(200).emitter.particle.angle this.fireangles[player.dir]+random(-.5,.5);

    
/*for(i=0;i<4;i++) {
      if(player.dir == i) {
      findimg(200).emitter.particle.angle = this.fireangles[i]+random(-.5,.5);
    }*/
  
}
  
  
setTimer(0.05);
  
  
//} //Extra bracket?


Not sure why you're making it stop updating after 2 seconds, since onClearFire seems to be doing that just fine.

Engine 02-10-2010 12:31 AM

Alright, I tired what you did and it didn't work so then I copied what you did and didn't work. I even removed all the unneccesary things in it that you said I didn't need and still nothing. I think it might have to do with the weapon npc. Here's the simplest thing I could think of to do, yet it still doesn't want to work.
Weapon
PHP Code:

//#CLIENTSIDE
function onKeyPressed() {
if(
params[1] = "f"){
  
player.attr[20] = "enginetest11.gani";
  
scheduleevent("1","ClearFire"0);
}
function 
onClearFire(){
  
player.attr[20] = NULL;
  
hideimg(200);
  
findimg(200).destroy();


Gani
PHP Code:


SCRIPT
function onCreated() {
  
with(findimg(200)){
    
this.player.x;
    
this.player.y;
    
emitter.nrofparticles 1;
    
emitter.particle.image "block.png";
  }
}
SCRIPTEND 

This will put the particle effect down once but will not destroy it or let me remove the current one and move it to my current location when i press 'f'. I'm sure that it's something simple and I'm just to autistic to realize it.

Immolate 02-10-2010 12:35 AM

Quote:

Originally Posted by Engine (Post 1555210)
Alright, I tired what you did and it didn't work so then I copied what you did and didn't work. I even removed all the unneccesary things in it that you said I didn't need and still nothing. I think it might have to do with the weapon npc. Here's the simplest thing I could think of to do, yet it still doesn't want to work.
Weapon
PHP Code:

//#CLIENTSIDE
function onKeyPressed() {
if(
params[1] = "f"){
  
player.attr[20] = "enginetest11.gani";
  
scheduleevent("1","ClearFire"0);
}
function 
onClearFire(){
  
player.attr[20] = NULL;
  
hideimg(200);
  
findimg(200).destroy();


Gani
PHP Code:


SCRIPT
function onCreated() {
  
with(findimg(200)){
    
this.player.x;
    
this.player.y;
    
emitter.nrofparticles 1;
    
emitter.particle.image "block.png";
  }
}
SCRIPTEND 

This will put the particle effect down once but will not destroy it or let me remove the current one and move it to my current location when i press 'f'. I'm sure that it's something simple and I'm just to autistic to realize it.

You're missing a closing brace at the end of the onKeyPressed event.

Engine 02-10-2010 12:37 AM

Quote:

Originally Posted by Immolate (Post 1555212)
You're missing a closing brace at the end of the onKeyPressed event.

Oh yeah, it was there I accidentally backspaced when typing php brackets.

Immolate 02-10-2010 12:39 AM

Quote:

Originally Posted by Engine (Post 1555213)
Oh yeah, it was there I accidentally backspaced when typing php brackets.

Didn't notice this before but you're using the assignmen operator instead of the equals operator.

= should be ==

Engine 02-10-2010 12:41 AM

For this?
PHP Code:

players.attr[20] = null


tempandrew 02-10-2010 12:41 AM

PHP Code:

//#CLIENTSIDE
function onKeyPressed() {
if(
params[1] = "f"){
  
player.attr[20] = "enginetest11.gani";
  
scheduleevent("1","ClearFire"0);
}
function 
onClearFire(){
  
player.attr[20] = NULL;
  
hideimg(200);
  
findimg(200).destroy();


Shouldn't the function be named "function ClearFire() {}" ?

EDIT: You're also missing a closing bracket in the first part. I think it should be...

PHP Code:

//#CLIENTSIDE
function onKeyPressed(codekey) {
  if (
lowercase(key) == "f") {
    
player.attr[20] = "enginetest11.gani";
    
scheduleevent("1","ClearFire"0);
  }
}

function 
ClearFire() {
  
player.attr[20] = NULL;
  
hideimg(200);
  
findimg(200).destroy();


(USE BETTER STYLING >=O)

Engine 02-10-2010 12:44 AM

Negitivo, or atleast I assume it shouldn't be. I can still call that function with scheduleevent(); with it being "function onClearFire();" maybe I'm mistaken.

Engine 02-10-2010 12:48 AM

Alright I figured it out I did
PHP Code:

player.attr[20] = "0"// instead of NULL 

I guess putting NULL as the value of a variable doesn't clear whatever data it currently has in it.

tempandrew 02-10-2010 12:49 AM

Quote:

Originally Posted by Engine (Post 1555220)
Negitivo, or atleast I assume it shouldn't be. I can still call that function with scheduleevent(); with it being "function onClearFire();" maybe I'm mistaken.

My mistake, I tested it and it called onClearFire().

Weird, I don't use scheduleevent but it's strange that differs from basically every other command that calls an event.

Engine 02-10-2010 12:56 AM

Quote:

Originally Posted by tempandrew (Post 1555224)
My mistake, I tested it and it called onClearFire().

Weird, I don't use scheduleevent but it's strange that differs from basically every other command that calls an event.

I use it as an alternative to sleep's and timeout's, but now I have a strange problem haha. This thing only wants to work when ScriptedRC NPC Editor is opened. If I minimize it or close it the npc no longer wants to put 'enginetest11.gani' on the level anymore but it still sets it as the player.attr[20].

Edit: I figured out the problem, I had the schedulevent time set at 0.5 and since I lag hard on vista and even harder with all that text I lagged enough to actually see it.

DrakilorP2P 02-10-2010 01:01 AM

Quote:

Originally Posted by tempandrew (Post 1555224)
My mistake, I tested it and it called onClearFire().

Weird, I don't use scheduleevent but it's strange that differs from basically every other command that calls an event.

All event functions must be named onSomething. scheduleEvent() and trigger() both allow you to skip the 'on' part so you can type trigger("Something", null);

tempandrew 02-10-2010 04:10 AM

Quote:

Originally Posted by DrakilorP2P (Post 1555230)
All event functions must be named onSomething. scheduleEvent() and trigger() both allow you to skip the 'on' part so you can type trigger("Something", null);

I know, my point is that if you go Function(), you don't call it with onFuntion().

Skyld 02-11-2010 04:29 AM

Quote:

Originally Posted by tempandrew (Post 1555270)
I know, my point is that if you go Function(), you don't call it with onFuntion().

With scheduleevent and such, if you omit the "on", it adds it for you so that the rule where events start with "on" are enforced. With traditional function calls like Foo(), the same does not apply because the function object is referenced directly by it's name.


All times are GMT +2. The time now is 03:06 PM.

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