Scripts / Simple status HUD, money system and weapon purchase system!

Author
Message
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 24th Mar 2019 21:46 Edited at: 25th Mar 2019 23:03
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:


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:


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

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:



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!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Mar 2019 21:54
You should use utilib functions, everyone already has utillib.

Been there, done that, got all the T-Shirts!
PM
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 24th Mar 2019 22:04
Quote: "You should use utilib functions, everyone already has utillib."


Don't quite know what that means tbh. I am quite new to scripting in general. So a few follow up questions:

1. What is it?
2. How would it improve my scripts?
3. Didn't really have anything else to add, but already typed out the 3 so might as well keep going.

Thanks.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Mar 2019 23:27
Check out the utillib.lua script.

Basically it contains a bunch of useful functions contained in a library which you can call from within your scripts, take a look at the pickuppables.lua scrpt to see how it is used.
Been there, done that, got all the T-Shirts!
PM
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 25th Mar 2019 00:20
Oh I see.. Feel a bit stupid now, but you live and you learn. Thank you! That will be quite useful.
PM
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 25th Mar 2019 18:40
Updated using utilib functions, cleaned up a bit and made a bit simpler
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Mar 2019 20:13 Edited at: 25th Mar 2019 20:14
FYI, any function that returns true or false and be used in an if statement without the '== true' or '== false' bit.

So 'if U.PlayerLookingAt( e, 100 ) then' works fine and so does 'if not U.PlayerLookingAt( e, 100 ) then'.

Moreover a 'nil' value is also 'false' so the following is how you can set a variable to an existing value or a default:

a = b or 20

In this case if b is nil a will be set to 20 otherwise it will take the value of b.

For functions this is how you can implement default parameters (you'll see I do it a lot in my various libraries).


function doSomething( a, b, c, d, e )
d = d or 200
e = e or 'some string'

So if the function is called with only three parameters the other two will be set to default values.
Been there, done that, got all the T-Shirts!
PM
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 25th Mar 2019 20:57
I see, very useful information! Thank you!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 25th Mar 2019 21:17
If you haven't realised it yet, Lua is an extremely powerful and flexible language, in fact I have over 40 years in the business, having used pretty much every language available (and a few that aren't!) and Lua is by far and away my favourite.
Been there, done that, got all the T-Shirts!
PM
iiDenTiiTy
5
Years of Service
User Offline
Joined: 22nd Mar 2019
Location:
Posted: 25th Mar 2019 23:09
Yes, really enjoyed LUA so far. Although the only other experience I have is learning a bit of programming in C++ a good while back, just for fun.
PM
sacdaly
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 14th May 2019 14:40
Hi
I get this message when adding the weapon lua ,i attached it to a Colt , named it Colt in the weapon and changed it to price of 50

--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
s clarke

Attachments

Login to view attachments
sacdaly
10
Years of Service
User Offline
Joined: 31st Oct 2013
Location:
Posted: 14th May 2019 14:42 Edited at: 14th May 2019 15:21
Sorry this 1

--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



Its ok iv found the problem not knowing scripting there was an 'end' missing after the statement on line 24 inserted and its functioning correctly now cheers

--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 == "Colt" then
price = 50
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
s clarke
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 14th May 2019 20:29
Can you just upload the whole script file so I can see it properly, alternatively use the code tags.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-04-20 10:12:27
Your offset time is: 2024-04-20 10:12:27