Jump to content
Asharonapaul

Diplomacy Script, First Attempt at Scripting in VX ACE

Recommended Posts

So I ran into a part of the development of my game, and realized I needed to know how to code, or have someone else script it for me. I posted in the Maker forums of the RPG Maker site, and no one seemed thrilled to write it for me. So I watched some tutorials on youtube, I found on a thread in the forums. It was helpful, but left me with unanswered questions. It seems that tutorials don't do a thurough job of explaining all the things the user could use. For one, I had no idea a class could use an array, I had to ask about it in the forum.

So I haven't finished it, I just have the first two blocks of the flow chart finished, and parts of the rest started. I messaged the person who did the tutorials and he said he would be more than happy at helping me do the window scripting so I can have information show up in the menu windows.



#Time Check
class Time_Check1
if $DAYA == 1
Dipolomacy_Eventer
end
end
#Establishes the settings for Factions
class Faction
def initialize
@status = "neutral"
@enemy = "none"
@taxes = 0
@diplomacy = 100
end
def status
@status
end
def status=(val)
@status = val
end
def enemy
@enemy
end
def enemy=(val)
@enemy = val
end
def ally
@ally
end
def ally=(val)
@ally = val
end

def taxes
@income
end
def taxes=(val)
@taxes = val
end
def vulnerability
@vulnerability
end
def vulnerability=(val)
@vulnerability = val
end
def diplomacy
@diplomacy
end
def diplomacy=(val)
@diplomacy = val
end
end




#Initialize Rome
$SenateOfRome = Faction.new
$SenateOfRome.taxes = 1000
$SenateOfRome.vulnerability = 50
$SenateOfRome.status = "War"
$SenateOfRome.enemy = ["Dacia", "Thracia", "Cappodcia", "Pontus Kingdom"]
$SenateOfRome.ally = ["Mauretania", "Egypt", "Osroene", "Mascat", "Galatian Confederacy", "Jerusalem", "Bosporan Kingdom"]
#Initialize Dacia
$Dacia = Faction.new
$Dacia.taxes = 50
$Dacia.vulnerability = 20
$Dacia.status = "War"
$Dacia.enemy = ["Senate Of Rome"]
$Dacia.ally = ["None"]
#Initialize Xiongnu
$Xiongnu = Faction.new
$Xiongnu.taxes = 700
$Xiongnu.vulnerability = 35
$Xiongnu.status = "War"
$Xiongnu.enemy = ["Han Empire"]
$Xiongnu.ally = ["Goguryeo", "Okjeo", "Buyeo", "Dongye"]
#Initialize Han Empire
$Han_Empire = Faction.new
$Han_Empire.taxes = 1200
$Han_Empire.vulnerability = 70
$Han_Empire.status = "War"
$Han_Empire.enemy = ["Xiongnu", "Goguryeo", "Okjeo", "Doongye", "Byeonhan", "Mahan", "Jinhan", "Japan", "Yuezhi"]
$Han_Empire.ally = ["None"]
#Initialize Buyeo
$Buyeo = Faction.new
$Buyeo.taxes = 200
$Buyeo.vulnerability = 40
$Buyeo.status = "War"
$Buyeo.enemy = ["Han Empire", "Goguryeo", "Okjeo", "Dongye"]
$Buyeo.ally = ["Xiongnu"]
#Initialize Goguryeo
$Goguryeo = Faction.new
$Goguryeo.taxes = 120
$Goguryeo.vulnerability = 30
$Goguryeo.status = "War"
$Goguryeo.enemy = ["Han Empire", "Buyeo", "Okjeo", "Dongyeo"]
$Goguryeo.ally = ["Xiongnu"]
#Initialize Okjeo
$Okjeo = Faction.new
$Okjeo.taxes = 150
$Okjeo.vulnerability = 15
$Okjeo.status = "War"
$Okjeo.enemy = ["Han Empire", "Goguryeo", "Buyeo", "Dongye"]
$Okjeo.ally = ["Xiongnu"]
#Initialize Yuezhi
$Yuezhi = Faction.new
$Yuezhi.taxes = 71
$Yuezhi.vulnerability = 40
$Yuezhi.status = "War"
$Yuezhi.enemy = ["Han Empire"]
$Yuezhi.ally = ["None"]
#Initialize Dongye
$Dongye = Faction.new
$Dongye.taxes = 600
$Dongye.vulnerability = 34
$Dongye.status = "War"
$Dongye.enemy = ["Han Empire", "Goguryeo", "Buyeo", "Okjeo"]
$Dongye.ally = ["Xiongnu"]
#Initialize Byeonhan
$Byeonhan = Faction.new
$Byeonhan.taxes = 150
$Byeonhan.vulnerability = 45
$Byeonhan.status = "War"
$Byeonhan.enemy = ["Han Empire", "Mahan", "Jinhan", "Japan"]
$Byeonhan.ally = ["None"]
#Initialize Mahan
$Mahan = Faction.new
$Mahan.taxes = 75
$Mahan.vulnerability = 67
$Mahan.status = "War"
$Mahan.enemy = ["Byeonhan", "Han Empire", "Jinhan", "Japan"]
$Mahan.ally = ["None"]
#Initialize Jinhan
$Jinhan = Faction.new
$Jinhan.taxes = 271
$Jinhan.vulnerability = 12
$Jinhan.status = "War"
$Jinhan.enemy = ["Byeonhan", "Han Empire", "Mahan", "Japan"]
$Jinhan.ally = ["None"]
#Initialize Japan
$Japan = Faction.new
$Japan.taxes = 126
$Japan.vulnerability = 23
$Japan.status = "War"
$Japan.enemy = ["Byeonhan", "Han Empire", "Jinhan", "Mahan"]
$Japan.ally = ["None"]
#Initialize Parthian Empire
$Parthian = Faction.new
$Parthian.taxes = 780
$Parthian.vulnerability = 40
$Parthian.status = "War"
$Parthian.enemy = ["Media", "Armenia", "Osorene", "Yadavas Kingdom"]
$Parthian.ally = ["None"]
#Initialize Yadavas Kingdom
$Yadavas = Faction.new
$Yadavas.taxes = 340
$Yadavas.vulnerability = 34
$Yadavas.status = "War"
$Yadavas.enemy = ["Parthian Empire", "Indo Scythian Confederacy", "Magadha dynasty"]
$Yadavas.ally = ["None"]
#Initialize Indo Scythian COnfederacy
$Scythia = Faction.new
$Scythia.taxes = 300
$Scythia.vulnerability = 24
$Scythia.status = "War"
$Scythia.enemy = ["Yadavas Kingdom"]
$Scythia.ally = ["Magadha Dynasty", "Satavahana"]
#Initialize Magadha Dynasty
$Magadha = Faction.new
$Magadha.taxes = 450
$Magadha.vulnerability = 45
$Magadha.status = "War"
$Magadha.enemy = ["Yadavas Kingdom"]
$Magadha.ally = ["Indo Scythian Confederacy"]
#Initialize Satavahana
$Satavahana = Faction.new
$Satavahana.taxes = 350
$Satavahana.vulnerability = 24
$Satavahana.status = "War"
$Satavahana.enemy = ["Pandyas"]
$Satavahana.ally = ["Kalinga Dynasty", "Chutus", "Cholas", "Ceras"]
#Initialize Kalinga Dynasty
$Kalinga = Faction.new
$Kalinga.taxes = 120
$Kalinga.vulnerability = 39
$Kalinga.status = "War"
$Kalinga.enemy = ["Pandyas"]
$Kalinga.ally = ["Satavahana", "Chutus", "Cholas", "Ceras"]
#Initialize Chutus
$Chutus = Faction.new
$Chutus.taxes = 241
$Chutus.vulnerability = 34
$Chutus.status = "War"
$Chutus.enemy = ["Pandyas"]
$Chutus.ally = ["Satavahana", "Kalinga Dynasty", "Cholas", "Ceras"]
#Initialize Cholas
$Cholas = Faction.new
$Cholas.taxes = 145
$Cholas.vulnerability = 45
$Cholas.status = "Peace"
$Cholas.enemy = ["None"]
$Cholas.ally = ["Satavahana", "Chutus", "Kalinga Dynasty", "Pandyas", "Ceras"]
#Initialize Pandyas
$Pandyas = Faction.new
$Pandyas.taxes = 134
$Pandyas.vulnerability = 34
$Pandyas.status = "War"
$Pandyas.enemy = ["Satavahana", "Chutus", "Kalinga Dynasty"]
$Pandyas.ally = ["Cholas", "Ceras"]
#Initizlize Ceras
$Ceras = Faction.new
$Ceras.taxes = 124
$Ceras.vulnerability = 24
$Ceras.status = "War"
$Ceras.enemy = ["Pandyas"]
$Ceras.ally = ["Satavahana", "Chutus", "Cholas", "Kalnga Dynasty"]
#Initialize Pyu
$Pyu = Faction.new
$Pyu.taxes = 34
$Pyu.vulnerability = 20
$Pyu.status = "Peace"
$Pyu.enemy = ["None"]
$Pyu.ally = ["Monn Cities", "Funan"]
#Initialize Monn Cities
$Monn = Faction.new
$Monn.taxes = 51
$Monn.vulnerability = 30
$Monn.status = "Peace"
$Monn.enemy = ["None"]
$Monn.ally = ["Pyu Cities", "Funan"]
#Initialize Funan
$Funan = Faction.new
$Funan.taxes = 32
$Funan.vulnerability = 34
$Funan.status = "Peace"
$Funan.enemy = ["None"]
$Funan.ally = ["Pyu Cities", "Monn Cities"]
#Initialize Mauretania
$Mauretania = Faction.new
$Mauretania.taxes = 43
$Mauretania.vulnerability = 32
$Mauretania.status = "Peace"
$Mauretania.enemy = ["None"]
$Mauretania.ally = ["Senate of Rome"]
#Initialize Thracia
$Thracia = Faction.new
$Thracia.taxes = 32
$Thracia.vulnerability = 21
$Thracia.status = "War"
$Thracia.enemy = ["Senate Of Rome"]
$Thracia.ally = ["None"]
#Initialize Sarmatian Confederacy
$Sarmatia = Faction.new
$Sarmatia.vulnerability = 32
$Sarmatia.status = "Peace"
$Sarmatia.enemy = ["None"]
$Sarmatia.ally = ["Bosporan Kingdom"]
#Initialize Galatian Confederacy
$Galatia = Faction.new
$Galatia.taxes = 53
$Galatia.vulnerability = 21
$Galatia.status = "Peace"
$Galatia.enemy = ["None"]
$Galatia.ally = ["Senate Of Rome"]
#Initialize Pontus Kingdom
$Pontus = Faction.new
$Pontus.taxes = 121
$Pontus.vulnerability = 32
$Pontus.status ="War"
$Pontus.enemy = ["Senate Of Rome", "Cappadocia", "Armenia"]
$Pontus.ally = ["Colchis", "Iberia"]
#Initialize Cappadocia
$Cappadocia = Faction.new
$Cappadocia.taxes = 34
$Cappadocia.vulnerability = 23
$Cappadocia.status = "War"
$Cappadocia.enemy = ["Senate Of Rome", "Pontus Kingdom", "Armenia", "Osroene"]
$Cappadocia.ally = ["None"]
#Initialize Bosporan Kingdom
$Bospora = Faction.new
$Bospora.taxes = 56
$Bospora.vulnerability = 34
$Bospora.status = "Peace"
$Bospora.enemy = ["None"]
$Bospora.ally = ["Sarmatian Confederacy"]
#Initialize Colchis
$Colchis = Faction.new
$Colchis.taxes = 32
$Colchis.vulnerability = 25
$Colchis.status = "War"
$Colchis.enemy = ["Iberia"]
$Colchis.ally = ["Pontus Kingdom"]
#Initialize Iberia
$Iberia = Faction.new
$Iberia.taxes = 24
$Iberia.vulnerability = 34
$Iberia.status = "War"
$Iberia.enemy = ["Colchis", "Armenia", "Albania"]
$Iberia.ally = ["Pontus Kingdom"]
#Initialize Armenia
$Armenia = Faction.new
$Armenia.taxes = 54
$Armenia.vulnerability = 24
$Armenia.status = "War"
$Armenia.enemy = ["Pontus Kingdom", "Cappadocia", "Iberia", "Albania", "Media"]
$Armenia.ally = ["None"]
#Initialize Albania
$Albania = Faction.new
$Albania.taxes = 24
$Albania.vulnerability = 34
$Albania.status = "War"
$Albania.enemy = ["Iberia", "Armenia", "MEdia", "Parthian Empire"]
$Albania.ally = ["None"]
#Initialize Media
$Media = Faction.new
$Media.taxes = 134
$Media.vulnerability = 24
$Media.status = "War"
$Media.enemy = ["Parthian Empire", "Armenia", "Albania"]
$Media.ally = ["None"]
#Initialize Osroene
$Osroene = Faction.new
$Osroene.taxes = 99
$Osroene.vulnerability = 29
$Osroene.status = "War"
$Osroene.enemy = ["Parthian Empire"]
$Osroene.ally = ["Senate Of Rome", "Mascat"]
#Initialze Mascat
$Mascat = Faction.new
$Mascat.taxes = 101
$Mascat.vulnerability = 30
$Mascat.status = "Peace"
$Mascat.enemy = ["None"]
$Mascat.ally = ["Senate Of Rome", "Osroene"]
#Initialize Jerusalem
$Jerusalem = Faction.new
$Jerusalem.taxes = 204
$Jerusalem.vulnerability = 49
$Jerusalem.status = "War"
$Jerusalem.enemy = ["Nabatene"]
$Jerusalem.ally = ["Senate Of Rome"]
#Initialize Nabatane
$Nabatane = Faction.new
$Nabatane.taxes = 124
$Nabatane.vulnerability = 21
$Nabatane.status = "War"
$Nabatane.enemy = ["Jerusalem", "Egypt"]
$Nabatane.ally = ["None"]
#Initialize Egypt
$Egypt = Faction.new
$Egypt.taxes = 1354
$Egypt.vulnerability = 32
$Egypt.status = "War"
$Egypt.enemy = ["Mascat", "Kush Kingdom"]
$Egypt.ally = ["Senate Of Rome"]
#Initialize Kush Kingdom
$Kush = Faction.new
$Kush.taxes = 345
$Kush.vulnerability = 24
$Kush.status = "War"
$Kush.enemy = ["Egypt", "Aksum Kingdom"]
$Kush.ally = ["None"]
#Initialize Aksum Kingdom
$Aksum = Faction.new
$Aksum.taxes = 124
$Aksum.vulnerability = 29
$Aksum.status = "War"
$Aksum.enemy = ["Egypt", "Kush Kingdom", "Himyarites"]
$Aksum.ally = ["None"]
#Initialize Himyarites
$Himyarites = Faction.new
$Himyarites.taxes = 98
$Himyarites.vulnerability = 32
$Himyarites.status = "War"
$Himyarites.enemy = ["Aksum Kingdom"]
$Himyarites.ally = ["None"]
#Initialize Garamentes
$Garamentes = Faction.new
$Garamentes.taxes = 34
$Garamentes.vulnerability = 25
$Garamentes.status = "War"
$Garamentes.enemy = ["Senate Of Rome"]
$Garamentes.ally = ["None"]
#Initialize Teotihuacan
$Teotihuacan = Faction.new
$Teotihuacan.taxes = 34
$Teotihuacan.vulnerability = 19
$Teotihuacan.status = "War"
$Teotihuacan.enemy = ["Totonac", "Maya"]
$Teotihuacan.ally = ["Tarascan", "Mixtec", "Zapotec"]
#Initialize Tarascan
$Tarascan = Faction.new
$Tarascan.taxes = 120
$Tarascan.vulnerability = 20
$Tarascan.status = "War"
$Tarascan.enemy = ["Totonac", "Maya"]
$Tarascan.ally = ["Teotihuacan", "Mixtec", "Zapotec"]
#Initialize Totonac
$Totonac = Faction.new
$Totonac.taxes = 90
$Totonac.vulnerability = 30
$Totonac.status = "War"
$Totonac.enemy = ["Tarascan", "Teotihuacan", "Maya", "Mixtec", "Zapotec"]
$Totonac.ally = ["None"]
#Initialize Maya
$Maya = Faction.new
$Maya.taxes = 121
$Maya.vulnerability = 20
$Maya.status = "War"
$Maya.enemy = ["Tarascan", "Teotihuacan", "Totonac", "Mixtec", "Zapotec"]
$Maya.ally = ["None"]
#Initialize Mixtec
$Mixtec = Faction.new
$Mixtec.taxes = 57
$Mixtec.vulnerability = 30
$Mixtec.status = "War"
$Mixtec.enemy = ["Maya", "Totonac", "Zapotec"]
$Mixtec.ally = ["Tarascan", "Teotihuacan"]
#Initialize Zapotec
$Zapotec = Faction.new
$Zapotec.taxes = 103
$Zapotec.vulnerability = 27
$Zapotec.status = "War"
$Zapotec.enemy = ["Maya", "Totonac", "Mixtec"]
$Zapotec.ally = ["Tarascan", "Teotihuacan"]

#Initialize

event = nil

if Input.press?(:C) == true
Time_Check1
end
#Diplomacy Eventer
#Set Cycle for Event to every 7 days

if event == nil
event = true
end
if event == true
$SenateOfRome.diplomacy = rand($SenateOfRome.vulnerability )
$Dacia.diplomacy = rand($Dacia.vulnerability)
end
p $SenateOfRome
p $Dacia


#Diplomacy for Senate of Rome
if event == true
if $SenateOfRome.diplomacy > 20
if $Dacia.diplomacy <= $SenateOfRome.diplomacy
if $SenateOfRome.enemy != "Dacia"
$SenateOfRome.enemy += ["Dacia"]
$Dacia.enemy = "Senate of Rome"
$SenateOfRome.status = "War"
$Dacia.status = "War"
end
else
if $SenateOfRome == $Dacia.diplomacy
if $SenateOfRome.enemy == "Dacia"
$SenateOfRome.enemy -= ["Dacia"]
$Dacia.enemy -= ["Senate of Rome"]
end
end
end
event = nil
end

p $SenateOfRome

 

 

 

So it's rather long, but should be explainable somehow. I'm still working out the mechanics and formulas for the diplomacy event. But I have some questions.

In the Flow Chart I have included, how do I have the Faction Maintence automatically update every seven days in game? How do I do script calls? I used global variables so I think that would help.

 

What are modules, and how can they help with this script?

post-60764-0-29214600-1442797238_thumb.png

post-60764-0-52930600-1442797283_thumb.png

Edited by chungsie

Share this post


Link to post
Share on other sites

Eeeep... Your code formatting isn't that good... did it mess up when posted?

 

Anyway, you should know that unless you explicitly modify the DataManager module to do it, nothing will be saved in saved games or reset on a new game for that matter. It's a very very bad idea therefor to use a whole bunch of globals for eevrything. Try putting everything in a hash instead!

 

I think this will work:

$factions = {} # temp, should create/set this in DataManager with all the $game_ globals.
 
$factions[:SenateOfRome] = Faction.new

$factions[:SenateOfRome].taxes = 1000

$factions[:SenateOfRome].vulnerability = 50

$factions[:SenateOfRome].status = "War"

$factions[:SenateOfRome].enemy = ["Dacia", "Thracia", "Cappodcia", "Pontus Kingdom"]

$factions[:SenateOfRome].ally = ["Mauretania", "Egypt", "Osroene", "Mascat", "Galatian Confederacy", "Jerusalem", "Bosporan Kingdom"]
You could actually completely do away with the need for a class if you are only storing data with nested hashes, but classes are nice too. :3 Edited by KilloZapit

Share this post


Link to post
Share on other sites

i really don't understand how data manager works. the scripter that is helping me make the information appear in game in window, is telling me to use $ for making global for saves.

Share this post


Link to post
Share on other sites

An easy way I've found to understand the DataManager (while not entirely accurate but for all intents and purposes here it works) is that it stores all current values of all variables, arrays, states, etc and is what is called upon when resuming a saved game or starting a fresh one. In your case you'd want the arrays to be saved and loaded upon returning to a saved game but when the classes are loaded and ran, since these variables aren't loaded into the DataManager properly to begin with they'll start fresh each time. That is bad, obviously.

Share this post


Link to post
Share on other sites

i really don't understand how data manager works. the scripter that is helping me make the information appear in game in window, is telling me to use $ for making global for saves.

Well they are either wrong or misleading. Using $ for globals is only for the program state (and is usually considered bad practice even for that), you have to mess around with DataManager to save things in saved games.

 

It's a pretty common mistake to make really, most people don't understand how globals work.

Edited by KilloZapit

Share this post


Link to post
Share on other sites

so can you please explain how the scrpt snippet you offered works? I'd like to understand better.

Share this post


Link to post
Share on other sites

Oh! It uses a hash, which is like an array (an array is a list list like ["Dacia", "Thracia", "Cappodcia", "Pontus Kingdom"] if you didn't know) except instead of looking things up by index number you can use anything as a "key". And :SenateOfRome is a symbol, which is kinda like a string (a string is anything with quotes like "War") except that each symbol is unique and can't be modified, which makes them a lot faster and ideal for when ever you want to have a unique identifier.

Share this post


Link to post
Share on other sites

No you can. Hashes can be changed all you want. Sorry if I was confusing you about symbols, thats a totally different thing.

Share this post


Link to post
Share on other sites

so say I used $Factions[:SenateOfRome].enemies and I wanted to know if thracia was an enemy, I would just do
if $Factions[:SenateOfRome].enemies = "Thracia"

code

end

?

would you consider being my teacher for scripting? I could use someone with more experience than i have in scripting. I actually got a reply to the recruitment topic, and we now have a scripter, but he's new to Ruby and ACE VX. unless you would rather join the team?

 

Share this post


Link to post
Share on other sites

Well, first you should use == not = in if staements, but more importantly since .enemies is an array you can't just compare it like that. Try

 

if $Factions[:SenateOfRome].enemies.include?("Thracia")

  code

end

 

Hehe, I am not sure I am much of a teacher, and I think I would be too lazy to work in a team... maybe you should read this instead! It has cartoon foxes!

Edited by KilloZapit

Share this post


Link to post
Share on other sites

how do I set a max for a variable? if I want vulnerability to not go above 100? and same with min. if I want it to not go below 0

Share this post


Link to post
Share on other sites

The fastest way to achieve max and min values would be follwing:

[actual_variable, max_variable].min -> actual_variable won't go above the set maximum

[actual_variable, min_variable].max -> actual_variable won't go below the set minimum

 

So for example following:

# I want a variable for enemy's vulnerability, but it should not go above 100 or below 0
@vulnerability = [[@enemy.vulnerability, 0].max, 100].min
# this would be a one-liner

You could also write a multiliner like

@vulnerability = enemy.vulnerability
@vulnerability = 0 if @vulnerability < 0
@vulnerability = 100 if @vulnerability > 100

Share this post


Link to post
Share on other sites

do i need to use hashes to make data storage and retrieval work? or can I use classes as is?

Share this post


Link to post
Share on other sites

You can use classes if you want sure, a hash is just another class of object after all.

Share this post


Link to post
Share on other sites

the team is currently creating the list for all cities in the game, and I will need to add that to the script, so I can have effects for each city.

if I use the hash it will make things easier?

Share this post


Link to post
Share on other sites

Maybe... thing about hashes is that you can always add any sort of value to them by name without explicitly defining methods like with classes. But it depends on what works best for you!

Share this post


Link to post
Share on other sites

so if I used hashes like you examplified. would I just use a save and load function for $faction? or would I have to do each hash? would save and load for a hash be easier than using classes?

Share this post


Link to post
Share on other sites

Well if you did it like my example, you could put a hash in $factions and classes in the hash, and you would only need a save/load thing for $factions then because it would be all in one place you see?

Share this post


Link to post
Share on other sites

ok cool. I will definitely work on rewriting everything.

I am afraid of figuring out the mechanics for how factions interact with another.

would I be able to make $habitation a hash? as I need to be able to keep track of cities.

Share this post


Link to post
Share on other sites

Sure, you cpould use any name you want, and as many hashes as you want. Just remember that for each $ variable you have to make it so it saves and loads it!

Share this post


Link to post
Share on other sites

when I get that far, would you be able to walk through with me on how to do the load and save? and how to make it work when something happens?

Share this post


Link to post
Share on other sites

I will try... it's not really that complected to save things. Do you know how to alias things yet?

Share this post


Link to post
Share on other sites

er... no... I mean

 

like giving a method a new name like:

 

alias new_name old_name

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted