Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Fish Selling System Help (https://forums.graalonline.com/forums/showthread.php?t=86695)

[email protected] 07-04-2009 12:20 PM

Fish Selling System Help
 
Ok, so I have this fish buying system. It's a gui I made with the f6 gui editor. It basically has like 20 buttons and if you have that fish and you want to sell it, you click on the name of the fish and it sells the fish to the npc 1 at a time.


It seems like it's working but right after it adds you money, it takes it away.

Example: You fish for a catfish, you click "sell catfish", you get 10 dollars for the fish, then 1 millisecond later, you get it taken away and it goes back to the original amount of money you had before selling it.

Here is the script.

[/PHP]
//#CLIENTSIDE
function onCreated() {
function onPlayerTouchsme()
{
MyGUI_Window1.visible = true;
}
new GuiWindowCtrl("MyGUI_Window1") {
profile = GuiBlueWindowProfile;
clientrelative = true;
clientextent = "303,195";

canmove = true;
canresize = true;
closequery = false;
destroyonhide = false;
text = " Selling your Fish!";
x = 341;
y = 214;

new GuiButtonCtrl("MyGUI_Button1") {
profile = GuiBlueButtonProfile;
text = "Sell FlyFish";
width = 80;
x = 2;
y = 10;
}
new GuiButtonCtrl("MyGUI_Button2") {
profile = GuiBlueButtonProfile;
text = "Sell Shrimp";
width = 80;
x = 2;
y = 51;
}
new GuiButtonCtrl("MyGUI_Button3") {
profile = GuiBlueButtonProfile;
text = "Sell Bass";
width = 80;
x = 2;
y = 90;
}
new GuiButtonCtrl("MyGUI_Button4") {
profile = GuiBlueButtonProfile;
text = "Sell Salmon";
width = 80;
x = 2;
y = 132;
}
new GuiButtonCtrl("MyGUI_Button6") {
profile = GuiBlueButtonProfile;
text = "Sell StingRay";
width = 80;
x = 219;
y = 7;
}
new GuiButtonCtrl("MyGUI_Button7") {
profile = GuiBlueButtonProfile;
text = "Sell Carp";
width = 80;
x = 220;
y = 47;
}
new GuiButtonCtrl("MyGUI_Button8") {
profile = GuiBlueButtonProfile;
text = "Sell Octopus";
width = 80;
x = 220;
y = 89;
}
new GuiButtonCtrl("MyGUI_Button9") {
profile = GuiBlueButtonProfile;
text = "Sell JellyFish";
width = 80;
x = 221;
y = 130;
}
new GuiButtonCtrl("MyGUI_Button10") {
profile = GuiBlueButtonProfile;
text = "Sell Shark!";
width = 80;
x = 112;
y = 79;
}
new GuiTextCtrl("MyGUI_Text1") {
profile = GuiBlueTextProfile;
height = 20;
text = "10$";
width = 18;
x = 88;
y = 14;
}
new GuiTextCtrl("MyGUI_Text2") {
profile = GuiBlueTextProfile;
height = 20;
text = "20$";
width = 18;
x = 85;
y = 55;
}
new GuiTextCtrl("MyGUI_Text3") {
profile = GuiBlueTextProfile;
height = 20;
text = "60$";
width = 18;
x = 85;
y = 96;
}
new GuiTextCtrl("MyGUI_Text4") {
profile = GuiBlueTextProfile;
height = 20;
text = "50$";
width = 18;
x = 87;
y = 136;
}
new GuiTextCtrl("MyGUI_Text5") {
profile = GuiBlueTextProfile;
height = 20;
text = "90$";
width = 18;
x = 197;
y = 10;
}
new GuiTextCtrl("MyGUI_Text6") {
profile = GuiBlueTextProfile;
height = 20;
text = "30$";
width = 18;
x = 197;
y = 51;
}
new GuiTextCtrl("MyGUI_Text7") {
profile = GuiBlueTextProfile;
height = 20;
text = "100$";
width = 24;
x = 195;
y = 95;
}
new GuiTextCtrl("MyGUI_Text8") {
profile = GuiBlueTextProfile;
height = 20;
text = "110$";
width = 24;
x = 196;
y = 133;
}
new GuiTextCtrl("MyGUI_Text9") {
profile = GuiBlueTextProfile;
height = 20;
text = "200$";
width = 24;
x = 141;
y = 60;
}
new GuiTextCtrl("MyGUI_Text10") {
profile = GuiBlueTextProfile;
height = 20;
text = "Click on The button of the fish you would like to sell!";
width = 248;
x = 22;
y = 172;
}
}
}

function MyGUI_Button1.onAction() {
// Button "Sell FlyFish" has been pressed
if (hasweapon(Fish/FlyFish))
{
player.chat = "I have sold (x1) FlyFish!";
player.rupees+=10;
Player.removeWeapon("Fish/FlyFish");
}
else
player.chat = "I do not have a FlyFish!";
}
function MyGUI_Button2.onAction() {
// Button "Sell Shrimp" has been pressed
}

function MyGUI_Button3.onAction() {
// Button "Sell Bass" has been pressed
}

function MyGUI_Button4.onAction() {
// Button "Sell Salmon" has been pressed
}

function MyGUI_Button6.onAction() {
// Button "Sell StingRay" has been pressed
}

function MyGUI_Button7.onAction() {
// Button "Sell Carp" has been pressed
}

function MyGUI_Button8.onAction() {
// Button "Sell Octopus" has been pressed
}

function MyGUI_Button9.onAction() {
// Button "Sell JellyFish" has been pressed
}

function MyGUI_Button10.onAction() {
// Button "Sell Shark!" has been pressed
}
[/PHP]

check out towards the end to see the script I have. Please someone help me fix it. thanks [;

Codein 07-04-2009 12:22 PM

Money changes, with other important stats (such as health, magic, etc) can only be changed on the serverside portion of the script.

Look into triggerserver and the onActionServerside() event :)

Pelikano 07-04-2009 12:24 PM

Use please

Stephen 07-04-2009 01:16 PM

On the topic of usability, you may want to consider a simpler dialog with three elements: a quantity, a drop down box (for fix selection) and a confirmation button.

cbk1994 07-05-2009 12:35 AM

I couldn't find the article I was looking for on the wiki, so I'll summarize for you.

You need to change the player's money serverside. The best way to do this would be to trigger serverside like this

PHP Code:

triggerserver("gui"name"sellFish""Salmon"); 

Then, at the top of your script (on serverside), you need to determine how much salmon the player has, then figure out how much to pay them. Take away the salmon, then pay the player.

PHP Code:

function onActionServerSide(cmdfish) {
  if (
cmd == "sellFish") {
    if (
fish == "Salmon") {
      
temp.amount clientr.fish.Salmon;
      
temp.pricePerFish 15;
      
      
clientr.fish.Salmon 0;
      
clientr.money += (pricePerFish amount);
    }
  }


This is a basic outline of what you want to do. If you were to add the rest of your script, it would look like this:

PHP Code:

function onActionServerSide(cmdfish) {
  if (
cmd == "sellFish") {
    if (
fish == "Salmon") {
      
temp.amount clientr.fish.Salmon;
      
temp.pricePerFish 15;
      
      
clientr.fish.Salmon 0;
      
clientr.money += (pricePerFish amount);
    } else if (
fish == "Shrimp") {
      
temp.amount clientr.fish.Shrimp;
      
temp.pricePerFish 10;
      
      
clientr.fish.Shrimp 0;
      
clientr.money += (pricePerFish amount);
    } 
// and a long list of else-ifs paying the player
  
}
}
//#CLIENTSIDE
// insert all your GUI stuff here

function MyGUI_Button1.onAction() {
  
triggerserver("gui"name"sellFish""Salmon");
}
function 
MyGUI_Button2.onAction() {
  
triggerserver("gui"name"sellFish""Shrimp");
}

// and all the other buttons, etc 


However, an easier way to do the serverside bit would be

PHP Code:

function onActionServerSide(cmdfish) {
  if (
cmd == "sellFish") {
    
// now you need to figure out how much to pay for each fish, so
    // add it to the list here
    
    
temp.price.Salmon 15;
    
temp.price.Trout 10;
    
temp.price.FlyFish 5;
    
temp.price.Shrimp 10;
    
// add all the other fish as well here
    
    // now that you did that list, you don't have to add anything else
    // down here for each fish
    
    
temp.amount clientr.fish.(fish);
    
temp.pricePerFish temp.price.(@ fish);
    
clientr.money += (amount pricePerFish);
    
clientr.fish.(fish) = 0;
  }


This just saves work, and makes it easier to change things later on. If that method confuses you, use the first one. Remember you're going to have to change the variables around to fit your server (e.g. clientr.money, clientr.fish.name)

[email protected] 07-05-2009 10:09 AM

Quote:

Originally Posted by cbk1994 (Post 1504257)
This just saves work, and makes it easier to change things later on. If that method confuses you, use the first one. Remember you're going to have to change the variables around to fit your server (e.g. clientr.money, clientr.fish.name)

Lovely post, I'd do my selling of the fish differently though

PHP Code:

temp.fish = {
  
"Salmon"10,
  
"Trout"15,
  
"Yada"5
};

temp.saleamount temp.fish.index( (selling fish name heresent from the triggeraction) ) + 1


cbk1994 07-05-2009 11:17 AM

Quote:

Originally Posted by [email protected] (Post 1504319)
Lovely post, I'd do my selling of the fish differently though

PHP Code:

temp.fish = {
  
"Salmon"10,
  
"Trout"15,
  
"Yada"5
};

temp.saleamount temp.fish.index( (selling fish name heresent from the triggeraction) ) + 1


The code you posted is wrong, actually. You'd need to do this (you forgot to take that index out of the array):

PHP Code:

temp.saleamount temp.fish[temp.fish.index(fish) + 1]; 

My way is probably more efficient, however, since the engine isn't having to check through the array once to find the index, add one to the index, then loop through the array again to find the other index. However, it'd be such a miniscule difference it would work fine either way.

[email protected] 07-05-2009 11:30 AM

Quote:

Originally Posted by cbk1994 (Post 1504323)
The code you posted is wrong, actually. You'd need to do this (you forgot to take that index out of the array):

PHP Code:

temp.saleamount temp.fish[temp.fish.index(fish) + 1]; 

My way is probably more efficient, however, since the engine isn't having to check through the array once to find the index, add one to the index, then loop through the array again to find the other index. However, it'd be such a miniscule difference it would work fine either way.

Oh, you're right haha. How dumb of me =p


All times are GMT +2. The time now is 01:23 PM.

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