UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Player-specific global variable

broken avatar :(
Created 9 years ago
by nabaro
0 Members and 1 Guest are viewing this topic.
2,016 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 22 January 2014
Last active: 3 years ago
Posts
143
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
nabaro's Groups
nabaro's Contact & Social Linkschelseafan122099nabarogamerblast11
How do I define a global variable that applies to only one player (whether they have a certain attribute or not)? Say I have this code:
Code Snippet
Plaintext
main()
{
flag_wait("all_players_connected");
players = get_players();
for(i = 0; i < players.size; i++)
{
level.players[i].hasability = 0;
players[i] thread give_ability();
}
}
give_ability()
{
self.hasability = 1;
}

Would the correct syntax be::
Code Snippet
Plaintext
level.self.hasability
, or
Code Snippet
Plaintext
self.hasability
, or something else, or is this not possible?

Thanks in advance for any replies!
Last Edit: November 18, 2014, 02:54:09 pm by nabaro
This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: usYork, SC
Date Registered: 15 March 2014
Last active: 5 years ago
Posts
214
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
WaW Scriptor
Signature
WaW Scriptor
×
PROxFTW's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
PROxFTW's Contact & Social LinksPROxFTWPROxFTWPROxFTWPROxFTW
Player variables are
Code Snippet
Plaintext
self. 
or
GetPlayers()[Num].
In your case of
Code Snippet
Plaintext
level.players[i].hasability
should be
Code Snippet
Plaintext
players[i].hasability
But the
Code Snippet
Plaintext
self.hasability = 1;
is correct
level variables like
Code Snippet
Plaintext
level.
is for the entire game.
Last Edit: November 18, 2014, 03:06:14 pm by PROxFTW
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 22 January 2014
Last active: 3 years ago
Posts
143
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
nabaro's Groups
nabaro's Contact & Social Linkschelseafan122099nabarogamerblast11
Are player variable inherently global, or do they need to be globalized by
Code Snippet
Plaintext
level.
? Because I want to use the player variable in various different scripts.
Marked as best answer by nabaro 9 years ago
broken avatar :(
×
broken avatar :(
Location: usYork, SC
Date Registered: 15 March 2014
Last active: 5 years ago
Posts
214
Respect
Forum Rank
Mr. Elemental
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
WaW Scriptor
×
PROxFTW's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
PROxFTW's Contact & Social LinksPROxFTWPROxFTWPROxFTWPROxFTW
Are player variable inherently global, or do they need to be globalized by
Code Snippet
Plaintext
level.
? Because I want to use the player variable in various different scripts.
level. and self. can be used in any gsc but with self. they will only work to that specific entity.
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 22 January 2014
Last active: 3 years ago
Posts
143
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Member
My Contact & Social Links
More
×
nabaro's Groups
nabaro's Contact & Social Linkschelseafan122099nabarogamerblast11
Alright, thank you!
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 6 months ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
Signature
Do not take life too seriously. You will never get out of it alive.
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Code Snippet
Plaintext
self
is not a player variable, it's the entity that's been called by the function.

Here's an empty stock script:
Code Snippet
Plaintext
#include common_scripts\utility;
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\_loadout;

init()
{
level thread onPlayerConnect();
}

onPlayerConnect()
{
for(;;)
{
level waittill( "connecting", player );
//I suggest placing variables here rather on oPS as in here it'll only be set once.
player thread onPlayerSpawned();
}
}

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

for(;;)
{
self waittill( "spawned_player" );
//whatever you want to set on player whenever they spawn EVERY TIME can be placed here.
}
}
Last Edit: November 18, 2014, 05:02:48 pm by DidUknowiPwn

 
Loading ...