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 06-09-2009, 05:30 PM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
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?

Graal Script 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);

Reply With Quote
  #2  
Old 06-09-2009, 07:32 PM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
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
__________________
Deep into the Darkness peering...
Reply With Quote
  #3  
Old 06-09-2009, 07:43 PM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
Quote:
Originally Posted by Angel_Light View Post
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...

Last edited by Seich; 06-09-2009 at 07:56 PM..
Reply With Quote
  #4  
Old 06-09-2009, 07:51 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano can only hope to improve
Well, why are you doing:

Graal Script 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:

Graal Script 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();
  } 

Reply With Quote
  #5  
Old 06-09-2009, 08:22 PM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
Quote:
Originally Posted by Pelikano View Post
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:
Graal Script Code:
function onPlayerEnters(){
   if(
temp.pllevel != player.level){
  
//stuff
  
}
//for loop resulting in true {
  
temp.pllevel player.level;
//}


Last edited by Seich; 06-09-2009 at 08:43 PM..
Reply With Quote
  #6  
Old 06-09-2009, 08:48 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Make sure you're doing

Graal Script Code:
if (player.level.name in blah
'player.level' is an object.
__________________
Reply With Quote
  #7  
Old 06-10-2009, 12:12 AM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
Quote:
Originally Posted by cbk1994 View Post
Make sure you're doing

Graal Script 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.. So my brain ain't working properly.. x.x Thanks for pointing it out
Reply With Quote
  #8  
Old 06-10-2009, 11:46 AM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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);
}
Reply With Quote
  #9  
Old 06-10-2009, 05:49 PM
Seich Seich is offline
Noctorious' NeoHunter
Seich's Avatar
Join Date: Jun 2008
Location: Honduras
Posts: 193
Seich will become famous soon enough
Send a message via MSN to Seich Send a message via Yahoo to Seich Send a message via Skype™ to Seich
That seems like really good method, I will try it out.
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:48 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.