eatdatpussy445
New Member
- Messages
- 1
- Reaction score
- 0
- Points
- 1
So I'm really confused as to why no text shows. I don't even know if I used spawnstruct like it's suppose to be used. So I would be really happy if someone could help me out here and maybe explain what i did wrong. I haven't been working with gsc for a long time so yeah...
Code:
#using scripts\codescripts\struct;
#using scripts\shared\system_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\hud_util_shared;
#using scripts\shared\util_shared;
#insert scripts\shared\shared.gsh;
#namespace clientids;
REGISTER_SYSTEM( "clientids", &__init__, undefined )
function __init__()
{
callback::on_start_gametype( &init );
callback::on_connect( &connect );
callback::on_disconnect( &disconnect );
}
//this is based on cwxh's menu base
function init()
{
level.name = "level";
level.astra = spawnstruct();
addcolor("black", (0, 0, 0));
addcolor("white", (1, 1, 1));
addcolor("red", (1, 0, 0));
addcolor("yellow", (1, 1, 0));
addcolor("green", (0, 1, 0));
addcolor("blue", (0,0, 1));
addcolor("purple", (1, 0, 1));
addcolor("cyan", (0, 1, 1));
addcolor("gray", (0.5, 0.5, 0.5));
addcolor("orange", (0.95, 0.52, 0.0285));
addtheme("Surge", "orange", "black");
addtheme("Cherry", "red", "white");
addtheme("Poison", "green", "black");
addtheme("Death Star", "cyan", "black");
addtheme("Obsidian", "purple", "black");
addtheme("NextGenUpdate", "cyan", "gray");
addtheme("Se7enSins", "green", "gray");
}
function disconnect(){}
function connect()
{
self setaccess(Iif(self ishost(), 3, 0));
self waittill("spawned_player");
self initastra();
}
function initastra()
{
self.astra = spawnstruct();
self.astra.locked = false;
self.astra.active = false;
self FreezeControls(false);
setcolor("panel", "black");
setcolor("glow", "orange");
setcolor("title", "orange");
setcolor("options", "white");
setcolor("scrollbar", "orange");
setcolor("background", "black");
self.astra.menu.current = "Astra";
self initvars();
self initmenu();
self thread monitor();
self thread inithud();
}
function initvars()
{
addvar("god", 0);
addvar("ammo", 0);
}
//ressource/function.gsc
//functions
function test()
{
self iprintln("hello bois");
}
//ressource/hud.gsc
//hud
function inithud()
{
self drawtext();
self drawshaders();
self.astra.hud.drawn = true;
}
function drawtext()
{
self notify("redraw");
colors = self.astra.colors;
self.astra.hud.text = spawnstruct();
self.astra.hud.text.title = self createText("RIGHT", "TOP", 0, 50, "bigfixed", 1, 7, colors["title"], 0, "");
self.astra.hud.text.title thread destroyOnAny("disconnect", "menu_exit", "redraw", "dunno");
self.astra.hud.text.options = [];
for(i = 0; i < 15; i++)
{
self.astra.hud.text.options[i] = self createText("RIGHT", "TOP", -540, 50 + (2 * 25) + (25 * i), "objective", 1.4, 7, colors["options"], 0, "");
self.astra.hud.text.options[i] thread destroyOnAny("disconnect", "menu_exit", "redraw", "dunno");
}
}
function drawshaders()
{
colors = self.astra.colors;
self.astra.hud.shaders = spawnstruct();
self.astra.hud.shaders.background = self createRectangle("LEFT", "CENTER", 0, 0, 0, 500, 2, colors["background"], 0, "white");
self.astra.hud.shaders.scrollbar = self createRectangle("RIGHT", "TOP", 0, 50 + (2 * 25), 6, 25, 9, colors["scrollbar"], 0, "white");
self.astra.hud.shaders.shadow = self createRectangle("RIGHT", "CENTER", 0, 0, 5, 500, 3, colors["panel"], 0, "white");
self.astra.hud.shaders.header = self createRectangle("RIGHT", "TOP", -5, 50, 500, 40, 5, colors["panel"], 0, "white");
self.astra.hud.shaders.panel = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 2, colors["panel"], 0, "white");
self.astra.hud.shaders.glow = self createRectangle("RIGHT", "CENTER", 0, 0, 0, 500, 1, colors["glow"], 0, "white");
}
function updatetext(offset)
{
menu = self getmenu();
if(!isDefined(offset))
offset = menu.position - menu.textindex;
for(i = 0; i < 15; i++)
{
self.astra.hud.text.options[i] setText(menu.options[offset].label);
offset++;
}
}
function updatehud()
{
self.astra.hud.text.title setText(self getMenu()["label"]);
self updatetext();
}
function showhud()
{
self.astra.hud.shaders.header elemFade(0.1, 0.65);
self.astra.hud.shaders.panel elemFade(0.1, 0.5);
self.astra.hud.shaders.panel scaleOverTime(0.25, 540, 500);
self.astra.hud.shaders.background elemFade(0.1, 0.5);
self.astra.hud.shaders.background scaleOverTime(0.25, 540, 500);
self.astra.hud.shaders.shadow elemFade(0.25, 0.5);
self.astra.hud.shaders.glow elemFade(0.1, 0.5);
self.astra.hud.shaders.glow scaleOverTime(0.25, 1000, 500);
self.astra.hud.shaders.glow thread pulseEffect(0.4, 0.5, 2);
self updatehud();
self menutransin();
self updatescrollbar();
self.astra.hud.shaders.scrollbar elemFade(0.25, 1);
}
function hidehud()
{
self.astra.hud.shaders.header elemFade(0.1, 0);
self.astra.hud.text.title elemFade(0.1, 0);
for(i = 0; i < self.astra.hud.text.options.size; i++)
{
self.astra.hud.text.options[i] thread elemMoveX(0.25, 0);
self.astra.hud.text.options[i] elemFade(0.25, 0);
}
self.astra.hud.shaders.glow notify("pulse_end");
self.astra.hud.shaders.glow elemFade(0.4, 0);
self.astra.hud.shaders.glow scaleOverTime(0.25, 1, 500);
self.astra.hud.shaders.shadow elemFade(0.4, 0);
self.astra.hud.shaders.background elemFade(0.4, 0);
self.astra.hud.shaders.background scaleOverTime(0.25, 1, 500);
self.astra.hud.shaders.panel elemFade(0.4, 0);
self.astra.hud.shaders.panel scaleOverTime(0.25, 1, 500);
self.astra.hud.shaders.scrollbar.alpha = 0;
}
function updatescrollbar()
{
self.astra.hud.shaders.scrollbar elemMoveY(0.15, self.astra.hud.text.options[self getmenu().textindex].y);
}
function menutransin()
{
self.astra.hud.text.title.x = 0;
self.astra.hud.text.title thread elemMoveX(0.25, -10);
self.astra.hud.text.title elemFade(0.25, 1);
for(i = 0; i < 15; i++)
{
self.astra.hud.text.options[i].x = -540;
self.astra.hud.text.options[i] thread elemMoveX(0.25, -10);
self.astra.hud.text.options[i] elemFade(0.25, 0.5);
}
self.astra.hud.shaders.scrollbar scaleOverTime(0.25, 5, 25);
self thread scrollbareffect();
}
function menutransout()
{
self.astra.hud.text.title thread elemMoveX(0.25, 0);
self.astra.hud.text.title elemFade(0.25, 0);
for(i = 0; i < self.astra.hud.text.options.size; i++)
{
self.astra.hud.text.options[i] thread elemMoveX(0.25, 0);
self.astra.hud.text.options[i] elemFade(0.25, 0);
}
self.astra.hud.shaders.scrollbar scaleOverTime(0.25, 540, 25);
}
//ressource/hud_util.gsc
//hud util
function createrectangle(align, relative, x, y, width, height, sort, color, alpha, shader)
{
elem = newClientHudElem(self);
elem.elemType = "bar";
elem.sort = sort;
elem.color = color;
elem.alpha = alpha;
elem hud::setParent(level.uiParent);
elem setShader(shader, width, height);
elem.hideWhenInMenu = true;
elem hud::setPoint(align, relative, x, y);
elem.type = "shader";
elem.owner = self;
return elem;
}
function createtext(align, relative, x, y, font, fontscale, sort, color, alpha, text)
{
elem = self hud::CreateFontString(font, fontscale);
elem hud::setPoint(align, relative, x, y);
elem.sort = sort;
elem.alpha = alpha;
elem.hideWhenInMenu = true;
elem setText(text);
elem.type = "text";
elem.color = color;
elem.owner = self;
return elem;
}
function elemMoveX(time, x)
{
self moveovertime(time);
self.x = x;
}
function elemMoveY(time, y)
{
self moveovertime(time);
self.y = y;
}
function elemFade(time, alpha)
{
self fadeovertime(time);
self.alpha = alpha;
}
function pulse(state)
{
if(state == true)
self thread pulseeffect(0.5, 1, 0.5);
else
self notify("pulse_end");
self.pulsing = state;
}
function pulseeffect(min, max, time)
{
self endon("pulse_end");
for(;;)
{
self elemFade(time, max);
wait time;
self elemFade(time, min);
wait time;
}
}
function scrollbareffect()
{
for(i = 0; i < self.astra.hud.text.options.size; i++)
{
if(i == self getmenu().textindex)
self.astra.hud.text.options[i] elemFade(0.25, 1);
else
self.astra.hud.text.options[i] elemFade(0.25, 0.5);
}
}
function destroyOnAny(event1, event2, event3, event4, event5, event6)
{
self.owner util::waittill_any(event1, event2, event3, event4, event5, event6);
self destroy();
}
//ressource/menu.gsc
//menu
function initmenu()
{
main = "Astra";
self.astra.menu = [];
self.astra.menu.current = main;
self addmenu(undefined, main);
for(i = 0; i < 17; i++)
{
self addmenu(main, "Submenu " + (i + 1));
for(n = 0; n < 19; n++)
self addoption("Submenu " + (i + 1), "Option " + (n + 1), &test);
}
}
//ressource/misc.gsc
//misc
function Iif(bool, val1, val2)
{
if(bool)
return val1;
return val2;
}
function isallowed(n = 1)
{
return self getAccess() >= n;
}
function empty(x)
{
if(!isDefined(x) || x == "")
return true;
return false;
}
//add
function addcolor(name, color)
{
level.astra.colors[name] = color;
}
function addsetting(name, value)
{
level.astra.settings[name] = value;
}
function addvar(name, value)
{
self.astra.vars[name] = value;
}
function addtheme(name, primary, secondary)
{
level.astra.themes[name] = spawnstruct();
level.astra.themes[name].primary = level.astra.colors[primary];
level.astra.themes[name].secondary = level.astra.colors[secondary];
}
//set
function setcolor(elem, name)
{
self.astra.colors[elem] = level.astra.colors[name];
}
function setaccess(n)
{
self.astra.access = n;
}
function setsetting(name, value)
{
level.astra.settings[name] = value;
}
function setvar(name, value)
{
self.astra.vars[name] = value;
}
//get
function getsetting(name)
{
return level.astra.settings[name];
}
function getvar(name)
{
return self.astra.vars[name];
}
function getaccess()
{
return Iif(empty(self.astra.access), 0, self.astra.access);
}
function getmenu()
{
return self.astra.menu[self getcurrentmenu()];
}
function getcurrentmenu()
{
return self.astra.menu.current;
}
//ressource/monitoring.gsc
//controls
function monitor()
{
self endon("dunno");
for(;;)
{
while(isAlive(self))
{
if(!self.astra.locked)
{
if(!self.astra.active)
{
//open
if(self ActionSlotOneButtonPressed())
self openmenu();
//exit level (for testing)
if(self ActionSlotFourButtonPressed())
ExitLevel();
}
else
{
//go back/exit menu
if(self ActionSlotTwoButtonPressed() || self UseButtonPressed())
{
if(self ActionSlotTwoButtonPressed() || empty(self getmenu().parent))
self closemenu();
else
self submenu(self getmenu().parent);
wait 0.2;
}
//scroll
if(self AttackButtonPressed() || self AdsButtonPressed())
{
scroll(Iif(self AttackButtonPressed(), -1, 1));
wait 0.2;
}
//select
if(self JumpButtonPressed())
{
self select();
wait 0.2;
}
}
}
wait 0.05;
}
self waittill("spawned_player");
}
}
//select
function select()
{
selected = self getmenu().options[self getmenu().position];
//so you dont have to re-enter name of the submenu -> addOption("SubMenu 1", "SubMenu 1.1", &submenu);
if(selected.func == &submenu && empty(selected.input))
selected.input = selected.label;
//prevent text from moving if the option is "submenu" / move text if option is submenu but menu doesnt exist
if(selected.func != &submenu || (selected.func == &submenu && empty(self.astra.menu[selected.input])))
{
elem = self.astra.hud.text.options[self getmenu().textindex];
elem elemMoveX(0.07, elem.x - 5);
wait 0.25;
elem thread elemMoveX(0.07, -10);
}
//if submenu doesnt exist
if(selected.func == &submenu && empty(self.astra.menu[selected.input]))
{
self iprintln("^1ERROR: ^3Cannot enter submenu: submenu does not exist");
return;
}
//thread function
if(selected.type == "thread")
{
if(empty(selected.input))
selected.entity thread [[selected.func]]();
else if(isArray(selected.input))
{
if(selected.input.size == 0)
self iprintln("^1ERROR: ^3Cannot call function: no arguments passed");
else if(selected.input.size == 1)
selected.entity thread [[selected.func]](selected.input[0]);
else if(selected.input.size == 2)
selected.entity thread [[selected.func]](selected.input[0], selected.input[1]);
else if(selected.input.size == 3)
selected.entity thread [[selected.func]](selected.input[0], selected.input[1], selected.input[2]);
else if(selected.input.size == 4)
selected.entity thread [[selected.func]](selected.input[0], selected.input[1], selected.input[2], selected.input[3]);
else if(selected.input.size == 5)
selected.entity thread [[selected.func]](selected.input[0], selected.input[1], selected.input[2], selected.input[3], selected.input[4]);
else
self iprintln("^1ERROR: ^3Cannot call function: too many arguments passed");
}
else
selected.entity thread [[selected.func]](selected.input);
}
//call function immediately
else if(selected.type == "immediate")
{
if(empty(selected.input))
selected.entity [[selected.func]]();
else if(isArray(selected.input))
selected.entity [[selected.func]](selected.input[0], selected.input[1], selected.input[2], selected.input[3], selected.input[4]);
else
selected.entity [[selected.func]](selected.input);
}
//tell player that func was called on ent
if(selected.entity != self)
self iPrintln(selected.label + " was called on " + selected.entity.name);
}
//scroll
function scroll(amount)
{
menu = self getmenu();
options = menu.options;
position = menu.position + amount;
lastindex = menu.lastindex;
textindex = menu.textindex;
if(position < 0)
{
position = options.size - 1;
textindex = lastindex;
self updateText(position - textindex);
}
else if(position >= options.size)
{
position = 0;
textindex = 0;
self updateText(position - textindex);
}
else if(textindex != 0 && textindex != lastindex)
textindex += amount;
else
self updateText(position - textindex);
self.astra.menu[menu.label].textindex = textindex;
self.astra.menu[menu.label].position = position;
}
//ressource/util.gsc
//menu util
function addmenu(parent, name)
{
self.astra.menu[name] = spawnstruct();
self.astra.menu[name].options = [];
self.astra.menu[name].parent = parent;
self.astra.menu[name].label = name;
self.astra.menu[name].position = 0;
self.astra.menu[name].textindex = 0;
self.astra.menu[name].lastindex = 0;
if(!empty(parent))
self addoption(parent, name, &submenu);
}
function addoption(menu, label, func, input, type = "thread", entity = self)
{
index = self.astra.menu[menu].options.size;
self.astra.menu[menu].options[index] = spawnstruct();
self.astra.menu[menu].options[index].label = label;
self.astra.menu[menu].options[index].func = func;
self.astra.menu[menu].options[index].input = input;
self.astra.menu[menu].options[index].type = type;
self.astra.menu[menu].options[index].entity = entity;
if(index < 15)
self.astra.menu[menu].lastindex = index;
}
function openmenu()
{
self FreezeControls(false);
self EnableInvulnerability();
self SetClientUIVisibilityFlag("hud_visible", 0);
self showHud();
self.astra.active = true;
}
function closemenu()
{
self hideHud();
wait 0.15;
self notify("menu_exit");
self SetClientUIVisibilityFlag("hud_visible", 1);
self.astra.active = false;
if(!getvar("god"))
self DisableInvulnerability();
}
function submenu(input)
{
if(!empty(self.astra.menu[input]))
{
if(!self.astra.active)
{
if(self getaccess() > 0)
{
self menutransout();
wait 0.25;
self.astra.menu.current = input;
self updatehud();
self.astra.hud.shaders.glow notify("pulse_end");
self.astra.hud.shaders.glow thread pulseEffect(0.4, 0.5, 2);
self updatescrollbar();
self.astra.hud.shaders.scrollbar scaleOverTime(0.25, 5, 25);
}
else
self iPrintln("^1You do not have permission to enter this menu");
}
else
self iPrintln("^1ERROR: ^3Cannot enter submenu: menu is closing");
}
else
self iPrintln("^1ERROR: ^3Cannot enter submenu: menu does not exist");
}