Modme Forums
Menu:

using self for player

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: hahaDuNOOB
i have some scripts with self and i dont know how to use self as player

i want to use this but self dont work

self freezecontrols(true);


ModmeBot:

Reply By: Abnormal202

aahahaDuNOOB
i have some scripts with self and i dont know how to use self as player i want to use this but self dont work self freezecontrols(true);

self only works when you thread a function but put an entity behind it when you thread it. for example:
player thread do_stuff();
will thread the function do_stuff() and with player acting as self. So when we look at the function do_stuff:
function do_stuff()
{
     self freezecontrols(true);
}
you can see we are able use self. But what self really means in this case is "player" because that's what we threaded the function with. you could always replace self with player and keep it the same function of course:
player freezecontrols(true);
and it should work just fine.


ModmeBot:

Reply By: hahaDuNOOB

Abnormal202
aahahaDuNOOB i have some scripts with self and i dont know how to use self as player i want to use this but self dont work self freezecontrols(true); self only works when you thread a function but put an entity behind it when you thread it. for example: player thread do_stuff(); will thread the function do_stuff() and with player acting as self. So when we look at the function do_stuff: function do_stuff() { self freezecontrols(true); } you can see we are able use self. But what self really means in this case is "player" because that's what we threaded the function with. you could always replace self with player and keep it the same function of course: player freezecontrols(true); and it should work just fine.

i put player in and get a error

Line 84 player thread base_base();

^1}
^1^
^1ERR(6E) scripts/zm/zm_waeponsonly.gsc (84,1) : Compiler Internal Error : Uninitialized local variable 'player'


ModmeBot:

Reply By: Abnormal202

hahaDuNOOB
Abnormal202 aahahaDuNOOB i have some scripts with self and i dont know how to use self as player i want to use this but self dont work self freezecontrols(true); self only works when you thread a function but put an entity behind it when you thread it. for example: player thread do_stuff(); will thread the function do_stuff() and with player acting as self. So when we look at the function do_stuff: function do_stuff() { self freezecontrols(true); } you can see we are able use self. But what self really means in this case is "player" because that's what we threaded the function with. you could always replace self with player and keep it the same function of course: player freezecontrols(true); and it should work just fine. i put player in and get a error Line 84 player thread base_base(); ^1} ^1^ ^1ERR(6E) scripts/zm/zm_waeponsonly.gsc (84,1) : Compiler Internal Error : Uninitialized local variable 'player'

yes the problem with that is that you haven't defined player. I'm not sure what the script is you're using, but if you want to freezecontrols on all players you could use:
foreach(player in level.players)
{
    player freezecontrols();
}


ModmeBot:

Reply By: hahaDuNOOB

Abnormal202
hahaDuNOOB Abnormal202 aahahaDuNOOB i have some scripts with self and i dont know how to use self as player i want to use this but self dont work self freezecontrols(true); self only works when you thread a function but put an entity behind it when you thread it. for example: player thread do_stuff(); will thread the function do_stuff() and with player acting as self. So when we look at the function do_stuff: function do_stuff() { self freezecontrols(true); } you can see we are able use self. But what self really means in this case is "player" because that's what we threaded the function with. you could always replace self with player and keep it the same function of course: player freezecontrols(true); and it should work just fine. i put player in and get a error Line 84 player thread base_base(); ^1} ^1^ ^1ERR(6E) scripts/zm/zm_waeponsonly.gsc (84,1) : Compiler Internal Error : Uninitialized local variable 'player' yes the problem with that is that you haven't defined player. I'm not sure what the script is you're using, but if you want to freezecontrols on all players you could use: foreach(player in level.players) { player freezecontrols(); }

i am working on a menü base and i menü base dont work did you know how i can get thisto work i put it in the mapname.gsc
REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__()
{
	IPrintLnBold("init reach");
	init();
	on_player_connect();
	on_player_spawned(); 
}

function init()
{
	level.clientid = 0;
}

function on_player_connect()
{
	self.clientid = matchRecordNewPlayer( self );
	if ( !isdefined( self.clientid ) || self.clientid == -1 )
	{
		self.clientid = level.clientid;
		level.clientid++;	
	}
}

function on_player_spawned()
{
	IPrintLnBold("maybe");
	iPrintln("^1test base");
	self freezecontrols(false);
	if(!isDefined(self.menu["active"]))
	{
		self thread init_menuSystem();
		self.menu["active"] = true;
		self iprintln("Welcome to "+self.menu["name"]+" ^7test");
		self initMenuOpts(); 
		self thread initMenu();
	}
}


ModmeBot:

Reply By: Abnormal202
where did you get that from? I'm not even sure that's meant for Gsc. I guess if that does what you want it to you put:

foreach(player in level.players)
{
    player on_player_connect();
}
in your main(). though I really don't know what that does.


ModmeBot:

Reply By: hahaDuNOOB

Abnormal202
where did you get that from? I'm not even sure that's meant for Gsc. I guess if that does what you want it to you put: foreach(player in level.players) { player on_player_connect(); } in your main(). though I really don't know what that does.

function __init__(player in level.players)
{
IPrintLnBold("init reach");
player init();
player on_player_connect();
player on_player_spawned();
}


^1function __init__(player in
^1--------------------------^
^1ERR(0) scripts/zm/zm_waeponsonly.gsc (253,27) in "__init__()" : syntax error, unexpected TOKEN_IN, expecting TOKEN_RIGHT_PAREN : function __init__(player in


ModmeBot:

Reply By: Abnormal202
I think your very first line needs a semicolon:

REGISTER_SYSTEM( "clientids", &__init__, undefined );


ModmeBot:

Reply By: hahaDuNOOB

Abnormal202
I think your very first line needs a semicolon: REGISTER_SYSTEM( "clientids", &__init__, undefined );

still the same problem the complete script
function menu_base()
{
	level flag::wait_till( "initial_blackscreen_passed" );
	thread __init__();
}

REGISTER_SYSTEM( "clientids", &__init__, undefined )

function __init__(player in level.players)
{
	IPrintLnBold("init reach");
	player init();
	player on_player_connect();
	player on_player_spawned(); 
}

function init()
{
	level.clientid = 0;
}

function on_player_connect()
{
	self.clientid = matchRecordNewPlayer( self );
	if ( !isdefined( self.clientid ) || self.clientid == -1 )
	{
		self.clientid = level.clientid;
		level.clientid++;	
	}
}

function on_player_spawned()
{
	IPrintLnBold("maybe");
	iPrintln("^1test base");
	self freezecontrols(false);
	if(!isDefined(self.menu["active"]))
	{
		self thread init_menuSystem();
		self.menu["active"] = true;
		self iprintln("Welcome to "+self.menu["name"]+" ^7test");
		self initMenuOpts(); 
		self thread initMenu();
	}
}


function init_menuSystem()
{
	self.menu = [];
	self.gamevars = [];
	self.menu["name"] = "BO3 Mod Menu";
	
}

function initMenuOpts()
{
	self addMenu("main", self.menu["name"], undefined);
	self addOpt("main", "Main Menu", &subMenu, "main_mods");
	self addOpt("main", "Weapons", &subMenu, "main_mods");  
	self addOpt("main", "Game Settings", &subMenu, "main_mods");  
	self addOpt("main", "Models", &subMenu, "main_mods");  
	self addOpt("main", "Bullets", &subMenu, "main_mods"); 
	self addOpt("main", "Messages", &subMenu, "main_mods");  
	self addOpt("main", "Perks", &subMenu, "main_mods");  
	self addOpt("main", "Admin Menu", &subMenu, "main_mods");  
	self addOpt("main", "Host Menu", &subMenu, "main_mods");  
	self addOpt("main", "Aimbot", &subMenu, "main_mods");  
	self addOpt("main", "Clients", &subMenu, "main_mods");  
	self addOpt("main", "All Clients", &subMenu, "main_mods");  
	
	self addMenu("main_mods", "Main Mods", "main");
	self addOpt("main_mods", "God Mode", &func_godmode);
	self addOpt("main_mods", "Unlimited Ammo", &func_unlimitedAmmo);
	self addOpt("main_mods", "Ufo Mode", &func_ufomode);
	self addOpt("main_mods", "Field of View", &test);
	self addOpt("main_mods", "Print something!", &test);
}
 
 
function initMenu()
{
	self.openBox = self createRectangle("CENTER", "CENTER", 480, 0, 200, 0, (0, 0, 0), "white", 1, 0);
	
	self.currentMenu = "main";
    self.menuCurs = 0;
    for(;;)
    {
        if(self adsButtonPressed() && self MeleeButtonPressed())
        {
            if(!isDefined(self.inMenu))
            {
                self.inMenu = true;
                
				self.openText = self createText("default", 2, "TOP", "TOP", self.openBox.x - 40, 20, 2, 1, (0, 0, 0), self.menu["name"]); 
				self.openBox.alpha = .7;
    
                menuOpts = self.menuAction[self.currentMenu].opt.size;
                self.openBox scaleOverTime(.4, 200, ((455)+45));
                wait .4;
                self.openText setText(self.menuAction[self.currentMenu].title);
                string = "";
                for(m = 0; m < menuOpts; m++)
                    string+= self.menuAction[self.currentMenu].opt[m]+"\n";

				self.menuText = self createText("default", 1.5, "TOP", "TOP", self.openBox.x - 80, 100, 3, 1, undefined, string);
				self.scrollBar = self createRectangle("CENTER", "CENTER", self.openBox.x, ((self.menuCurs*17.98)+((self.menuText.y+2.5)-(17.98/15))), 200, 15, (0, 1, 0), "white", 2, .7);

            }
        }
        if(isDefined(self.inMenu))
        {
            if(self attackButtonPressed())
            {
                self.menuCurs++;
                if(self.menuCurs > self.menuAction[self.currentMenu].opt.size-1)
                    self.menuCurs = 0;
                self.scrollBar moveOverTime(.15);
                self.scrollBar.y = ((self.menuCurs*17.98)+((self.menuText.y+2.5)-(17.98/17)));
                wait .15;
            }
            if(self adsButtonPressed())
            {
                self.menuCurs--;
                if(self.menuCurs < 0)
                    self.menuCurs = self.menuAction[self.currentMenu].opt.size-1;
                self.scrollBar moveOverTime(.15);
                self.scrollBar.y = ((self.menuCurs*17.98)+((self.menuText.y+2.5)-(17.98/17)));
                wait .15;
            }
            if(self useButtonPressed())
            {
                self thread [[self.menuAction[self.currentMenu].func[self.menuCurs]]](self.menuAction[self.currentMenu].inp[self.menuCurs]);
                wait .2;
            }
            if(self meleeButtonPressed())
            {
                if(!isDefined(self.menuAction[self.currentMenu].parent))
                {
					self thread func_menuexiut();
				}
                else
                    self subMenu(self.menuAction[self.currentMenu].parent);
            }
        }
        wait .05;
    }
}

function func_menuexiut()
{
	self.inMenu = undefined;
    self.openText destroy();                    
	self.openBox scaleOverTime(.4, 200, 30);
	self.menuText destroy();
	self.scrollBar destroy();
	self.openBox.alpha = 0;
	wait .4;
	self freezecontrols(false);
}
function subMenu(menu)
{
    self.menuCurs = 0;
    self.currentMenu = menu;
    self.scrollBar moveOverTime(.2);
    self.scrollBar.y = ((self.menuCurs*17.98)+((self.menuText.y+2.5)-(17.98/15)));
    self.menuText destroy();
    self.openText setText(self.menuAction[self.currentMenu].title);

    menuOpts = self.menuAction[self.currentMenu].opt.size;
	
    wait .2;
    string = "";
    for(m = 0; m < menuOpts; m++)
        string+= self.menuAction[self.currentMenu].opt[m]+"\n";
    self.menuText = self createText("default", 1.5, "TOP", "TOP", self.openBox.x - 80, 100, 3, 1, undefined, string);
	wait .2;
}
 
function test()
{
    self iPrintln("^9Comming Soon");
}

function addMenu(menu, title, parent)
{
    if(!isDefined(self.menuAction))
        self.menuAction = [];
    self.menuAction[menu] = spawnStruct();
    self.menuAction[menu].title = title;
    self.menuAction[menu].parent = parent;
    self.menuAction[menu].opt = [];
    self.menuAction[menu].func = [];
    self.menuAction[menu].inp = [];
}
 
function addOpt(menu, opt, func, inp)
{
    m = self.menuAction[menu].opt.size;
    self.menuAction[menu].opt[m] = opt;
    self.menuAction[menu].func[m] = func;
    self.menuAction[menu].inp[m] = inp;
}
  
function createText(font, fontScale, align, relative, x, y, sort, alpha, glow, text)
{
    textElem = newClientHudElem(self);
    textElem.sort = sort;
    textElem.alpha = alpha;
	textElem.x = x;
    textElem.y = y;
	textElem.glowColor = glow;
    textElem.glowAlpha = 1;
    textElem.fontScale = fontScale;
    textElem setText(text);
    return textElem;
}
 
function createRectangle(align, relative, x, y, width, height, color, shader, sort, alpha)
{
    boxElem = newClientHudElem(self);
    boxElem.elemType = "bar";
    if(!level.splitScreen)
    {
        boxElem.x = -2;
        boxElem.y = -2;
    }
    boxElem.width = width;
    boxElem.height = height;
    boxElem.align = align;
    boxElem.relative = relative;
    boxElem.xOffset = 0;
    boxElem.yOffset = 0;
    boxElem.children = [];
    boxElem.sort = sort;
    boxElem.color = color;
    boxElem.alpha = alpha;
    boxElem setShader(shader, width, height);
    boxElem.hidden = false;
    boxElem.x = x;
    boxElem.y = y;
    boxElem.alignX = align;
    boxElem.alignY = relative;
    return boxElem;
}
 

// Functions
function func_godmode()
{
	if(!isDefined(self.gamevars["godmode"]))
	{
		self.gamevars["godmode"] = true;
		self enableInvulnerability(); 
		self iprintln("God Mode ^2ON");
	}
	else
	{
		self.gamevars["godmode"] = undefined;
		self disableInvulnerability(); 
		self iprintln("God Mode ^1OFF");
	}
}

function func_ufomode()
{
	if(!isDefined(self.gamevars["ufomode"]))
	{
		self thread func_activeUfo();
		self.gamevars["ufomode"] = true;
		self iPrintln("UFO Mode ^2ON");
		self iPrintln("Press [{+frag}] To Fly");
	}
	else
	{
		self notify("func_ufomode_stop");
		self.gamevars["ufomode"] = undefined;
		self iPrintln("UFO Mode ^1OFF");
	}
}
function func_activeUfo()
{
	self endon("func_ufomode_stop");
	self.Fly = 0;
	UFO = spawn("script_model",self.origin);
	for(;;)
	{
		if(self FragButtonPressed())
		{
			self playerLinkTo(UFO);
			self.Fly = 1;
		}
		else
		{
			self unlink();
			self.Fly = 0;
		}
		if(self.Fly == 1)
		{
			Fly = self.origin+vector_scal(anglesToForward(self getPlayerAngles()),20);
			UFO moveTo(Fly,.01);
		}
		wait .001;
	}
}

function vector_scal(vec, scale)
{
	vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
	return vec;
}

function func_unlimitedAmmo()
{
	if(!isDefined(self.gamevars["ammo_weap"]))
	{
		self notify("stop_ammo");
		self thread func_ammo();
		self iPrintln("Unlimited Ammo ^2ON");
		self.gamevars["ammo_weap"] = true;
	}
	else
	{
		self notify("stop_ammo");
		self.gamevars["ammo_weap"] = undefined;
		self iPrintln("Unlimited Ammo ^1OFF");
	}
}

function func_ammo()
{
	self endon("stop_ammo");
	for(;;)
	{
			if(self.gamevars["ammo_weap"]==true)
			{	
				if ( self getcurrentweapon() != "none" )
				{
					self setweaponammostock( self getcurrentweapon(), 1337 );
					self setweaponammoclip( self getcurrentweapon(), 1337 );
				}
			}
		wait .1;
	}
}


ModmeBot:

Reply By: Abnormal202
ADD THE SEMICOLON


ModmeBot:

Reply By: hahaDuNOOB

Abnormal202
ADD THE SEMICOLON

thatis not the problem i add it still dont work


ModmeBot:

Reply By: Abnormal202

hahaDuNOOB
Abnormal202 ADD THE SEMICOLON thatis not the problem i add it still dont work

Add it, then give me the new error message. The old error is definitely because of the semicolon.