Welcome, Guest. Please login or register.
Did you miss your activation email?
September 20, 2024, 02:36:00 AM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Coding help
Pages: [1]
Author Topic: Coding help  (Read 5389 times)
A55hat
Poster

Posts: 16


« on: January 31, 2011, 04:27:20 AM »

Hey guys, me again working on the same thing after stopping for a while and I was wanting to taking it a step further and making it work without changing the actual base files. How would i change the health status eg. "Healthy" "Wounded" "Hurt" etc. without screwing with the util.lua file?

Here is how it looks in the util.lua file at the moment. Please try to help me, thank you.

local function HealthToString(health)
 if makeup = 0 or makeup = nil then
if health > 90 then
return "Healthy", healthcolors.healthy
elseif health > 70 then
return "Hurt", healthcolors.hurt
elseif health > 45 then
return "Wounded", healthcolors.wounded
elseif health > 20 then
return "Badly Wounded", healthcolors.badwound
else
return "Near Death", healthcolors.death
end
elseif makeup = 100 then
return "Healthy", healthcolors.healthy
elseif makeup = 80 then
return "Hurt", healthcolors.hurt
elseif makeup = 69 then
return "Wounded", healthcolors.wounded
elseif makeup = 44 then
return "Badly Wounded", healthcolors.badwound
elseif makeup = 19 then
return "Near Death", healthcolors.death
 end
end
« Last Edit: January 31, 2011, 04:33:42 AM by A55hat »
Mr. Gash
Poster

Posts: 382


www.nonerdsjustgeeks.com


« Reply #1 on: January 31, 2011, 05:36:36 AM »

You don't.
Bad King Urgrain
Administrator
*****
Posts: 12276



« Reply #2 on: January 31, 2011, 09:59:47 AM »

One simple option is replacing the function:
-- In an AddCSLua'd client script...

local function MyHealthToString(health)
  -- code here
end

local function ReplaceHealthToString()
  util.HealthToString = MyHealthToString
end
hook.Add("Initialize", "bla", ReplaceHealthToString)


Of course, your pasted code will error because it is using "if x = y" instead of "if x == y".
A55hat
Poster

Posts: 16


« Reply #3 on: January 31, 2011, 04:09:04 PM »

One simple option is replacing the function:
-- In an AddCSLua'd client script...

local function MyHealthToString(health)
  -- code here
end

local function ReplaceHealthToString()
  util.HealthToString = MyHealthToString
end
hook.Add("Initialize", "bla", ReplaceHealthToString)


Of course, your pasted code will error because it is using "if x = y" instead of "if x == y".


Thank you for your help and if x = y is how it initialy was in the util file but i guess ur rite. Also being a new coder, I dont know what AddCSLua is or where to put the changed code. Sorry for being such a noob :P
« Last Edit: January 31, 2011, 04:23:05 PM by A55hat »
Manmax75
Poster

Posts: 254


Programming Guy


« Reply #4 on: January 31, 2011, 08:25:04 PM »

Your lucky that BKU helped you. AddCSLua tells the server to download a file to the client, in otherwords, this script is a clientside script. For more information consult the gmod wiki.

For now, I will give you a direct link outlining the purpose and function of AddCSLua()

http://wiki.garrysmod.com/?title=G.AddCSLuaFile

Ride Forward and Thrust Your Pelvis In The Dark Void. The One Induced By Pleasure Yet Cast By The Bigger Picture.
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: Coding help « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.009 seconds with 18 queries.