Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Prize Shop script (https://forums.graalonline.com/forums/showthread.php?t=74066)

ff7chocoboknight 05-19-2007 05:00 PM

Prize Shop script
 
The Events Team Admin in the pw I work for asked me to make him a script for a prize shop. I made it and he sent this script back saying it didn't work. This isn't the script I sent him though.... Can someone fix the script before I go mad?
HTML Code:

//#CLIENTSIDE
function onPlayerChats() {
  if (player.chat == "buy Juggling") {
    if (clientr.etcoins >= "30") {
        clientr.etcoins -= "30";
        addweapon "*Prizes/Juggle";
    }
  }
  if (player.chat == "buy PK Heal") {
    if (clientr.etcoins >= "30") {
        clientr.etcoins -= "30";
        addweapon "*Prizes/PK Heal";
    }
  }
  if (player.chat == "buy Jump") {
    if (clientr.etcoins >= "50") {
      clientr.etcoins -= "50";
      addweapon "*Prizes/Jump";
    }
  }
    if (player.chat == "buy Light Mouse") {
    if (clientr.etcoins >= "150") {
        clientr.etcoins -= "150";
        addweapon "*Prizes/Light Mouse";
    }
  }
}


Chompy 05-19-2007 05:05 PM

remove quotes from the number ("30" to 30 etc..)

addweapon("*Prizes/Light Mouse");
need ( )

addweapon is serverside
setting clientr. strings must be done serverside

:)

ff7chocoboknight 05-19-2007 05:15 PM

So, it should be this...?
HTML Code:

//#SERVERSIDE
function onPlayerChats() {
  if (player.chat == "buy Juggling") {
    if (clientr.etcoins >= 30) {
        clientr.etcoins -= 30;
        addweapon ("*Prizes/Juggle");
    }
  }
  if (player.chat == "buy PK Heal") {
    if (clientr.etcoins >= 30) {
        clientr.etcoins -= 30;
        addweapon ("*Prizes/PK Heal");
    }
  }
  if (player.chat == "buy Jump") {
    if (clientr.etcoins >= 50) {
      clientr.etcoins -= 50;
      addweapon ("*Prizes/Jump");
    }
  }
    if (player.chat == "buy Light Mouse") {
    if (clientr.etcoins >= 150) {
        clientr.etcoins -= 150;
        addweapon ("*Prizes/Light Mouse");
    }
  }
}

It's what I sent him before, but without the //#SERVERSIDE

godofwarares 05-19-2007 05:25 PM

Quote:

Originally Posted by ff7chocoboknight (Post 1309514)
So, it should be this...?
HTML Code:

//#SERVERSIDE
function onPlayerChats() {
  if (player.chat == "buy Juggling") {
    if (clientr.etcoins >= 30) {
        clientr.etcoins -= 30;
        addweapon ("*Prizes/Juggle");
    }
  }
  if (player.chat == "buy PK Heal") {
    if (clientr.etcoins >= 30) {
        clientr.etcoins -= 30;
        addweapon ("*Prizes/PK Heal");
    }
  }
  if (player.chat == "buy Jump") {
    if (clientr.etcoins >= 50) {
      clientr.etcoins -= 50;
      addweapon ("*Prizes/Jump");
    }
  }
    if (player.chat == "buy Light Mouse") {
    if (clientr.etcoins >= 150) {
        clientr.etcoins -= 150;
        addweapon ("*Prizes/Light Mouse");
    }
  }
}

It's what I sent him before, but without the //#SERVERSIDE

//#SERVERSIDE does not exist. You need to do a trigger from client to server to achieve what you are going after.

Twinny 05-19-2007 05:29 PM

Quote:

Originally Posted by godofwarares (Post 1309516)
//#SERVERSIDE does not exist. You need to do a trigger from client to server to achieve what you are going after.

Actually, if it's a NPC in a shop: why use clientside? Remove the //#SERVERSIDE line as that does nothing and all shall be sweet.

Skyld 05-19-2007 05:29 PM

Quote:

Originally Posted by godofwarares (Post 1309516)
//#SERVERSIDE does not exist. You need to do a trigger from client to server to achieve what you are going after.

Why not just do it all serverside? There is nothing there that needs to be clientside at all.

Gambet 05-19-2007 05:31 PM

Quote:

Originally Posted by Skyld (Post 1309519)
Why not just do it all serverside? There is nothing there that needs to be clientside at all.



^Right, take a look at these:


PHP Code:

function onActionServerSide()
{
 if (
params[0] == "PurchaseItem")
  {
   switch(
params[1])
    {
     case 
"Juggling":
      if (
clientr.etcoins >= 30)
       {
        
clientr.etcoins -= 30;
        
addweapon("*Prizes/Juggle");
       }
      else
       {
        
player.chat "Insufficient funds!";
       }
      break;
    }
  }
}

//#CLIENTSIDE
function onPlayerChats()
{
 
tokens player.chat.tokenize();
 if (
tokens[0] == "buy")
  {
   
this.t_chat tokens.substring(4);
   switch(
this.t_chat)
    {
     case 
"Juggling":
      
triggerserver("gui",name,"PurchaseItem","Juggling");
      break;
    }
  }



Compared to:

PHP Code:

function onPlayerChats()
{
 
tokens player.chat.tokenize();
 if (
tokens[0] == "buy")
  {
   
this.t_chat tokens.substring(4);
   switch(
this.t_chat)
    {
     case 
"Juggling":
      if (
clientr.etcoins >= 30)
       {
        
clientr.etcoins -= 30;
        
addweapon("*Prizes/Juggle");
       }
      else
       {
        
player.chat "Insufficient funds!";
       }
      break;
    }
  }



Get the picture?

Skyld 05-19-2007 05:35 PM

Quote:

Originally Posted by Gambet (Post 1309521)
I would probably do so for better organization:

Why not this?
PHP Code:

function purchaseItem(temp.itemID

  switch (
temp.itemID
  { 
    case 
"Juggling"
    {
       if (
clientr.etcoins >= 30
       { 
         
player.clientr.etcoins -= 30
         
player.addweapon("*Prizes/Juggle"); 
       } 
         else 
       { 
         
player.chat "Insufficient funds!"
       } 

       break; 
     } 
  } 


function 
onPlayerChats() 

  
temp.tokens player.chat.tokenize(); 

  if (
temp.tokens[0] == "buy"
  {
    if (
temp.tokens[0in {"Juggling"})
    {
      
this.purchaseItem(player.chat.substring(4));
    }
  }


The clientside does not need to be involved, therefore there is no reason to involve it.

Gambet 05-19-2007 05:38 PM

Quote:

Originally Posted by Skyld (Post 1309522)
Stuff




I fixed my post before you posted, your page just wasn't refreshed.


I was trying to find a way to word it correctly and realized I had worded it incorrectly. Fixed it just in time, though ^^

Deadly_Killer 05-19-2007 05:45 PM

PHP Code:

function onCreated() {
  
this.items = {{"Juggling"30"*Prizes/Juggle"}, {"PK Heal"30"*Prizes/PK Heal"}, {"Jump"30"*Prizes/Jump"}, {"Light Mouse"150"*Prizes/Light Mouse"}};
}

function 
onPlayerChats() {
  if (
player.chat.starts("buy")) {
    
temp.item player.chat.substring(4);
    
    for (
temp.var : this.items) {
      if (
temp.item == temp.var[0]) {
        
temp.iteminfo temp.var;
        
        break;
      }
    }
    
    if (
temp.iteminfo != NULL) {
      if (
clientr.etcoins >= temp.iteminfo[1]) {
        
clientr.etcoins -= temp.iteminfo[1];
        
addWeapon(temp.iteminfo[2]);
        
        
player.chat format("You bought %s for %d event coins!"temp.iteminfo[0], temp.iteminfo[1]);
      }
      else 
player.chat format("You require %d event coins for this item!"temp.iteminfo[1]);
    }
  }


or the:
{
}
format

PHP Code:

function onCreated()
{
  
this.items = {{"Juggling"30"*Prizes/Juggle"}, {"PK Heal"30"*Prizes/PK Heal"}, {"Jump"30"*Prizes/Jump"}, {"Light Mouse"150"*Prizes/Light Mouse"}};
}

function 
onPlayerChats()
{
  if (
player.chat.starts("buy"))
  {
    
temp.item player.chat.substring(4);
    
    for (
temp.var : this.items)
    {
      if (
temp.item == temp.var[0])
      {
        
temp.iteminfo temp.var;
        
        break;
      }
    }
    
    if (
temp.iteminfo != NULL)
    {
      if (
clientr.etcoins >= temp.iteminfo[1])
      {
        
clientr.etcoins -= temp.iteminfo[1];
        
addWeapon(temp.iteminfo[2]);
        
        
player.chat format("You bought %s for %d event coins!"temp.iteminfo[0], temp.iteminfo[1]);
      }
        else
      {
        
player.chat format("You require %d event coins for this item!"temp.iteminfo[1]);
      }
    }
  }



Gambet 05-19-2007 05:48 PM

Quote:

Originally Posted by Deadly_Killer (Post 1309528)
Stuff



I avoided doing such since you would only do so assuming everything for each and every item would be the same (I.E, the same chat messages and so forth). Unless everything is going to be the same, you'd have to break it up as I did. Else, your method would be the way to go.


Since he didn't group everything as such, I just took his method and fixed it up.



EDIT: Though now that I think about it, you could set it all up in the arrays, so I guess it would work either way. The only thing you should do is break up your array so it doesn't extend far across the script as such.

Deadly_Killer 05-19-2007 05:59 PM

Quote:

Originally Posted by Gambet (Post 1309531)
EDIT: Though now that I think about it, you could set it all up in the arrays, so I guess it would work either way. The only thing you should do is break up your array so it doesn't extend far across the script as such.

Widescreen monitor ftw ;D

ff7chocoboknight 05-19-2007 07:31 PM

Holy shizzle! I started a scripting war!

ff7chocoboknight 05-21-2007 03:00 AM

Where would I put the script to make it work?

Gambet 05-21-2007 03:42 AM

Quote:

Originally Posted by ff7chocoboknight (Post 1310080)
Where would I put the script to make it work?



You say you scripted the system to begin with and now you don't know where scripts go? x-x


All times are GMT +2. The time now is 02:25 AM.

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