Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-09-2010, 10:31 PM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #2  
Old 02-09-2010, 11:11 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
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.
Reply With Quote
  #3  
Old 02-10-2010, 12:31 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #4  
Old 02-10-2010, 12:35 AM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by Engine View Post
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.
Reply With Quote
  #5  
Old 02-10-2010, 12:37 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
Quote:
Originally Posted by Immolate View Post
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.
Reply With Quote
  #6  
Old 02-10-2010, 12:39 AM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by Engine View Post
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 ==
Reply With Quote
  #7  
Old 02-10-2010, 12:41 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
For this?
PHP Code:
players.attr[20] = null
Reply With Quote
  #8  
Old 02-10-2010, 12:41 AM
tempandrew tempandrew is offline
Registered User
Join Date: May 2005
Posts: 98
tempandrew is on a distinguished road
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)
Reply With Quote
  #9  
Old 02-10-2010, 12:44 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #10  
Old 02-10-2010, 12:48 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #11  
Old 02-10-2010, 12:49 AM
tempandrew tempandrew is offline
Registered User
Join Date: May 2005
Posts: 98
tempandrew is on a distinguished road
Quote:
Originally Posted by Engine View Post
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.
Reply With Quote
  #12  
Old 02-10-2010, 12:56 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
Quote:
Originally Posted by tempandrew View Post
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.
Reply With Quote
  #13  
Old 02-10-2010, 01:01 AM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by tempandrew View Post
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);
Reply With Quote
  #14  
Old 02-10-2010, 04:10 AM
tempandrew tempandrew is offline
Registered User
Join Date: May 2005
Posts: 98
tempandrew is on a distinguished road
Quote:
Originally Posted by DrakilorP2P View Post
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().
Reply With Quote
  #15  
Old 02-11-2010, 04:29 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by tempandrew View Post
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.
__________________
Skyld
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:33 AM.


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