Quote:
Originally Posted by oo_jazz_oo
Ok, heres the npc in the level:
The shops class:
The -shop npc:
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(1, 32, 32); // you need a shape for triggeractions
function onActionServerside()
{
if (params[0] == "addw")
ShopFunctions.addShopItem(params[1]);
}
//#CLIENTSIDE
function onCreated()
{
sethape(1, 32, 32); // you need a shape for triggeractions
setTimer(0.05);
}
function onMouseDown(button)
{
if (button == "left")
openShopGui();
}
function openShopGui()
{
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 >= this.price){
client.money -= this.price;
triggeraction(this.x + 0.5, this.y + 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