Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-02-2013, 03:12 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Graal Stock Market

Today I present you with a fully functional mini stock market.
Each player starts with $1,000 virtual cash (clientr.stockcash).
You can then purchase stocks (defined in the DBNPC "Stocks").
When the NYSE stock market is open, the stocks will update every second.
Whilst the NYSE market is closed players can still purchase stocks and sell, but won't make any profit or loss.
The configuration is pretty simple.
In the DBNPC "Stocks", just add the stock name and symbol to the array.
Then upload the weapon script and add it to whoever.
All code can be found in the attached file, Stocks.zip.
It's important the DBNPC is named "Stocks".
The code may not be the best way to do it all but it works and is fairly secure.
To purchase a stock, select it on the left and then change the quantity with the up/down buttons and click buy.
Selling, select it on the right hand side and click sell.

Edit:
v1.2
Updated code to provide live stock data when market is closed.
Fixed a few bugs.
Fixed a possible exploit.
v1.3
Added charts.
Attached Thumbnails
Click image for larger version

Name:	stocks_screenshot.png
Views:	290
Size:	81.3 KB
ID:	55275  
Attached Files
File Type: zip Stocks.zip (2.7 KB, 202 views)
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 01-03-2013 at 11:25 AM..
Reply With Quote
  #2  
Old 01-02-2013, 06:00 PM
papajchris papajchris is offline
Zeus Condero
papajchris's Avatar
Join Date: Jan 2006
Location: Michigan
Posts: 1,600
papajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to beholdpapajchris is a splendid one to behold
Really cool. I think something like this would be a far better way to gamble than bet flipping on Era.
__________________
Reply With Quote
  #3  
Old 01-02-2013, 08:20 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Let me know when this goes live, I already found 3 exploits just looking through the code once-over. Can't wait to break your server.
Reply With Quote
  #4  
Old 01-02-2013, 08:53 PM
BboyEatsbacon BboyEatsbacon is offline
The Bacon Man
BboyEatsbacon's Avatar
Join Date: Feb 2011
Location: United States
Posts: 60
BboyEatsbacon will become famous soon enough
Quote:
Originally Posted by Hezzy002 View Post
Let me know when this goes live, I already found 3 exploits just looking through the code once-over. Can't wait to break your server.
Why not suggest ways to patch this rather than being a **** about it?
Reply With Quote
  #5  
Old 01-02-2013, 09:39 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
because i dont like gunderak!!
Reply With Quote
  #6  
Old 01-03-2013, 12:50 AM
BboyEatsbacon BboyEatsbacon is offline
The Bacon Man
BboyEatsbacon's Avatar
Join Date: Feb 2011
Location: United States
Posts: 60
BboyEatsbacon will become famous soon enough
Quote:
Originally Posted by Hezzy002 View Post
because i dont like gunderak!!
Oh, proceed then.
Reply With Quote
  #7  
Old 01-03-2013, 04:27 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Hezzy just **** off.
You're so cool, you'll hack virtual currency in a game.
And how do you suppose to hack it, it's all server side.
Might make even more checks just to piss you off.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #8  
Old 01-03-2013, 04:29 AM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
kiss me gunderak
Reply With Quote
  #9  
Old 01-03-2013, 04:46 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Just piss off.
I coded it to be a bit of fun.
Not for people like yourself to just offer negativity towards it.
If you have something useful to say, feel free. Otherwise, go crawl back under that rock of yours.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #10  
Old 01-03-2013, 05:56 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is a jewel in the roughTricxta is a jewel in the rough
You know... it'd be "way cool" if you made your own independent system and base stocks off in game businesses. Then determine stock price via items sold each day or whatever, amount of stocks available and demand for that stock.

Also I notice you don't have divdends implemented, always room for an update!
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #11  
Old 01-03-2013, 06:01 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
I was considering making my own stocks, I did to some degree, But it failed.
And basing it off items wouldn't really work, seeming you'd have to code it in your self.
So it would work for one server only really.
And dividends, eh, I mean I suppose you could make it pay out every hour of online time or something, I don't know. Can't really make it annually lol.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #12  
Old 01-03-2013, 06:03 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
This was my initial attempt at making fake stocks.
Instead of having to wait t'ill the real stock market is open.
PHP Code:
function onCreated(){
  
onTimeout();
  
this.stocks = {
    {
"Graalordinates", -212},
    {
"PlayerKillCo", -53},
    {
"UnixmadBreadFund", -710},
    {
"BrokeLenders", -613},
    {
"Gold", -123},
    {
"Silver", -0.512},
    {
"Oil", -2.615},
    {
"Facebook", -418},
    {
"Google", -314},
    {
"Yahoo", -211},
  };
}
function 
onTimeout(){
  for(
0this.stocks.size(); ++){
    
temp.stock this.stocks[i][0];
    
temp.min this.stocks[i][1];
    
temp.max this.stocks[i][2];
    
temp.amnt random(minmax);
    if(
this.stock_price.(@stock) < amnt){
      
this.stock_price.(@stock) += random(0.010.02);
    }
    if(
this.stock_price.(@stock) > amnt){
      
this.stock_price.(@stock) -= random(0.010.02);
    }
    
temp.min this.stock_price.(@stock) < 0;
    
this.stock_price.(@stock) = this.stock_price.(@stock[0]).substring(0, (min?5:4));
  }
  
settimer(5);

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 01-03-2013, 04:59 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
PHP Code:
  if(params[0] == "Buy"){
    
temp.rate Stocks.stock_price.(@params[1]);
    
temp.amnt params[2];
    
temp.price amnt*rate;
    if(
clientr.stockcash >= price){
      
clientr.stockcash -= price;
      
clientr.stocks.(@int(random(1,9999999)))= {params[1], rateamnt};
      
clientr.stockcash clientr.stockcash.substring(0clientr.stockcash.pos(".") + 3);
    }
  }
  if(
params[0] == "Sell"){
    
temp.rate Stocks.stock_price.(@params[1]);
    for(
temp.getstringkeys("clientr.stocks.")){
      
temp.amnt clientr.stocks.(@i)[2];
      
temp.price amnt*rate;
      
temp.checkname clientr.stocks.(@i)[0];
      if(
checkname == params[1]){
        
temp.checkrate clientr.stocks.(@i)[1];
        if(
checkrate.pos(params[2]) >= 0){
          
temp.checkquantity clientr.stocks.(@i)[2];
          if(
checkquantity == params[3]){;
            if(
clientr.stocks.(@i) == null) return;
            
clientr.stocks.(@i) = null;
            
clientr.stockcash += price;
            return;
          }
        }
      }
    }
  } 
No validation? Huge security holes... What if params[1] or params[2] was negative?
clientr.stockcash -= -(price);

See where I'm going?
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #14  
Old 01-03-2013, 05:26 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
not only that but stocks are stupid
Reply With Quote
  #15  
Old 01-03-2013, 05:28 PM
James James is offline
LOCAL DOUCHEBAG
James's Avatar
Join Date: Aug 2001
Location: Oregon
Posts: 3,132
James is a splendid one to beholdJames is a splendid one to beholdJames is a splendid one to beholdJames is a splendid one to behold
Send a message via AIM to James
lol ^
__________________

JAMES BAY PACKERS
2011 FANTASY FOOTBALL CHAMPIONS
2012 FANTASY FOOTBALL CHAMPIONS


“If I can slow it down in my mind... things will be fine."

-Aaron Rodgers
2011's NFL Most Valuable Player




Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:09 AM.


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