Graal Forums

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

Seich 06-09-2009 05:30 PM

small problem
 
Hello, recently I've been working with a weapon npc which, is supposed to show a gui bitmap button when a player enters certain levels. The problem is that, even thought I manage to display the button when I am on one of those levels, I haven't been able to remove the button when the player leaves the level. I've tried two different approaches and, none worked as expected. My first approach was to loop through an array with the levels and test if the level was in the array. My second approach was using the onPlayerEnters event and check is the player was on one of those levels. The second method worked fine, but I am unable to make it so the button disappears after the player leaves the level. any suggestions?

PHP Code:

//#CLIENTSIDE
function onCreated(){
    
this.tut_place false;
    
this.localinfo = {
        {
"Electric Workshop""noc_inside-elect.nw"},
        {
"Car Workshop""noc_inside-mech-garage.nw"},
        {
"Guns Shop""noc_inside-general-store.nw"}
    };
}

function 
onPlayerEnters(){
        if(
player.level in this.localinfo[0][1]){
            
this.tut_place true;
        }else{
            
//this.tut_place = false;
        
}
    
setTimer(.5);
}

function 
onTimeout(){
        if(
this.tut_place){
        if(!
tutorial_button.visible){
            new 
GuiBitmapButtonCtrl("tutorial_button") {
               
screenwidth 64;
               
0;
               
width 64;
               
height 64;
               
normalbitmap "noc_button.png";
               
mouseoverbitmap "noc_button-over.png";
               
pressedbitmap "noc_button-click.png";
            }
        }
    }else{
        
tutorial_button.destroy();
    }
    
setTimer(.5);



Angel_Light 06-09-2009 07:32 PM

Just a suggestion, but maybe use the visible flag since you're going to be using the same button over and over.

I remember is GS1 there was the flag 'playerleaves'. You can probably try onPlayerLeaves() and see if that works

Seich 06-09-2009 07:43 PM

Quote:

Originally Posted by Angel_Light (Post 1498159)
Just a suggestion, but maybe use the visible flag since you're going to be using the same button over and over.

I remember is GS1 there was the flag 'playerleaves'. You can probably try onPlayerLeaves() and see if that works

okay, I will try that.

edit: D: It didn't work.. apparently onPlayerLeaves() doesn't work as an event...

Pelikano 06-09-2009 07:51 PM

Well, why are you doing:

PHP Code:

if(player.level in this.localinfo[0][1]){ 

Instead of checking the whole Array?

Also when you start showing a GUI, it'll remain untill it's destroy()ed, and in this script, you're just checking if the GUI should be showed, if yes you show it, if not you don't.

Using a TimeOut here is just unnecessary, I'd suggest you do:

PHP Code:

//#CLIENTSIDE 
function onCreated(){ 
    
this.localinfo = { 
        {
"Electric Workshop""noc_inside-elect.nw"}, 
        {
"Car Workshop""noc_inside-mech-garage.nw"}, 
        {
"Guns Shop""noc_inside-general-store.nw"
    };
    if (
player.level in this.localinfo[0][1]) {
      
ShowGui();
    }

function 
ShowGui() {
  new 
GuiBitmapButtonCtrl("tutorial_button") { 
    
screenwidth 64
    
0
    
width 64
    
height 64
    
normalbitmap "noc_button.png"
    
mouseoverbitmap "noc_button-over.png"
    
pressedbitmap "noc_button-click.png"
  }   
}
function 
onPlayerEnters(){ 
  if (
player.level in this.localinfo[0][1]) { 
    if (!
tutorial_button) {
      
tutorial_button.destroy();
    }
  }
  else { 
    
ShowGui();
  } 



Seich 06-09-2009 08:22 PM

Quote:

Originally Posted by Pelikano (Post 1498166)
That ^

Oh yeah, apparently I posted the wrong code block -.-' there's a for loop there if I was comparing it to a single string in the array it would be way easier -.-'.

edit: nvm I found an easier way after stopping and thinking about it for second. To fix it I set a variable with the current player.level, and then I just checked onPlayerEnters to see if it's different.

Basically:
PHP Code:

function onPlayerEnters(){
   if(
temp.pllevel != player.level){
  
//stuff
  
}
//for loop resulting in true {
  
temp.pllevel player.level;
//}



cbk1994 06-09-2009 08:48 PM

Make sure you're doing

PHP Code:

if (player.level.name in blah

'player.level' is an object.

Seich 06-10-2009 12:12 AM

Quote:

Originally Posted by cbk1994 (Post 1498183)
Make sure you're doing

PHP Code:

if (player.level.name in blah

'player.level' is an object.

Oh yeah.. lol my bad xD.. I haven't slept in more than a day:asleep:.. So my brain ain't working properly.. x.x Thanks for pointing it out :)

[email protected] 06-10-2009 11:46 AM

Maybe better if you did this

HTML Code:

function onPlayerEnters() { 
  this.array = {
      //Shop Names
    {"level1.nw", "level4.nw", "level3.nw"},
      //Descriptions
    {"Gun Shop", "Electrical Shop", "Adult Stall"}
  };
    //The index of the shop level in the array
  temp.index = this.array[0].index(player.level.name);
    //If the entry doesn't exist, don't continue
  if (temp.index == -1) return;

  this.message_title = this.attay[1][temp.index];
  setTimer(0.05);
}


Seich 06-10-2009 05:49 PM

That seems like really good method, I will try it out.


All times are GMT +2. The time now is 01:11 PM.

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