Hi again!
--EDIT--
Re-did all the scripts to use utillib to detect when player is looking at entity.
Merged the upgrades into one script.
Changed the money script to use the name of the entity as the amount of money given.
----
So I've been working on some more scripts, these includes:
Simple Status HUD:
-- Place this script on any object. Make sure it is always active and not static.
g_PlayerMoney = 0
g_Upgrade_Speed = 0
g_Upgrade_Jump = 0
g_Save_Jump = 220 --Jump height starting value, same as default in GG. Can be changed and will take effect on level start.
g_Save_Speed = 0.75 --Same with this only the max speed^^
g_StatsHudOpen = 0
function iid_stats_hud_main(e)
--Makes the upgrades correct when loading saves as they get reset otherwise
SetGamePlayerControlMaxspeed(g_Save_Speed)
SetGamePlayerControlJumpmax(g_Save_Jump)
--Open/close HUD by use of the J button
if GetTimer(e) > 300 then
if g_KeyPressJ == 1 and g_StatsHudOpen == 0 then
StartTimer(e)
g_StatsHudOpen = 1
end
end
if GetTimer(e) > 300 then
if g_KeyPressJ == 1 and g_StatsHudOpen == 1 then
StartTimer(e)
g_StatsHudOpen = 0
end
end
--The HUD
if g_StatsHudOpen == 1 then
Text(0,2,1,"Stats: ")
Text(0,4,1,"Money: " .. g_PlayerMoney)
Text(0,10,1,"Upgrades: ")
Text(0,14,1,"Speed: Level " .. g_Upgrade_Speed)
Text(0,16,1,"Jump: Level " .. g_Upgrade_Jump)
end
end
Which does pretty much what it says above. Simple as it can get, but it works! It links up with some other scripts coming now!
Money:
--Requires iid_stats_hud.lua
--Add this to an entity to act as money
--Name the entity the ammount of money to be collected. ex. "100"
local U = require "scriptbank\\utillib"
function iid_money_init_name(e,name)
weapon_name[e] = name
end
function iid_money_main(e)
--Checks if player is looking at the money
if U.PlayerLookingAt(e, 100) == true and g_PlayerHealth > 0 then
TextCenterOnX(50,68,1,"Press E to pick up money")
end
--Checks if player is looking at the money and presses E on the money
if U.PlayerLookingAt(e, 100) == true and g_KeyPressE == 1 then
PlaySound(e,0)
g_PlayerMoney = g_PlayerMoney + tonumber(weapon_name[e]) --Adds the ammount of money gained to the global variable g_PlayerMoney
Destroy(e)
PromptDuration("You picked up ".. weapon_name[e] .. "$", 1000) -- Tells the player how much money is collected
end
end
A pretty simple script that you can place on an item, when activated with E the player gets an amount of money equal to the name of the entity. So if you name the entity "50", the player will receive 50$.
Now so far all you've got is a way to make a number go up, we need something to actually spend the money on in my opinion. Here comes the..
Weapon Purchase System
--Place this on a weapon and the player cannot pick it up unless he has enough money for it.
--Requires iid_stats_hud.lua
local U = require "scriptbank\\utillib"
function iid_buy_weapon_init_name(e,name)
weapon_name[e] = name
end
--List of weapons that uses the entity name to locate price, add to the if statements to add more weapons as shown below.
function WeaponPricelist(weapon)
local price = 0
if weapon == "Pistol" then
price = 200
elseif weapon == "Shotgun" then
price = 400
--[[ To add more follow this template:
elseif weapon == "your weapon's name" then
price = 'price of weapon'
]]--
end
return price
end
function iid_buy_weapon_main(e)
--Tells you how much the weapon costs when looking at it--
if U.PlayerLookingAt(e,100) == true and g_PlayerHealth > 0 then
TextCenterOnX(50,68,1,"Press E to purchase " .. weapon_name[e] .. " for: " .. WeaponPricelist(weapon_name[e]) .. "$")
--Gives the player the weapon and takes away the price of the weapon from the players money.
if U.PlayerLookingAt(e,100) == true and g_KeyPressE == 1 and g_PlayerMoney >= WeaponPricelist(weapon_name[e]) then
Prompt("Purchased the " .. weapon_name[e])
PlaySound(e,0)
AddPlayerWeapon(e)
Destroy(e)
ActivateIfUsed(e)
g_PlayerMoney = g_PlayerMoney - WeaponPricelist(weapon_name[e])
--Tells the player he can not afford the weapon.
elseif U.PlayerLookingAt(e,100) == true and g_KeyPressE == 1 and g_PlayerMoney < WeaponPricelist(weapon_name[e]) then
PromptDuration("You cannot afford the " .. weapon_name[e], 2000)
end
end
This one is explained pretty in-depth in the comments of the code. Name the gun entity in the game the same as the one that has the price you want to use in the WeaponPricelist.
Jump/Speed Upgrades:
--Place this on an entity and name it "jump" or "speed" accordingly.
--Requires iid_stats_hud.lua
local U = require "scriptbank\\utillib"
function iid_upgrade_init_name(e,name)
weapon_name[e] = name
end
--List of upgrades, more can be added by replicating the elseif statments as shown below
function Upgradelist(name)
local upgrade = 0
if name == "jump" then --can be changed to whatever else you wish to call the jump upgrade
upgrade = 1
elseif name == "speed" then --can be changed to whatever else you wish to call the speed upgrade
upgrade = 2
--[[
elseif name == "your upgrade" then
upgrade = 3 (+1 each new upgrade)
]]--
end
return upgrade
end
function iid_upgrade_main(e)
--Detect if you are looking at the upgrade
if U.PlayerLookingAt(e,100) == true and g_PlayerHealth > 0 and Upgradelist(weapon_name[e]) > 0 then
TextCenterOnX(50,68,1,"Press E to apply " .. weapon_name[e] .." upgrade")
--Check if you are max level or not
if Upgradelist(weapon_name[e]) == 1 and g_Upgrade_Jump == 10 then
Prompt("You are already max level!")
elseif Upgradelist(weapon_name[e]) == 2 and g_Upgrade_Speed == 10 then
Prompt("You are already max level!")
end
--Changing the variables that effect the players stats, if adding a new upgrade follow the guidelines below.
if g_KeyPressE == 1 and Upgradelist(weapon_name[e]) == 1 and g_Upgrade_Jump < 10 then
Destroy(e)
SetGamePlayerControlJumpmax(GetGamePlayerControlJumpmax() + 5) -- Change this number to change how much jump is added per level.
g_Upgrade_Jump = g_Upgrade_Jump + 1 --Adds one to the level of upgrade
g_Save_Jump = GetGamePlayerControlJumpmax() -- Some variables reset on save/load, this is to avoid that, more info in iid_stats_hud.lua
elseif g_KeyPressE == 1 and Upgradelist(weapon_name[e]) == 2 and g_Upgrade_Speed < 10 then
Destroy(e)
SetGamePlayerControlTopspeed(GetGamePlayerControlTopspeed() + 0.05)-- Change this number to change how much speed is added per level.
g_Upgrade_Speed = g_Upgrade_Speed + 1
g_Save_Speed = GetGamePlayerControlTopspeed()
--elseif g_KeyPressE == 1 and Upgradelist(weapon_name[e]) == 2 and g_Upgrade_Speed < 10 then
-- Destroy(e)
-- (What your upgrade does)
end
--Tells you if your entity name does not match up with any items on the Upgradelist
elseif U.PlayerLookingAt(e,100) == true and g_PlayerHealth > 0 and Upgradelist(weapon_name[e]) == 0 then
TextCenterOnX(50,68,1,"ERROR! " .. weapon_name[e] .. " is not a valid upgrade name! Look in iid_upgrade.lua!")
end
end
Two types of upgrades that also is linked to the Status HUD and the current level of them shows up here, max level is by default 10 of each. And the amount of jump/speed gained per level can be changed by adjusting the values commented in the code.
If you have any questions just ask! I could probably do these a lot cleaner but right now I'm just focusing on making it work, feedback is much appreciated!
K. Bye!