View Single Post
  #21  
Old 04-28-2007, 10:25 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by oo_jazz_oo View Post
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
__________________

Last edited by Chompy; 04-28-2007 at 10:44 AM..
Reply With Quote