Zwip-Zwap Zapony
Member
Alright, basically I'm trying to make a little Lua script to draw custom HUD at a user-specified scale, but I've run into some issues, so I have 2 questions.
1 - How do I set a "float" console variable's default value to a decimal number? If I type 1, it becomes 1, of course. But if I type 0.75 as the default value, Lua complains. If I type 3/4, it turns into 0. If I type simply FRACUNIT, Lua crashes SRB2 about 65536 being too high a number (as I've set the minimum and maximum to 0 and 1, respectively), so in no way can I use 3*FRACUNIT/4 for it.
2 - How do I properly acquire a console variable's value and then store it as a different variable... within a HUD function thing? For a while when I tried, SRB2 exclaimed "warning, attempted to call something on an upvalue (userdata structure)", and then later after some more messing around with the script (adding ".value" at the end of the equals thing), it started calling it a nil value instead of an "upvalue".
So far, I'm only trying to draw a single graphic on-screen with very basic set-up and stuff before trying to go advanced with it, just to get a hang of it. And here is the script, in case you want to see it to help:
The variable in question SRB2 says is nil is "zhudvarsize", at the v.drawScaled line, but "zhudvarsize" should be set by the splitscreen-checking part above it.
(Also, yes, I know the v.drawScaled line is missing the snap to left and bottom flags, but again, I'm just trying to get a hang of it before going advanced.)
1 - How do I set a "float" console variable's default value to a decimal number? If I type 1, it becomes 1, of course. But if I type 0.75 as the default value, Lua complains. If I type 3/4, it turns into 0. If I type simply FRACUNIT, Lua crashes SRB2 about 65536 being too high a number (as I've set the minimum and maximum to 0 and 1, respectively), so in no way can I use 3*FRACUNIT/4 for it.
2 - How do I properly acquire a console variable's value and then store it as a different variable... within a HUD function thing? For a while when I tried, SRB2 exclaimed "warning, attempted to call something on an upvalue (userdata structure)", and then later after some more messing around with the script (adding ".value" at the end of the equals thing), it started calling it a nil value instead of an "upvalue".
So far, I'm only trying to draw a single graphic on-screen with very basic set-up and stuff before trying to go advanced with it, just to get a hang of it. And here is the script, in case you want to see it to help:
Code:
//Initialize console stuff
COM_AddCommand("zhud",function(player) CONS_Printf(player,"ZHud by Zwip-Zwap Zapony\nList of variables:\nzhudsize <0.0-1.0>\nzhudsplitsize <0.0-1.0>\nzhudabilitybar <off/on/always>") end)
local zhudcvarsize=CV_RegisterVar({"zhudsize",1,CV_FLOAT,{MIN=0,MAX=1}})
local zhudcvarsplitsize=CV_RegisterVar({"zhudsplitsize",1,CV_FLOAT,{MIN=0,MAX=1}})
local zhudcvarabilitybar=CV_RegisterVar({"zhudabilitybar",0,0,{Off=0,On=1,Always=2}})
//Disable vanilla HUD
hud.disable("coopemeralds")
hud.disable("lives")
hud.disable("nightsdrill")
hud.disable("nightslink")
hud.disable("nightsrecords")
hud.disable("nightsrings")
hud.disable("nightsscore")
hud.disable("nightstime")
hud.disable("rankings")
hud.disable("rings")
hud.disable("score")
hud.disable("stagetitle")
hud.disable("tabemblems")
hud.disable("textspectator")
hud.disable("time")
hud.disable("tokens")
//Draw own HUD
hud.add(function(v,player)
//Sized co-ordinate stuff
if splitscreen==0
local zhudvarsize=zhudcvarsize.value
local zhudvartop=0
local zhudvarbottom=200*FRACUNIT
local zhudvarcenterv=100*FRACUNIT
local zhudvarleft=0
local zhudvarright=320*FRACUNIT
local zhudvarcenterh=160*FRACUNIT
else
local zhudvarsize=zhudcvarsplitsize.value
if #player==0
local zhudvartop=0
local zhudvarbottom=100*FRACUNIT
local zhudvarcenterv=50*FRACUNIT
else
local zhudvartop=100*FRACUNIT
local zhudvarbottom=200*FRACUNIT
local zhudvarcenterv=150*FRACUNIT
end
local zhudvarleft=0
local zhudvarright=320*FRACUNIT
local zhudvarcenterh=160*FRACUNIT
end
//Lives
if G_GametypeUsesLives() and player.mo and player.mo.skin
v.drawScaled(zhudvarleft+(16*zhudvarsize),zhudvarbottom-(24*zhudvarsize),zhudvarsize,v.cachePatch("LIVSONIC"),V_HUDTRANS,v.getColormap(player.mo.skin,player.skincolor))
end
end)
(Also, yes, I know the v.drawScaled line is missing the snap to left and bottom flags, but again, I'm just trying to get a hang of it before going advanced.)
Last edited: