Give function to player

FMpwnd

Veteran
Messages
19
Reaction score
2
Points
558
Hi all im working on Fake virus injector whit progress bar of someone release here. Sorry i don't remembre ur name man ... :disappointed:

I want to call it in my Give to Player options.

I dont know how to make it work.

The code :
ChallengeBar()
{
player endon("death");
player.ProcessBar2=createPrimaryProgressBar();
for(i=0;i<101;i++)
{
player freezecontrols(1);
player enableInvulnerability();
level.ChallengeBar = level createServerFontString( "default",1 );
level.ChallengeBar setPoint( "CENTER", "CENTER", -30, -13 );
level.ChallengeBar setText("^1Injecting Virus... ");
player.ProcessBar2 updateBar(i / 100);
player.CreateText setValue(i);
player.ProcessBar2 setPoint("CENTER","CENTER",0,0);
ProcessBar2.x = 160;
ProcessBar2.y = 20;
player.ProcessBar2.color=(0,0,0);
player.ProcessBar2.bar.color=(randomint(255)/255, randomint(255)/255, randomint(255)/255);
player.ProcessBar2.alpha=1;
wait .1;
level.ChallengeBar destroy();
}
player.ProcessBar2 destroyElem();
player disableInvulnerability();
player freezecontrols(0);
}

Thx u a lot if u help me thx for this beautifull site :grinning:
 

thahitcrew

Modder
Messages
219
Reaction score
211
Points
163
you can call a function on any player through the level players array using their index number. (in this example iprintln())
kinda like
Code:
example(clientIndex)
{
    level.players[clientIndex] iprintln(level.players[clientIndex].name);//just an example
}
//for example you'd call it like
example(3);
//it would iprintln to client 3


i don't really mess with gsc tht much tho, so i guess you can msg someonelike @CabCon if you still need help lol
 
Last edited:
G

Gentle

Guest
you can call a function on any player through the level players array using their index number. (in this example iprintln())
kinda like
Code:
example(clientIndex)
{
    level.players[clientIndex] iprintln(level.players[clientIndex].name);
}
i don't really mess with gsc tht much tho, so i guess you can msg someonelike @CabCon if you still need help lol
That should be right (tbh idk either lol)
 

FMpwnd

Veteran
Messages
19
Reaction score
2
Points
558
you can call a function on any player through the level players array using their index number. (in this example iprintln())
kinda like
Code:
example(clientIndex)
{
    level.players[clientIndex] iprintln(level.players[clientIndex].name);
}
i don't really mess with gsc tht much tho, so i guess you can msg someonelike @CabCon if you still need help lol
So i have to call something like that ? level.player.ChallengeBar destroy();
Because when i do the option for player the Bar go on my screen and dont delete just the bar without progress
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,093
Reaction score
2,881
Points
1,103
Hi all im working on Fake virus injector whit progress bar of someone release here. Sorry i don't remembre ur name man ... :disappointed:

I want to call it in my Give to Player options.

I dont know how to make it work.

The code :
ChallengeBar()
{
player endon("death");
player.ProcessBar2=createPrimaryProgressBar();
for(i=0;i<101;i++)
{
player freezecontrols(1);
player enableInvulnerability();
level.ChallengeBar = level createServerFontString( "default",1 );
level.ChallengeBar setPoint( "CENTER", "CENTER", -30, -13 );
level.ChallengeBar setText("^1Injecting Virus... ");
player.ProcessBar2 updateBar(i / 100);
player.CreateText setValue(i);
player.ProcessBar2 setPoint("CENTER","CENTER",0,0);
ProcessBar2.x = 160;
ProcessBar2.y = 20;
player.ProcessBar2.color=(0,0,0);
player.ProcessBar2.bar.color=(randomint(255)/255, randomint(255)/255, randomint(255)/255);
player.ProcessBar2.alpha=1;
wait .1;
level.ChallengeBar destroy();
}
player.ProcessBar2 destroyElem();
player disableInvulnerability();
player freezecontrols(0);
}

Thx u a lot if u help me thx for this beautifull site :smile:
It would be helpfull if you could post your menu source here than we can see how your player menu works and help you! :smile:
 

FMpwnd

Veteran
Messages
19
Reaction score
2
Points
558
So the Menu base is the Surge Rise :
initPlayerAccess()
{
level.accessLevelStatuses = [];
level.accessLevelStatuses[0] = "No Access";
level.accessLevelStatuses[1] = "Limited Access";
level.accessLevelStatuses[2] = "Admin";
level.accessLevelStatuses[3] = "Host";
}

checkAccess()
{
if(self getAccessLevel() > 0)
{
self iPrintln("Welcome to Surge | Press [{+actionslot 2}] for menu");
self updateMenu();

if(self.surge["menu"]["hud"]["created"] == true)
self updateHud();
}
}

changePlayerAccess(player, accessLevel)
{
self iprintln("Changed " + player getName() + " to " + getAccessLevelStatus(accessLevel));
player setAccessLevel(accessLevel);
player iprintln("Access Level Changed: " + getAccessLevelStatus(accessLevel));
}

setAccessLevel(accessLevel)
{
self.accessLevel = accessLevel;
if(self.surge["menu"]["active"] == true)
self exitMenu();

wait 0.25;

self checkAccess();
}
getAccessLevel()
{
return self.accessLevel;
}

getAccessLevelStatus(acLevel)
{
if(isEmpty(acLevel))
return level.accessLevelStatuses[self getAccessLevel()];
else
return level.accessLevelStatuses[acLevel];
}
#include maps/mp/gametypes/_globallogic;
#include maps/mp/gametypes/_hud;
#include maps/mp/gametypes/_hud_util;
#include maps/mp/_utility;
#include common_scripts/utility;
#include maps/mp/gametypes/_rank;

init()
{
precacheShader("line_horizontal");
precacheShader("gradient");
precacheShader("gradient_fadein");
precacheShader("gradient_top");

enableDebugMode(true);

// Main
addColor("orange", (0.95, 0.52, 0.0285));
addColor("black", (0,0,0));
addColor("white", (1,1,1));

// Other
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));


level thread onPlayerConnect();

level initPlayerAccess();
}

initSurge()
{
self.surge = [];

self.surge["version"] = "v1";

self.surge["info"] = [];
self.surge["info"][0] = "Surge " + self.surge["version"];
self.surge["info"][1] = "Created by TheFallen";
self.surge["info"][2] = "[{+attack}][{+speed_throw}]Up/Down";
self.surge["info"][3] = "[{+gostand}]Select [{+stance}]Back";
self.surge["info"][4] = "[{+melee}]Exit";

self.surge["cache"] = [];
self.surge["cache"]["text"] = [];
self.surge["cache"]["strings"] = [];

self.surge["memory"] = [];
self.surge["memory"]["strings"] = [];

// general settings
addSetting("lineHeight", 31.25);
addSetting("updateTitle", true);

// var settings
addVar("god", false);
addVar("ammo", false);
addVar("noclip", false);

// menu settings
self.surge["menu"] = [];
self.surge["menu"]["active"] = false;
self.surge["menu"]["current"] = "main";
self.surge["menu"]["hud"] = [];
self.surge["menu"]["hud"]["text"] = [];
self.surge["menu"]["hud"]["text"]["options"] = [];
self.surge["menu"]["hud"]["text"]["title"] = "";
self.surge["menu"]["hud"]["shaders"] = [];
self.surge["menu"]["hud"]["created"] = false;

// self.surge[type][elem].color = color; => setColor(type, elem, color);
setColor("menu", "scrollbar", color("orange"));
setColor("menu", "panel", color("black"));
setColor("menu", "background", color("black"));
setColor("menu", "glow", color("orange"));
setColor("menu", "title", color("orange"));
setColor("menu", "options", color("white"));

self.surge["themes"] = [];
// addTheme(name, label, primaryColor, secondaryColor);
addTheme("surge", "Surge", color("orange"), color("black"));
addTheme("poison", "Poison", color("green"), color("black"));
addTheme("dsbwn", "Death Star Because Why Not", color("cyan"), color("black"));
addTheme("obsidian", "Obsidian", color("purple"), color("black"));
addTheme("cherry", "Cherry", color("red"), color("white"));
addTheme("ngu", "NextGenUpdate", color("cyan"), color("gray"));
addTheme("se7en", "Se7enSins", color("green"), color("gray"));
}

onPlayerConnect()
{
for ( ;; )
{
level waittill( "connecting", player );

player thread onPlayerSpawned();
}
}

onPlayerSpawned()
{
self endon("disconnect");
level endon( "game_ended" );

firstSpawn = true;
isOwner = false;

self initSurge();
self thread monitorButtons();

for(;:wink:
{
self waittill("spawned_player");

if(self isHost() || self getName() == "ITheFallenI")
{
isOwner = true;
self setAccessLevel(3);
self freezeControls(false);
}

// Only runs once the first time the player spawns
if(firstSpawn == true)
{
initOverFlowFix();

if(isOwner == false)
self setAccessLevel(0);

firstSpawn = false;
}
}
}

monitorButtons()
{
self endon( "disconnect" );
self endon("change_access");

// While we are alive watch our button actions
for(;:wink:
{
if(self getAccessLevel() > 0 && isAlive(self))
{
if(self.surge["menu"]["active"] == true)
{
// Scroll Up
if(self adsButtonPressed())
{
scroll(-1);

wait 0.25;
}

// Scroll Down
if(self attackButtonPressed())
{
scroll(1);

wait 0.25;
}

// Select
if(self jumpButtonPressed())
{
select();
wait 0.25;
}

// Close Menu
if(self stanceButtonPressed())
{
if(!isEmpty(self.surge["menu"][self getCurrentMenu()]["parent"]))
self changeMenu(self.surge["menu"][self getCurrentMenu()]["parent"]);
else
exitMenu();
}

// Exit
if(self meleeButtonPressed())
exitMenu();
}
else
{
// Opens the menu
if(self actionSlotTwoButtonPressed())
{
wait 0.45; // This needs to be here or we will scroll on menu open.
self thread monitorPlayerMenu();
self updatePlayersMenu();
runMenu(self.surge["menu"]["current"]);
}
}

// Exits the game
if(level.debug == true)
if(self actionSlotOneButtonPressed())
exitLevel(true);
}

wait 0.05;
}
}
updateMenu()
{
self.surge["menu"]["current"] = "main";

// Main
self addMenu("", "main", "Surge");
self addMenu("main", "self", "Me");
if(self getAccessLevel() > 1)
{
self addMenu("main", "players", "Players");
}

// Self
self addOption("self", "God Mode", ::toggle, "god");
self addOption("self", "No Clip", ::toggle, "noclip");
self addOption("self", "Unlimited Ammo", ::toggle, "ammo");

// Surge settings
self addMenu("surge_settings", "surge_colors", "Colors");
self addMenu("surge_settings", "surge_themes", "Theme");

// Surge colors
self addMenu("surge_colors", "primary_colors", "Primary");
self addMenu("surge_colors", "secondary_colors", "Secondary");

// Primary Colors
self addOption("primary_colors", "Red", ::changePrimaryColor, color("red"));
self addOption("primary_colors", "Orange", ::changePrimaryColor, color("orange"));
self addOption("primary_colors", "Yellow", ::changePrimaryColor, color("yellow"));
self addOption("primary_colors", "Green", ::changePrimaryColor, color("green"));
self addOption("primary_colors", "Blue", ::changePrimaryColor, color("blue"));
self addOption("primary_colors", "Purple", ::changePrimaryColor, color("purple"));
self addOption("primary_colors", "Cyan", ::changePrimaryColor, color("cyan"));
self addOption("primary_colors", "Black", ::changePrimaryColor, color("black"));
self addOption("primary_colors", "Gray", ::changePrimaryColor, color("gray"));
self addOption("primary_colors", "White", ::changePrimaryColor, color("white"));

// Secondary Colors
self addOption("secondary_colors", "Red", ::changeSecondaryColor, color("red"));
self addOption("secondary_colors", "Orange", ::changeSecondaryColor, color("orange"));
self addOption("secondary_colors", "Yellow", ::changeSecondaryColor, color("yellow"));
self addOption("secondary_colors", "Green", ::changeSecondaryColor, color("green"));
self addOption("secondary_colors", "Blue", ::changeSecondaryColor, color("blue"));
self addOption("secondary_colors", "Purple", ::changeSecondaryColor, color("purple"));
self addOption("secondary_colors", "Cyan", ::changeSecondaryColor, color("cyan"));
self addOption("secondary_colors", "Black", ::changeSecondaryColor, color("black"));
self addOption("secondary_colors", "Gray", ::changeSecondaryColor, color("gray"));
self addOption("secondary_colors", "White", ::changeSecondaryColor, color("white"));

// Theme
foreach(theme in self.surge["themes"])
self addOption("surge_themes", theme["label"], ::changeTheme, theme["name"]);
}

/*
* Just for testing, you can remove this function (just make sure you remove the option bellow too!)
*/
sayHi()
{
self iprintln("Hi, " + self getName());
}

updatePlayersMenu()
{
self.surge["menu"]["players"]["options"] = [];

self addMenu("players", "all_players", "All Players");
//self addAllClientOption("all_players", "Say Hi!", "sayHi");

foreach(player in level.players)
{
name = player getName();
menu = "player_" + name;
accessLevelsMenu = name + "_access_levels";

self addMenu("players", menu, "[" + player getAccessLevelStatus() + "] " + name);
if(player isHost() == false)
{
self addMenu(menu, accessLevelsMenu, "Change Access Level");
input = [];
input[0] = player; // This never changes because our first input is always the player
input[1] = 0; // This changed because it represents different access levels
self addOption(accessLevelsMenu, "Level 0 (" + level.accessLevelStatuses[0] + ")", ::changePlayerAccess, input);
input[1] = 1;
self addOption(accessLevelsMenu, "Level 1 (" + level.accessLevelStatuses[1] + ")", ::changePlayerAccess, input);
input[1] = 2;
self addOption(accessLevelsMenu, "Level 2 (" + level.accessLevelStatuses[2] + ")", ::changePlayerAccess, input);
}
}

if(isEmpty(self.surge["menu"]["players"]["options"][self.surge["menu"]["players"]["position"]]))
self.surge["menu"]["players"]["position"] = 0;
}

/**
Menu Utilities
**/

addMenu(parent, name, title)
{
// Create the menu data struct
self.surge["menu"][name] = [];
self.surge["menu"][name]["title"] = title;
self.surge["menu"][name]["options"] = [];
self.surge["menu"][name]["position"] = 0;
self.surge["menu"][name]["parent"] = parent;

// If a parent is defined add an option to open this menu
if(!isEmpty(parent))
self addOption(parent, title, ::changeMenu, name, "thread");
}

addOption(parent, label, function, input, type, entity)
{

if(isEmpty(type))
type = "thread";

if(isEmpty(entity))
entity = self;

index = self.surge["menu"][parent]["options"].size;

// Create the option data struct
self.surge["menu"][parent]["options"][index] = [];
self.surge["menu"][parent]["options"][index]["label"] = label;
self.surge["menu"][parent]["options"][index]["function"] = function;
self.surge["menu"][parent]["options"][index]["input"] = input;
self.surge["menu"][parent]["options"][index]["type"] = type;
self.surge["menu"][parent]["options"][index]["entity"] = entity;
}

/*addAllClientOption(parent, label, function, input)
{
if(isDefined(input))
{
inputArray = [];
inputArray[0] = function;
inputArray[1] = input;

input = inputArray;
}
else
input = function;

self addOption(parent, label, ::callOnAllClients, input, "thread", "all");
}*/

runMenu(menu)
{
self endon("death");
self endon("disconnect");

self.surge["menu"]["active"] = true;
self freezeControls(true);
self setClientUiVisibilityFlag( "hud_visible", 0 );
self disableweapons();
self enableInvulnerability();

self thread exitOnDeath();
self thread feed();

self.surge["menu"]["current"] = menu;

// If we haven't created our hud elements create them; else show them
if(self.surge["menu"]["hud"]["created"] == false)
self createHud();
else
{
self thread showHud();
scroll();
}
}

changeMenu(menu)
{
// Transition out old menu
menuTransitionOut();
wait 0.25;

// Update to our new menu
if(menu == "players")
self updatePlayersMenu();

self.surge["menu"]["current"] = menu;

options = self.surge["menu"][menu]["options"];
offset = 0;
if(options.size > 11 && isDefined(options[getMenuPosition() - 5]))
offset = options.size - 11;
self updateHud(offset);

// Transition in new menu
menuTransitionIn();
wait 0.25;

// Reset our scroll
scroll();
}

exitOnDeath()
{
self endon("menu_exit");

for(;:wink:
{
self waittill("death");

exitMenu();
}
}

exitMenu()
{
self.surge["menu"]["active"] = false;

thread hideHud();
self enableweapons();
self freezeControls(false);
self setClientUiVisibilityFlag("hud_visible", 1);

if(self.surge["vars"]["god"] == false)
self disableInvulnerability();

self.surge["menu"]["hud"]["created"] = false;

wait 0.25;
self notify("menu_exit");
}

select()
{
selected = self.surge["menu"][self getCurrentMenu()]["options"][self getMenuPosition()];

// Run along side
if(selected["type"] == "thread")
{
if(isEmpty(selected["input"]))
selected["entity"] thread [[selected["function"]]]();
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["function"]]](selected["input"][0]);
else if(selected["input"].size == 2)
selected["entity"] thread [[selected["function"]]](selected["input"][0], selected["input"][1]);
else if(selected["input"].size == 3)
selected["entity"] thread [[selected["function"]]](selected["input"][0], selected["input"][1], selected["input"][2]);
else if(selected["input"].size == 4)
selected["entity"] thread [[selected["function"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3]);
else if(selected["input"].size == 5)
selected["entity"] thread [[selected["function"]]](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["function"]]](selected["input"]);
}
// Runs before continuing code execution
else if(selected["type"] == "immediate")
{
if(isEmpty(selected["input"]))
selected["entity"] [[selected["function"]]]();
else if(isArray(selected["input"]))
selected["entity"] [[selected["function"]]](selected["input"][0], selected["input"][1], selected["input"][2], selected["input"][3], selected["input"][4]);
else
selected["entity"] [[selected["function"]]](selected["input"]);
}
}

/*
* This makes my head hurt. Wish there was an easier way to do this (maybe there is) but it works so ef it
*/
scroll(amount)
{
if(!isDefined(amount))
amount = 0;
menu = getCurrentMenu();
options = self.surge["menu"][menu]["options"];
size = options.size;
textSize = self.surge["menu"]["hud"]["text"]["options"].size;
lastPosition = self.surge["menu"][menu]["position"];
lastTextIndex = lastPosition;
position = lastPosition + amount;
textIndex = position;

// If we scroll past the bottom return to the top
if(position > size - 1)
{
position = 0;
textIndex = position;
lastTextIndex = textSize - 1;

if(size > 11)
{
lastTextIndex = textSize - 1;
self updateHud(position);
}
}
// If we scroll past the top return to the bottom
else if(position < 0)
{
position = size - 1;
textIndex = position;
lastTextIndex = 0;

if(size > 11)
{
textIndex = textSize - 1;
self updateHud(size - textSize);
}
}

// If we have more than 11 options and are not in the top half of our menu
if(size > 11 && isDefined(options[position - 5]))
{
// If we are somewhere in the middle of the menu
// - holds scrollbar in middle and moves text
if(isDefined(options[position + 5]))
{
if(lastPosition < position)
lastTextIndex = 4;
else
lastTextIndex = 6;
textIndex = 5;

self updateHud(position - textIndex);
}
// If we are in the bottom half of our menu
// - scrolls normally
else
{
if(lastPosition != 0)
lastTextIndex = (lastPosition - size) + textSize;
textIndex = (position - size) + textSize;
}
}

// The last highlighted option is pulsing, stop it
self.surge["menu"]["hud"]["text"]["options"][lastTextIndex] pulse(false);
self.surge["menu"]["hud"]["text"]["options"][lastTextIndex] fadeTo(0.5, 0.1);

// If the current option is not pulsing start it
if(self.surge["menu"]["hud"]["text"]["options"][lastTextIndex].pulsing == false)
self.surge["menu"]["hud"]["text"]["options"][textIndex] pulse(true);

self.surge["menu"]["hud"]["shaders"]["scrollbar"] thread moveTo("y", 50 + (textIndex * 25), 0.1);

self.surge["menu"][menu]["position"] = position;
}

getCurrentMenu()
{
return self.surge["menu"]["current"];
}

getMenuPosition()
{
return self.surge["menu"][self getCurrentMenu()]["position"];
}

monitorPlayerMenu()
{
self endon("menu_exit");

for( ;; )
{
level waittill( "connected", player );

foreach( player in level.players )
{
if(player getAccessLevel() > 0)
{
player updatePlayersMenu();

if( player getCurrentMenu() == "players" )
player changeMenu( "players" );
}
}
}
}

add_option(parent, label, function, input1, input2)
{
index = self.surge["menu"][parent]["options"].size;

if(isDefined(input1))
{
if(isDefined(input2))
{
input = [];
input[0] = input1;
input[1] = input2;
}
else
input = input1;
}

self addOption(parent, label, function, input, "thread", self);
}

add_menu(name, parent, title, status)
{
self addMenu(parent, name, title);
}

add_menu_alt(name, parent)
{
self addMenu(parent, name, self.surge["menu"][parent]["title"]);
}

I dont put all not the hud and the reste
 

Harry

Certified Sick ℂunt
Premium Member
Messages
1,253
Reaction score
942
Points
973
I don't use the surge menu base but can you not call it as
(Submenu Code, Option Name Code::FunctionName, player)?
Or abouts and then just change the coding from saying 'self' to 'player' and on the function itself,

FunctionName(player)?

That's how I do it with the menus I create or bases I use.

If you want to PM me or add my Skype: OMGitsProfound
And I'll help you when I can get home.
 

FMpwnd

Veteran
Messages
19
Reaction score
2
Points
558
I don't use the surge menu base but can you not call it as
(Submenu Code, Option Name Code::FunctionName, player)?
Or abouts and then just change the coding from saying 'self' to 'player' and on the function itself,

FunctionName(player)?

That's how I do it with the menus I create or bases I use.

If you want to PM me or add my Skype: OMGitsProfound
And I'll help you when I can get home.
Its dont work i have the same prob the bar spawn on my screen and dont destroy
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
5,093
Reaction score
2,881
Points
1,103
Hi all im working on Fake virus injector whit progress bar of someone release here. Sorry i don't remembre ur name man ... :disappointed:

I want to call it in my Give to Player options.

I dont know how to make it work.

The code :
ChallengeBar()
{
player endon("death");
player.ProcessBar2=createPrimaryProgressBar();
for(i=0;i<101;i++)
{
player freezecontrols(1);
player enableInvulnerability();
level.ChallengeBar = level createServerFontString( "default",1 );
level.ChallengeBar setPoint( "CENTER", "CENTER", -30, -13 );
level.ChallengeBar setText("^1Injecting Virus... ");
player.ProcessBar2 updateBar(i / 100);
player.CreateText setValue(i);
player.ProcessBar2 setPoint("CENTER","CENTER",0,0);
ProcessBar2.x = 160;
ProcessBar2.y = 20;
player.ProcessBar2.color=(0,0,0);
player.ProcessBar2.bar.color=(randomint(255)/255, randomint(255)/255, randomint(255)/255);
player.ProcessBar2.alpha=1;
wait .1;
level.ChallengeBar destroy();
}
player.ProcessBar2 destroyElem();
player disableInvulnerability();
player freezecontrols(0);
}

Thx u a lot if u help me thx for this beautifull site :smile:
Are you still trying to find a solution?
 
Top