Sorry for the long post, the spoilers wont work for me for some reason.
This is a collection of my creations, I'm putting these up as templates for you to modify to your own needs.
The leveling
This is the level up script, you can read the comments to modify it.
--[[
script version: 0.1
MANY ORCS WERE CAPTURED AND KILLED IN THE MAKING OF THIS SCRIPT, REMEMBER THEM WHEN YOU ARE LEVELING!
This will add leveling up and random skill gain into your game THE SKILLS ARE IN BUT MEAN AND DO NOTHING
the code that can be modified is heavily commented, otherwise you shouldn't change it unless you know
what you are doing and before changing anything make sure to save a backup for if you break it.
to jump straight to the sections you can press ctrl + f to search and type the chapter you want to go to.
chapter001 - stats
chapter002 - player xp
chapter003 - monster xp
chapter004 - adding levels
--]]
--variable declaration--------------------------------------------------------
g_stats_system = {} -- the players current stats
g_exp = {} -- the xp table or xp you need to level
g_monster_xp_list = {} -- the xp list for the monsters 1 is orc, he gives g_monster_xp_list[1] xp.
g_perk_system = {}
g_xp_gain = 100
g_level_up = false
local level = true
local timer = 0
local show_level_up_prompt = false
local level_one = true
local level_two = false
local level_three = false
local level_four = false
--panel location
local p_x1 = 60
local p_y1 = 90
local p_x2 = 70
local p_y2 = 100
--text position
local level_textx = 66
local level_texty =95
local xp_textx = 62
local xp_texty = 95
local text_size = 1
--this is the random amount to add to the skills after leveling up
--you can change this number if you want something else its something
--at the moment but later you will be able to choose what you want.
local r = math.random(5)
function character_stats_init(e)
end
--[[
chaprer001
this is where you define your players stat levels, if you want more or less keep the
number sequence
skill_name, -- comment with the next number like the next skill will be 7.skill_name
and to refrence your skill you use
g_stats_system[what ever number the stat is]
--]]
g_stats_system = {
0, -- 1 xp
1, -- 2 level
1, -- 3 str
1, -- 4 def
1, -- 5 spd
1, -- 6 lck
1 -- perk points
}
--[[
chapter002
this is the xp till next level to add them you would just like above and the n in this g_exp[n]
so for level 1 is g_exp[1]
--]]
g_exp = {
100, -- to level 2
350, -- to level 3
690, -- to level 4
900, -- to level 5
180, -- to level 6
2500, -- to level 7
2900, -- to level 8
3600, -- to level 9
4000, -- to level 10
}
--[[
chapter003
this is how much xp monsters give the player for killing them
just like above but every number is the xp the monster gives
--]]
g_monster_xp_list = {
15, --1.fast zombies
25, --2.hard hitters
50 --
}
g_perk_system = {
0, -- survivor - this will give more hp when taking health packs
0,
0
}
--[[
chapter004
in order to add more levels you must add another if to the list, you can copy everything below
elseif g_stats_system[1] == g_exp[5] then
if g_stats_system[2] == 5 then
g_level_up = true
end
end
IF THIS IS COMPLICATED FOR YOU SAVE A BACK UP BEFORE YOU MODIFY OR EDIT.
--]]
function character_stats_main(e)
--display level and xp
TextCenterOnX(level_textx,level_texty,text_size,"Level: "..g_stats_system[2])
TextCenterOnX(xp_textx,level_texty,text_size,"XP: "..g_stats_system[1])
Panel(p_x1,p_y1,p_x2,p_y2)
-- the leveling if!
if g_stats_system[1] >= g_exp[1] and g_stats_system[2] == 1 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[2] and g_stats_system[2] == 2 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[3] and g_stats_system[2] == 3 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[4] and g_stats_system[2] == 4 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[5] and g_stats_system[2] == 5 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[6] and g_stats_system[2] == 6 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[7] and g_stats_system[2] == 7 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[9] and g_stats_system[2] == 8 then
g_level_up = true
elseif g_stats_system[1] >= g_exp[9] and g_stats_system[2] == 9 then
g_level_up = true
end
if g_level_up == true then
g_stats_system[2] = g_stats_system[2] + 1
g_stats_system[3] = g_stats_system[3] + r
g_stats_system[4] = g_stats_system[4] + r
g_stats_system[5] = g_stats_system[5] + r
g_stats_system[6] = g_stats_system[6] + r
PlayNon3DSound(e,0)
timer = 0
PromptDuration("You have leveled up to " ..g_stats_system[2],2000)
g_level_up = false
end
end
--[[
CREDITS
soneproject - FOR THE LEVEL UP SOUND OBTAINED FROM FREESOUND.ORG
--]]
Add this to any of the enemies exit functions and change the g_monster_xp_list variable to what ever enemy you want in the main script.
if ai_soldier_state[e]~= "deathanim" then
g_stats_system[1] = g_stats_system[1] + g_monster_xp_list[1]
end
3. basic inventory system - This is considered done and you can get them from below. All of my scripts are as is and are free for any type of project. I plan to get a video of these. If anyone would like to use them but is having trouble with them ask here and ill help you out. The icons are place holders I made so you dont need them. You will have to change the path in the main_inv script. Added the icons I didn't upload them before completeing the last edit.
The scripts for the inventory
I have finished the inventory scripts ( there is eight) there is A item script for the items ( medkits, money, flashlight, batteries) A loot script for searching for money in furniture, There is a medkit merchant to sell you a set number of medkits.
Screenshots of the inventory
main inventory script - this is what actually handles the inventory, its functions, and the sprites.
--[[
This is what goes inside of a dynamic always active entity. the script itself isn't that hard at all to read ill comment some of this stuff later.
--]]
g_medkits = 0
g_max_medkits = 10
g_money = 0
g_flashlight = false
g_flashlight_battery = 0
g_battery_drain = 100
g_player_hp_max = 100
g_player_current_hp = g_PlayerHealth
--for the hp icon
--text location
local hp_tex_posx = 6
local hp_tex_posy = 82
local hp_text_size = 20
--sprite location
local hp_spr_posx = 2
local hp_spr_posy = 79
--sprite size
local hp_spr_sizex = 3
local hp_spr_sizey = 5
--for the money icon
--text location
local money_tex_posx = 10
local money_tex_posy = 82
local money_text_size = 20
--sprite location
local money_spr_posx = 7
local money_spr_posy = 79
--sprite size
local money_spr_sizex = 3
local money_spr_sizey = 5
--for the flashlight icon
--sprite location
local flon_spr_posx = 12
local flon_spr_posy = 79
--sprite size
local flon_spr_sizex = 3
local flon_spr_sizey = 5
local floff_spr_sizex = 3
local floff_spr_sizey = 5
--for the battery drain
--text location
local battery_tex_posx = 15
local battery_tex_posy = 82
local battery_text_size = 20
--for batter count
--text
local batt_tex_posx = 21
local batt_tex_posy = 82
local batt_text_size = 20
--sprite location
local batt_spr_posx = 18
local batt_spr_posy = 79
--sprite size
local batt_spr_sizex = 3
local batt_spr_sizey = 5
local btn_pressed = 0
function main_inv_init(e)
SetFlashLightKeyEnabled(0)
-- for the hp icon
health_sprite = LoadImage("scriptbank\\images\\Marks\\000.png")
health_icon = CreateSprite(health_sprite)
SetSpriteSize (health_icon,hp_spr_sizex,hp_spr_sizey)
SetSpriteDepth (health_sprite, 100)
-- for the money
money_sprite = LoadImage("scriptbank\\images\\Marks\\001.png")
money_icon = CreateSprite(money_sprite)
SetSpriteSize (money_icon,money_spr_sizex,money_spr_sizey)
SetSpriteDepth (money_sprite, 100)
-- for the floff icon
flon_sprite = LoadImage("scriptbank\\images\\Marks\\002.png")
flon_icon = CreateSprite(flon_sprite)
SetSpriteSize (flon_icon,flon_spr_sizex,flon_spr_sizey)
SetSpriteDepth (flon_sprite, 100)
-- for the flon icon
floff_sprite = LoadImage("scriptbank\\images\\Marks\\003.png")
floff_icon = CreateSprite(floff_sprite)
SetSpriteSize (floff_icon,flon_spr_sizex,flon_spr_sizey)
SetSpriteDepth (floff_sprite, 100)
-- for the battery icon
batt_sprite = LoadImage("scriptbank\\images\\Marks\\004.png")
batt_icon = CreateSprite(batt_sprite)
SetSpriteSize (batt_icon,batt_spr_sizex,batt_spr_sizey)
SetSpriteDepth (batt_sprite, 100)
end
function main_inv_main(e)
--start of hp code-------------------------------------------------------------------------
if g_medkits >= 1 then
Text(hp_tex_posx,hp_tex_posy,1,""..g_medkits)
SetSpritePosition(health_icon,hp_spr_posx,hp_spr_posy)
else
SetSpritePosition(health_icon,300,300)
end
if g_medkits > 0 and btn_pressed == 1 and g_PlayerHealth < g_player_hp_max then
SetPlayerHealth(g_PlayerHealth+50)
PromptDuration("You used A medkit",1000)
g_medkits = g_medkits - 1
elseif GetScancode() == 44 and g_medkits <= 0 then
PromptDuration("You don't have any medkits.",1000)
end
if GetScancode() == 44 then
btn_pressed = 1
else
btn_pressed = 0
end
if g_PlayerHealth > g_player_hp_max then
--g_PlayerHealth = g_player_hp_max
SetPlayerHealth(g_player_hp_max)
end
--end of hp code-----start of money code--------------------------------------------------------
if g_money >= 1 then
Text(money_tex_posx,money_tex_posy,1,""..g_money)
SetSpritePosition(money_icon,money_spr_posx,money_spr_posy)
else
SetSpritePosition(money_icon,300,300)
end
--end of money code===start of flashlight==============================================================
if g_flashlight == true then
if g_PlayerFlashlight == 1 then
Text(battery_tex_posx,battery_tex_posy,1,"%"..g_battery_drain) -- battery drain
SetSpritePosition(flon_icon, flon_spr_posx, flon_spr_posy)
SetSpritePosition(floff_icon,300,300)
elseif g_PlayerFlashlight == 0 then
SetSpritePosition(floff_icon,flon_spr_posx,flon_spr_posy)
SetSpritePosition(flon_icon,300,300)
end
else
SetSpritePosition(flon_icon,300,300)
SetSpritePosition(floff_icon,300,300)
end
--flashlight end start of battery-----------------------------------------------------------------------------
if g_flashlight_battery > 0 then
Text(batt_tex_posx,batt_tex_posy,1,""..g_flashlight_battery)
SetSpritePosition(batt_icon,batt_spr_posx,batt_spr_posy)
else
SetSpritePosition(batt_icon,300,300)
end
end
the medkit objects, put this in the medkit entity, or what ever entity your using to give your player health.
--[[
this script is the medkit loot script, when you see a medkit you will pick it up and
it will add one medkit to your inventory.
--]]
local full_medkits = "Your medkit pouch is full."
function loot_medkit_init(e)
end -- end init
function loot_medkit_main(e)
pdist = GetPlayerDistance(e)
if pdist < 100 then
Prompt("Press E to collect Medkit")
end
if g_KeyPressE == 1 and pdist < 100 and g_medkits < g_max_medkits then
g_medkits = g_medkits + 1
PromptDuration("You picked up a Medkit", 3000)
Destroy(e)
elseif g_medkits == g_max_medkits then
PromptDuration(full_medkits,1000)
end
end -- main
This is the money script, put this script into what ever entity your money is and he will be given a random amount.
--[[
This script is the money item, when the player picks this up he will be given a random amount of money?
--]]
local min_loot = 10 -- the smallest amount to loot
local max_loot = 20 -- the largest amount to loot
local rand = math.random(min_loot,max_loot)
function loot_money_init(e)
end -- end init
function loot_money_main(e)
pdist = GetPlayerDistance(e)
if pdist < 50 then
Prompt("Press E to collect Money")
end
if g_KeyPressE == 1 and pdist < 100 then
--if g_PlayerHealth < 70 then
g_money = g_money + rand
PromptDuration("You picked up " .. rand .." money", 3000)
Destroy(e)
--end
end
end -- main
This is the flashligth script. you put this into your flashlight entity.
--This is so the User Can't use the flash light until he obtains
--the flashlight
-- Later on this will put one flash light in the inventory, you can only have one light in your inventory...
function flight_init(e)
end -- init
function flight_main(e)
pdist = GetPlayerDistance(e)
if pdist < 80 then
Prompt("Press E to collect flashlight")
end
if g_KeyPressE == 1 and pdist < 80 then
SetFlashLightKeyEnabled(1)
PromptDuration("You now have the Flashlight", 3000)
Destroy(e)
PromptDuration("Press F to Toggle The Flash light.",10000)
g_flashlight = true
elseif g_flashlight == true then
PromptDuration("You already have a Flashlight.",1000)
end
end -- main
this is the flashlight battery script, I dont have any flashlight entities so i put this on calculators and other things with batteries and made the player think he was stealing batteries out of those objects, gave me a sense of survival and resourcefulness.
--[[
Battery item, put this script on any battery object or something you can steal the batteries from
and it will give you batteries.
--]]
local obtained_battery = "You found A battery."
local collect_batteries = "Press E to take this items batteries."
function item_battery_init(e)
end -- end init
function item_battery_main(e)
pdist = GetPlayerDistance(e)
if pdist < 100 then
Prompt(collect_batteries)
end
if g_KeyPressE == 1 and pdist < 100 then
g_flashlight_battery = g_flashlight_battery + 1
PromptDuration(obtained_battery, 3000)
Destroy(e)
end
end -- main
this script makes entities loot able for money.
--[[
This script will make any object searchable for money with minor configuring.
--]]
local loot_message = "Press E to search for Money"
local found_money = "You picked up Money"
local money_looted = "There is nothing else here."
local rand = math.random(1,100)
local looted = 0
local btn_pressed = 0
function loot_money_search_init(e)
end -- init
function loot_money_search_main(e)
pdist = GetPlayerDistance(e)
if pdist <= 80 and looted == 0 then
Prompt(loot_message)
end
if pdist < 80 and g_KeyPressE == 1 and btn_pressed == 0 and looted == 0 then
g_money = g_money + rand
PromptDuration(found_money .. rand, 3000)
looted = 1
elseif looted == 1 and g_KeyPressE == 1 and pdist < 80 then
PromptDuration(money_looted,1000)
end
if g_KeyPressE == 1 then
btn_pressed = 1
elseif g_KeyPressE == 0 then
btn_pressed = 0
end
end -- main
this is the battery controller script, this will need to be in a dynamic object and always on.
--[[
This is what controls the battery drain, put it in A dynamic, yet always on object.
--]]
local timer = 0
local no_battery = "You have ran out of batteries."
function main_battery_cont_init(e)
end -- end init
function main_battery_cont_main(e)
--[[
--drain the battery, and then take one point of battery life
if g_PlayerFlashlight == 1 then --and g_flashlight_battery > 0 then
StartTimer(e)
if GetTimer(e) >= 1000 then
g_battery_drain = g_battery_drain - 1
StartTimer(e)
end
--]]
if g_PlayerFlashlight == 1 and g_battery_drain > 0 then
if timer == 0 then
StartTimer(e)
timer = 1
g_battery_drain = g_battery_drain - 1
end
if timer == 1 and GetTimer(e) >= 500 then--1000 then
timer = 0
end
end
--Prompt("timer " .. GetTimer(e)) -- for debugging
--change batteries if you have some
if g_battery_drain == 0 and g_flashlight_battery > 0 then
SetFlashLightKeyEnabled(1)
g_flashlight_battery = g_flashlight_battery - 1
g_battery_drain = 100
elseif g_battery_drain == 0 and g_flashlight_battery == 0 then
SetFlashLight(0)
PromptDuration(no_battery,3000)
SetFlashLightKeyEnabled(0)
end
end --main
4. NPC talking system - My basic npc talking system is now done, granted this is a WIP, all I got at the moment is Two scripts. The first script is the database, the scripts with the table that will hold the dialog. I wanted this in its own script because it could get quite long. The second script goes in the npc entity. Pretty much all it does is get the entity name and prompt the dialog from the message script. THIS HAS NO AI, and just prompts text depending on what your entities name is. for making npc dialog easier to manage.
this script will house all the dialog for all the characters, all you have to do is name the character entity and put the name of the entity and what you want he/she to say.
--[[
this script will house all the dialog for all the characters,
all you have to do is name the character entity and put the name of the entity
and what you want he/she to say tlike below.
entity name = "dialog"
--]]
g_dialog = {}
g_npc_dialog = {}
function npc_message_init_name(e,name)
--g_name[e] = name -- for future refrence you can delete this if you like
end -- end init
function npc_message_main(e)
g_npc_dialog = {
anthony = "Hello there.",
joe = "hey you need to be careful out there!"
}
end -- main
unless you want the distance changed this script don't need changed you can put this script in the npc and it will work.
--[[
unless you want the distance changed this script dont need changed
you can put this script in the npc and it will work.
THIS MAKES THE CHARACTER STAND STILL THERE IS NO AI TO THIS SCRIPT MORE OF LIKE
A TOWN STRANDING NPC.
--]]
--variables
g_name = {}
--show the text
local npc_dialogx = 50
local npc_dialogy = 50
--show the npc name
local npc_namex = 60
local npc_namey = 60
--text size......
local npc_name_size = 1
local npc_dialog_size = 5
function name_script_init_name(e,name)
g_name[e] = name
end
function name_script_main(e)
pdist = GetPlayerDistance(e)
if pdist <= 80 then
Text(npc_namex,npc_namey,npc_name_size,""..g_name[e])
TextCenterOnX(npc_dialogx,npc_dialogy,npc_dialog_size,""..g_npc_dialog[g_name[e]])
end
end
Some screenshots of the npc scripts but there isn't much to see.
Here is a quick implementation of hunger and thirst, and two scripts for the food and water items.
Hunger and thirst will gradually go down in random increments, and when you eat and drink they will go up in random increments.
Main survival script
--this will display the hunger and thirst for the player to see
--[[
this is the timers for the hunger and thirst to go down .
--]]
tbl_timer = {}
--[[
these are global so that you can take my stats script or other scripts
and change these values there like when you level up you may want to give yourself
more hunger or thirst, or you may want to make it as you level up you dont get hungry so fast.
--]]
g_hunger = 100
g_thirst = 100
g_food_amount = math.random(10,20) -- this is how much food you get for finding food
g_take_hunger = math.random(5,30) -- to take hunger away
g_hunger_timer = math.random(5000,60000) -- miliseconds
g_water_amount =math.random(10,20) -- this is how much water you get for finding water
g_take_water = math.random(5,30) -- take water away
g_water_timer = math.random(5000,60000) -- miliseconds
function survival_init(e)
-- start timers
GlobalTimerStart(1)
GlobalTimerStart(2)
end
function survival_main(e)
--Text(1, 1, 1, "Global Timer 1: " .. tostring(GlobalTimerGet(1)))
Text(1, 5, 1, "hunger: " .. g_hunger)
Text(1, 10, 1, "water: " .. g_thirst)
-- reset every 5 seconds
if GlobalTimerGet(1) >= g_hunger_timer then
GlobalTimerStart(1)
g_hunger = g_hunger - math.random(10,25)--g_take_hunger
end
if GlobalTimerGet(2) >= g_water_timer then
GlobalTimerStart(2)
g_thirst = g_thirst - math.random(10,25)--g_take_water
end
end
function GlobalTimerStart(Timer)
tbl_timer[Timer]=g_Time
end
function GlobalTimerGet(Timer)
return math.abs(tbl_timer[Timer]-g_Time)
end
food item
--this is the script you put inside the food items to make the player "eat" teh entity.
function give_food_init(e)
end
local got = false
function give_food_main(e)
PlayerDist = GetPlayerDistance(e)
if PlayerDist <= 80 then
Prompt("Press E to pick up food")
end
if PlayerDist <= 80 then --default 80
if g_KeyPressE == 1 then
PromptDuration("You ate some food",3000)
PlaySound(e,0)
g_hunger = g_hunger + g_food_amount
got = true
Destroy(e)
end
end
end
water item
--put this in the water item that you want the player to "drink"
function give_water_init(e)
end
function give_water_main(e)
pdist = GetPlayerDistance(e)
if pdist < 100 then
Prompt("Press E to drink from well")
end
if g_KeyPressE == 1 and pdist <= 80 then
if g_thirst < 100 then
PromptDuration("You drank from the well", 3000)
g_thirst = g_thirst + g_water_amount
Destroy(e)
elseif g_thirst >= 100 then
PromptDuration(" You don't need A drink right now.",1000)
end
end
end -- main
Markchapman10 is my Skype let's have some dev talk.