[XP] RPG Maker XP Online System (RMX-OS)

Started by Blizzard, June 20, 2009, 11:52:23 am

Previous topic - Next topic

G_G

I'm working on a plugin. How do I make it detect that the server is shutdown or is being shutdown. Its going to be an extension but I also had an idea, I was just going to alias a couple of methods in Server.rb and place it in its own .rb and add it to an extension. Would that work?

nathmatt

May 20, 2010, 06:46:23 pm #721 Last Edit: May 20, 2010, 06:48:38 pm by nathmatt
check out the extensoin skeleton
Spoiler: ShowHide

def self.main
 # while server is running
  while RMXOS.server.running
    self.server_update #server is running
    sleep(0.1) # 0.1 seconds pause, decreases server load
  end
  # server is shut down
end


the only way i can think of to tell if you hit the x to close it thought would be to have a parallel program running to check the server
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


G_G

Well I managed a simple Online Status plugin. However the plugin only sets it Offline if you press CTRL + C to shutdown the server. If you shut it down by clicking X then it doesn't change it.

Magus

Okay... the HTML help file is unclear. It doesn't explain hosting very well, so I'm stuck at the moment.
Like.. how do I make it, so that other people, such as my friends can play.
LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

Wizered67

um..... you give them the game.......

Well, I don't know what you have and haven't done, but you have to forward the port and put in your ip in the options stuff.

Magus

May 20, 2010, 08:03:02 pm #725 Last Edit: May 20, 2010, 10:54:41 pm by Nawm
Edit:

I was kidding. I have it downpacked..
LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

G_G

May 20, 2010, 10:57:10 pm #726 Last Edit: May 20, 2010, 11:41:52 pm by game_guy
Okay, well I've got something else I'm working on. I need to know how to access a clients party, or give a client gold. Might as well tell you what I plan. I'm making a Random Gold extension.

After so many configurable minutes, it'll randomly choose a connected client. It'll give that person a random amount of gold between Min and Max. Then it sets Last_user to the client's name just so that same client can't get gold twice in a row. Then waits another configurable minutes.

EDIT: I know the idea sounds stupid, but its mostly for practice. I practically know nothing about Rmx-os. So it makes sense making silly small plugins for it.

Blizzard

May 21, 2010, 02:58:13 am #727 Last Edit: May 21, 2010, 03:06:37 am by Blizzard
Quote from: Nawm on May 20, 2010, 07:39:33 pm
Okay... the HTML help file is unclear. It doesn't explain hosting very well, so I'm stuck at the moment.
Like.. how do I make it, so that other people, such as my friends can play.


Have you ever heard of the Internet and the information that is out there, my friend?

@G_G:

The method nathmatt posted:


def self.main
 # while server is running
  while RMXOS.server.running
    self.server_update #server is running
    sleep(0.1) # 0.1 seconds pause, decreases server load
  end
  # YOUR CODE BEFORE SHUTDOWN GOES HERE
  # server is shut down
end


Clicking X kills the server and I don't think there's a way around that. The only actual way I could think of would be that the server writes to a file every 5 seconds and if the file hasn't been modified for more than 10 seconds, everything outside of RMX-OS knows that RMX-OS isn't running anymore.

As for the other plugins...
RMX-OS is not related to the game in any way. There is almost not game data on the server. The only game data that is on the server while it's running is the data that is required for other clients to know where the client is standing, etc. You can't give people gold on the server and expect it to appear in game. RMX-OS is a server, not a client. It synchronizes clients. It does not run a messed up copy of the game like Netplay (hence RMX-OS runs a lot faster than Netplay).

You can always use the message code EVA when sending clients a message that they should interpret.

client.send("EVA$game_party.gain_gold(1000)")

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

I tested that code out and it worked perfectly. However here's my code and how its setup but it doesn't seem that the its actually being updated. Here's my code.
module RMXOS

#------------------------------------------------------------------
# Passes the extension's main module to RMX-OS on the top
# level so it can handle this extension.
# Returns: Module of this extension for update.
#------------------------------------------------------------------
def self.load_current_extension
return RandomGold
end

end

#======================================================================
# module ExtensionSkeleton
#======================================================================

module RandomGold

VERSION = 1.0
RMXOS_VERSION = 1.11
SERVER_THREAD = true

# :::: START Configuration
TIME_WAIT = 10 # In Minutes : Must be whole number
  GOLD_MIN = 1
  GOLD_MAX = 500
# :::: END Configuration

#------------------------------------------------------------------
# Initializes the extension (i.e. instantiation of classes).
#------------------------------------------------------------------
def self.initialize
    @last_user = ""
    @time = 0
    @clients = []
end
#------------------------------------------------------------------
# Calls constant updating on the server.
#------------------------------------------------------------------
def self.main
# while server is running
while RMXOS.server.running
                                  self.server_update
sleep(1) # 1 seconds pause, decreases server load
end
end
#------------------------------------------------------------------
# Handles the server update.
#------------------------------------------------------------------
def self.server_update
# - YOUR SERVER CODE HERE
    @time += 1
    puts "Random Gold: #{TIME_WAIT - @time}"
    if @time >= TIME_WAIT
      gold = rand(GOLD_MAX) + GOLD_MIN
      client = rand($clients.size)
      $client[client].send("EVA$game_party.gain_gold(#{gold})")
      @time = 0
    end
end
#------------------------------------------------------------------
# Handles updating from a client.
# client - Client instance (from Client.rb)
# Returns: Whether to stop check the message or not.
#------------------------------------------------------------------
def self.client_update(client)
# - YOUR CLIENT MESSAGE CODE HERE
return false
end

end


But it doesn't seem to be updating. I waited ten seconds and then it should've chosen a random client to give gold to. I can't say for sure it is actually updating or If I'm doing something wrong. But I've waited several seconds and I didn't get any gold.

Magus

Quote from: Blizzard on May 21, 2010, 02:58:13 am
Quote from: Nawm on May 20, 2010, 07:39:33 pm
Okay... the HTML help file is unclear. It doesn't explain hosting very well, so I'm stuck at the moment.
Like.. how do I make it, so that other people, such as my friends can play.


o.o That quote is old. If you read my next post afterwards, you should be able to dismiss it
Have you ever heard of the Internet and the information that is out there, my friend?

@G_G:

The method nathmatt posted:


def self.main
  # while server is running
   while RMXOS.server.running
     self.server_update #server is running
     sleep(0.1) # 0.1 seconds pause, decreases server load
   end
   # YOUR CODE BEFORE SHUTDOWN GOES HERE
   # server is shut down
end


Clicking X kills the server and I don't think there's a way around that. The only actual way I could think of would be that the server writes to a file every 5 seconds and if the file hasn't been modified for more than 10 seconds, everything outside of RMX-OS knows that RMX-OS isn't running anymore.

As for the other plugins...
RMX-OS is not related to the game in any way. There is almost not game data on the server. The only game data that is on the server while it's running is the data that is required for other clients to know where the client is standing, etc. You can't give people gold on the server and expect it to appear in game. RMX-OS is a server, not a client. It synchronizes clients. It does not run a messed up copy of the game like Netplay (hence RMX-OS runs a lot faster than Netplay).

You can always use the message code EVA when sending clients a message that they should interpret.

client.send("EVA$game_party.gain_gold(1000)")


LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

G_G

Nawm, what are you trying to say here?

Blizzard

Quote$clients[client].send("EVA$game_party.gain_gold(#{gold})")


I think I forgot to add the code that detects crashed extensions. O_o
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Quote from: Blizzard on May 21, 2010, 09:22:50 am
Quote$clients[client].send("EVA$game_party.gain_gold(#{gold})")


I think I forgot to add the code that detects crashed extensions. O_o


YES it fixed it! Here's what the server does. It counts down from X seconds. (Will be minutes) Then when it reaches TIME_WAIT it gives a random client a random amount of gold. In the server itself, it out puts this.
p "Time Left Til Gold: #{TIME_WAIT - @time}"


When it prints 0, it means @time is at TIME_WAIT, @time is set to 0 after it gives the gold, however it doesn't start counting down again and on top of that it doesn't print the client's name who got the gold.

Here's my new script.
http://pastebin.com/E4mcS5S8

Any help is appreciated thanks BLizz!

Blizzard

Why don't you just set the sleep time to the number of seconds which the server will wait and just keep running the gold distro in the main loop? xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Just tried it, now nothings working D:
	def self.main
# while server is running
while RMXOS.server.running
if @time >= TIME_WAIT
gold = rand(GOLD_MAX) + GOLD_MIN
client = rand($clients.size)
$clients[client].send("EVA$game_party.gain_gold(#{gold})")
puts "#{$client[client].player.username} gained #{gold}"
@time = 0
else
@time += 1
end
puts "Time Left Til Gold: #{WAIT_TIME - @time}"
sleep(1)
end
end

Blizzard

	def self.main
# while server is running
while RMXOS.server.running
self.server_update
sleep(WAIT_TIME)
end
end

def self.server_update
gold = rand(GOLD_MAX) + GOLD_MIN
client = $clients[rand($clients.size)]
client.send("EVA$game_party.gain_gold(#{gold})")
puts "#{client.player.username} gained #{gold}"
end


;)
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

May 21, 2010, 07:44:59 pm #736 Last Edit: May 21, 2010, 07:52:02 pm by game_guy
Again, it works only one time. Then its like it stops updating. I set the time wait to 10 seconds. Sat there for 10, got 227 gold, then sat for another 10 and I didn't get anything. And the message wasn't getting printed either.  D:

EDIT: Typo on WAIT_TIME xD didn't realize, its supposed to be TIME_WAIT, works perfectly now <3 Sorry for bugging you !

Blizzard

No problem. I just uploaded RMX-OS 1.13 which properly reports extension bugs. Now errors like this won't happen anymore. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Small update if you dont mind .__.

Random Gold makes sure that no player gets gold randomly twice in a row.
Got all wanted features built in. Except one (keep reading, maybe you can help me)
-Set Wait Time in seconds before gifting gold
-Set gold minimum and maximum
-Set log gold messages
-Never picks same person twice
-Set error messages to what you want

Feature I wanted.
-When client gets the gold, I want a message to appear in the chatbox. I only want him to see it, is it possible?

Blizzard

May 22, 2010, 04:22:42 am #739 Last Edit: May 22, 2010, 04:28:04 am by Blizzard
This here would be a full fletched extension making use of the skeleton and RMX-OS as system.

module RMXOS

def self.load_current_extension
return Goldy
end

module Data
PlayerGotLucky = 'You got lucky! You won AMOUNT gold from the server!'
GoldyGotLucky = '\'PLAYER\' got \'AMOUNT\' gold.'
end

end

#======================================================================
# module Goldy
#======================================================================

module Goldy

VERSION = 1.0
RMXOS_VERSION = 1.13
SERVER_THREAD = true

# START Configuration
SERVER_DISPLAY = true # show log in command prompt screen
LOG_FILENAME = './logs/goldy.log' # leave empty if no log file should be created
DELETE_LOG_ON_START = true
WAIT_TIME = 30
MIN_GOLD = 1000
MAX_GOLD = 10000
# END Configuration

def self.initialize
@lucky_user_ids = []
end
 
def self.main
while RMXOS.server.running
self.server_update
sleep(WAIT_TIME)
end
end

def self.server_update
logged_in_clients = $clients.find_all {|client| client.player.user_id > 0}
unlucky_clients = logged_in_clients.find_all {|client| !@lucky_user_ids.include?(client.player.user_id)}
if unlucky_clients.size > 0
client = unlucky_clients[rand(unlucky_clients.size)]
@lucky_user_ids.push(client.player.user_id)
gold = rand(MAX_GOLD - MIN_GOLD + 1) + MIN_GOLD
client.send("EVA$game_party.gain_gold(#{gold})")
message = RMXOS::Data::PlayerGotLucky.sub('AMOUNT') {gold.to_s}
color = RMXOS::Data::ColorOK
client.send("CHT#{color}\t0\t#{message}")
message = RMXOS::Data::GoldyGotLucky.sub('PLAYER', client.player.username).sub('AMOUNT', gold.to_s)
self.log(message)
end
end

def self.client_update(client)
return false
end

def self.log(message)
puts message if SERVER_DISPLAY
if LOG_FILENAME != ''
file = File.open(LOG_FILENAME, 'a')
file.write(message + "\n")
file.close
end
end

end


You realize, though, that this is generally a stupid idea? (I saw that you posted a topic.) Each time the server crashes, the queue would be emptied and everybody could get gold again.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.