Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Classes with guis (https://forums.graalonline.com/forums/showthread.php?t=73704)

Andy0687 04-28-2007 07:01 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303772)
One last thing. ><
I cant get the weapon to add to the player. =/
I have tried everything....whats wrong with this?

My guess is this little bit right here

PHP Code:

triggeraction(0,0,"serverside","-Shop","addw",@this.item); 

for one you dont need the @ at the start of the param, nor do you need it on the serverside (addweapon).
You never actually set anywhere in any of your script what this.item is.

but if you did trying

PHP Code:

triggeraction(00"serverside""-Shop""addw"thiso.item); 

and

PHP Code:

function onActionServerside() {
 if (
params[0] == "addw") {
  
addweapon(params[1]);
 }


was what you were looking for?

Edit:

It also seems to me like you almost by Habit use @ at the start of variables for example

PHP Code:

if (client.money >=@this.price){ 

Might not work? Anyways that could/should be rewritten as

PHP Code:

if (client.money >= this.price){ 


oo_jazz_oo 04-28-2007 07:09 AM

It is a habit to write @ before variables. ><
I dont know why. >_<
But, anyway, this.item is set in the level script as this.item = "Guns/Tommy Gun";
And it still doesnt work, even after your fixes. -.-

zokemon 04-28-2007 07:10 AM

Quote:

Originally Posted by Rapidwolve (Post 1303758)
Use thiso.itemname for GUI Controls

About time someone saw that o_o

xXziroXx 04-28-2007 07:28 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303775)
It is a habit to write @ before variables. ><
I dont know why. >_<
But, anyway, this.item is set in the level script as this.item = "Guns/Tommy Gun";
And it still doesnt work, even after your fixes. -.-

Post the script and show us how it looks now?

oo_jazz_oo 04-28-2007 07:35 AM

Ok, heres the npc in the level:

HTML Code:

this.join("shops");

//#CLIENTSIDE

this.shopname = "John's Shop";

this.itemname = "Tommy Gun";

this.price = "15000";

this.image1 = "dh_tommygun-icon.gif";

this.item = "Guns/Tommy Gun";


The shops class:

HTML Code:

//#CLIENTSIDE
function onCreated(){
setTimer(.05);
}
function onActionLeftMouse(){
new GuiWindowCtrl("shopwin") {
  profile = GuiBlueWindowProfile;
  x = 10;
  y = 100;
  destroyonhide=true;
  canresize=false;
  canminimize=false;
  canmaximize=false;
  canclose=false;
  canmove=true;
  width = 160;
  height = 140;
  text = "";
 
new GuiMLTextCtrl("shopitem") {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 25;
  width = 160;
  height = 1;
  text = "<center>"@thiso.itemname@"</center>";
}

new GuiMLTextCtrl(shoppri) {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 45;
  width = 160;
  height = 1;
  text = "<center>Price:</center>";
}

new GuiMLTextCtrl(shopprice) {
  profile = GuiBlueMLTextProfile;
  x = 0;
  y = 65;
  width = 160;
  height = 1;
  text = "<center>"@thiso.price@" $</center>";
}

 new GuiFrameSetCtrl("Test_Frames") {
  x = 10;
  y = 65;
  width = 140;
  height = 15;
  rowcount = 1;
  columncount = 1;
  setColumnOffset(1,80);
  setRowOffset(1,80);
  bordercolor = {128,128,255,128};
 
  new GuiScrollCtrl("Test_Frame1") {
    profile = GuiBlueScrollProfile;
    hScrollBar = "dynamic";
    vScrollBar = "dynamic";
  }
 }
 
 new GuiButtonCtrl("cancelb") {
  profile = GuiBlueButtonProfile;
  x = 10;
  y = 90;
  width = 50;
  height = 20;
  text = "Cancel";
 }
 
  new GuiButtonCtrl("buyb") {
  profile = GuiBlueButtonProfile;
  x = 100;
  y = 90;
  width = 50;
  height = 20;
  text = "Buy";
 }

 
}
Test_Frames.PushtoBack();
}

function cancelb.onAction(){
shopwin.destroy();
}
function buyb.onAction(){
if (client.money >[email protected]){
client.money -=this.price;
triggeraction(0,0,"serverside","-Shop","addw",this.item);
}
}


The -shop npc:

HTML Code:

function onActionServerside(){
 if (params[0] == "addw") {
addweapon(params[1]);
      }
    }

But I cant get the weapon to add to the player. >_<

Chompy 04-28-2007 10:25 AM

Quote:

Originally Posted by oo_jazz_oo (Post 1303779)
Ok, heres the npc in the level:

HTML Code:

...

The shops class:

HTML Code:

...

The -shop npc:

HTML Code:

...
But I cant get the weapon to add to the player. >_<

btw; onActionLeftMouse() is serverside :P

I just "modified" some of the script and added another way to add the weapon to the player (public functions in wnpcs)

level npc
PHP Code:

function onCreated()
  
this.join("shops");

//#CLIENTSIDE
function onCreated()
{
  
this.shopname "John's Shop";
  
this.itemname "Tommy Gun";
  
this.price "15000";
  
this.image1 "dh_tommygun-icon.gif";
  
this.item "Guns/Tommy Gun";


class "shops":
PHP Code:

function onCreated()
  
sethape(13232); // you need a shape for triggeractions

function onActionServerside()
{
  if (
params[0] == "addw")
    
ShopFunctions.addShopItem(params[1]);
}
//#CLIENTSIDE
function onCreated()
{
  
sethape(13232); // you need a shape for triggeractions
  
setTimer(0.05);
}
function 
onMouseDown(button)
{
  if (
button == "left")
    
openShopGui();
}
function 
openShopGui()
{
  new 
GuiWindowCtrl(shopwin) {
    
profile GuiBlueWindowProfile;
    
10;
    
100;
    
destroyonhide true;
    
canresize false;
    
canminimize false;
    
canmaximize false;
    
canclose false;
    
canmove true;
    
width 160;
    
height 140;
    
text "";
    new 
GuiMLTextCtrl(shopitem) {
      
profile GuiBlueMLTextProfile;
      
0;
      
25;
      
width 160;
      
height 1;
      
text "<center>" thiso.itemname "</center>";
    }
    new 
GuiMLTextCtrl(shoppri) {
      
profile GuiBlueMLTextProfile;
      
0;
      
45;
      
width 160;
      
height 1;
      
text "<center>Price:</center>";
    }
    new 
GuiMLTextCtrl(shopprice) {
      
profile GuiBlueMLTextProfile;
      
0;
      
65;
      
width 160;
      
height 1;
      
text "<center>" thiso.price " $</center>";
    }
    new 
GuiFrameSetCtrl(Test_Frames) {
      
10;
      
65;
      
width 140;
      
height 15;
      
rowcount 1;
      
columncount 1;
      
setColumnOffset(180);
      
setRowOffset(180);
      
bordercolor = {128128255128};
      new 
GuiScrollCtrl(Test_Frame1) {
        
profile GuiBlueScrollProfile;
        
hScrollBar "dynamic";
        
vScrollBar "dynamic";
      }
    }
    new 
GuiButtonCtrl("cancelb") {
      
profile GuiBlueButtonProfile;
      
10;
      
90;
      
width 50;
      
height 20;
      
text "Cancel";
    }
    new 
GuiButtonCtrl("buyb") {
      
profile GuiBlueButtonProfile;
      
100;
      
90;
      
width 50;
      
height 20;
      
text "Buy";
    }
  }
  
Test_Frames.PushtoBack();
}

function 
cancelb.onAction()
  
shopwin.destroy();

function 
buyb.onAction()
{
  if (
client.money >= this.price){
    
client.money -= this.price;
    
triggeraction(this.0.5this.0.5"serverside""addw"thiso.item);
  }


weapon npc "ShopFunctions":
PHP Code:

public function addShopItem(item)
  
addweapon(params[1]); 

Make the shops class trigger a wnpc to add the weapon to the player,
instead of using triggeractions to get to an other wnpc, use triggeraction to get serverside in the class, then
trigger to the wnpc using the magic of object-oriented and public functions

oo_jazz_oo 04-28-2007 11:51 PM

Still wont work. =/
Its the triggeraction that isnt working...cause, if you replace
ShopFunctions.addShopItem(params[1]);
with
player.chat = "Test";
Nothing happens, so there is a problem in the triggeraciotn. -.-

Rapidwolve 04-29-2007 03:24 AM

It would be params[0] wouldn't it? either do addWeapon(params[0]) or addWeapon(temp.item)

ff7chocoboknight 04-29-2007 03:37 AM

most of the corrections made are right but not put into the script correctly

Inverness 04-29-2007 04:46 AM

Quote:

Originally Posted by Chompy (Post 1303785)
btw; onActionLeftMouse() is serverside :P

Actions occur on both sides as long as the object has a shape on both sides.

Chompy 04-29-2007 03:30 PM

Quote:

Originally Posted by oo_jazz_oo (Post 1303972)
Still wont work. =/
Its the triggeraction that isnt working...cause, if you replace
ShopFunctions.addShopItem(params[1]);
with
player.chat = "Test";
Nothing happens, so there is a problem in the triggeraciotn. -.-

two things :)

first:
I changed the styling and some vars from the original (your script), but didn't see this:
PHP Code:

if (client.money >= this.price){ 

try change it to
PHP Code:

if (client.money >= thiso.price){ 

(They are right before the triggeraction)

second:

change addWeapon(params[1]); to addWeapon(item); in ShopFunctions,
I was using params[1] because I was thinking of the class (params[1] was the item there)

class "shops":
PHP Code:

function onCreated()
  
sethape(13232); // you need a shape for triggeractions

function onActionServerside()
{
  if (
params[0] == "addw")
    
ShopFunctions.addShopItem(params[1]);
}
//#CLIENTSIDE
function onCreated()
{
  
sethape(13232); // you need a shape for triggeractions
  
setTimer(0.05);
}
function 
onMouseDown(button)
{
  if (
button == "left")
    
openShopGui();
}
function 
openShopGui()
{
  new 
GuiWindowCtrl(shopwin) {
    
profile GuiBlueWindowProfile;
    
10;
    
100;
    
destroyonhide true;
    
canresize false;
    
canminimize false;
    
canmaximize false;
    
canclose false;
    
canmove true;
    
width 160;
    
height 140;
    
text "";
    new 
GuiMLTextCtrl(shopitem) {
      
profile GuiBlueMLTextProfile;
      
0;
      
25;
      
width 160;
      
height 1;
      
text "<center>" thiso.itemname "</center>";
    }
    new 
GuiMLTextCtrl(shoppri) {
      
profile GuiBlueMLTextProfile;
      
0;
      
45;
      
width 160;
      
height 1;
      
text "<center>Price:</center>";
    }
    new 
GuiMLTextCtrl(shopprice) {
      
profile GuiBlueMLTextProfile;
      
0;
      
65;
      
width 160;
      
height 1;
      
text "<center>" thiso.price " $</center>";
    }
    new 
GuiFrameSetCtrl(Test_Frames) {
      
10;
      
65;
      
width 140;
      
height 15;
      
rowcount 1;
      
columncount 1;
      
setColumnOffset(180);
      
setRowOffset(180);
      
bordercolor = {128128255128};
      new 
GuiScrollCtrl(Test_Frame1) {
        
profile GuiBlueScrollProfile;
        
hScrollBar "dynamic";
        
vScrollBar "dynamic";
      }
    }
    new 
GuiButtonCtrl("cancelb") {
      
profile GuiBlueButtonProfile;
      
10;
      
90;
      
width 50;
      
height 20;
      
text "Cancel";
    }
    new 
GuiButtonCtrl("buyb") {
      
profile GuiBlueButtonProfile;
      
100;
      
90;
      
width 50;
      
height 20;
      
text "Buy";
    }
  }
  
Test_Frames.PushtoBack();
}

function 
cancelb.onAction()
  
shopwin.destroy();

function 
buyb.onAction()
{
  if (
client.money >= thiso.price) { // Changed this to thiso
    
client.money -= this.price;
    
triggeraction(this.0.5this.0.5"serverside""addw"thiso.item);
  }


wnpc "ShopFunctions":
PHP Code:

public function addShopItem(temp.item)
  
addweapon(item); 

Quote:

Originally Posted by Rapidwolve (Post 1304034)
It would be params[0] wouldn't it? either do addWeapon(params[0]) or addWeapon(temp.item)

You're right :p typo

should be addWeapon(item); in ShopFunctions



Quote:

Originally Posted by Inverness (Post 1304070)
Actions occur on both sides as long as the object has a shape on both sides.

:O didn't know :p

ff7chocoboknight 04-29-2007 04:37 PM

w00t go Chompy

Rapidwolve 04-29-2007 05:41 PM

Quote:

Originally Posted by Chompy (Post 1304132)
You're right :p typo
should be addWeapon(item); in ShopFunctions

Hmm, I always do it like this and it works fine.

PHP Code:

public function addShopItem(item)
{
  
addWeapon(temp.item);  // I put the 'temp.' here



ff7chocoboknight 04-29-2007 06:17 PM

I've used it both ways it really depends on what the scripts are for (GUIs and chests for example)


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

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