CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Gaming
Call of Duty Classics
Call of Duty: Black Ops 2
Call of Duty: Black Ops 2 Mods and Scripts
Call of Duty: Black Ops 2 Scripts
Add Player To Co-Host List
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="BullyWiiPlaza" data-source="post: 6540" data-attributes="member: 543"><p>Nice, I need to do this too but you guys are horrible for using a dvar for each player. Use an array kind of data structure for unlimited players and less messy code. Also please us the xuids, they are the "real" way of identifying players, not the name <img src="/styles/default/xenforo/smilies.emoji/people/expressionless.emoji.svg" class="smilie" loading="lazy" alt=":expressionless:" title="Expressionless :expressionless:" data-shortname=":expressionless:" /></p><p>[CODE]xuid = self getXuid();[/CODE]</p><p>Feel free to translate the code below to GSC. Sometimes debugging in a proper language can save you some time so don't be surprised why the heck someone used a different language.</p><p>[SPOILER="Java implementation example"]</p><p>[CODE]public class CoHostsManager</p><p>{</p><p> private String coHosts;</p><p> public static String delimiter = "#"; // level.coHostsDelimiter;</p><p></p><p> public CoHostsManager()</p><p> {</p><p> coHosts = "";</p><p> // level.coHosts = getDvar("coHosts");</p><p> // this.coHosts = TestPersistentCoHosts.coHostsDvar;</p><p> }</p><p></p><p> public boolean isCoHost(String xuid)</p><p> {</p><p> return coHosts.contains(xuid); // isSubStr(xuid, coHosts)</p><p> }</p><p></p><p> public void addCoHost(String xuid)</p><p> {</p><p> if (!isCoHost(xuid))</p><p> {</p><p> if (!coHosts.equals(""))</p><p> {</p><p> coHosts += delimiter;</p><p> }</p><p></p><p> coHosts += xuid;</p><p> System.out.println("Co-Host added"); // self iPrintln("...");</p><p></p><p> // setDvar("coHosts", coHosts);</p><p> // TestPersistentCoHosts.coHostsDvar = coHosts;</p><p> }</p><p> }</p><p></p><p> public void removeCoHost(String excludedXuid)</p><p> {</p><p> if (isCoHost(excludedXuid))</p><p> {</p><p> rebuildCoHosts(excludedXuid);</p><p></p><p> System.out.println("Co-Host removed"); // self iPrintln("...");</p><p> } else</p><p> {</p><p> System.out.println("^1Not added to Co-Hosts"); // self iPrintln("...");</p><p> }</p><p> }</p><p></p><p> private void rebuildCoHosts(String excludedXuid)</p><p> {</p><p> String[] coHostsArray = coHosts.split(delimiter); // strTok(level.coHosts, level.coHostsDelimiter);</p><p></p><p> coHosts = "";</p><p></p><p> for (String coHost : coHostsArray)</p><p> {</p><p> if (!coHost.equals(excludedXuid))</p><p> {</p><p> addCoHost(coHost);</p><p> }</p><p> }</p><p> }</p><p></p><p> @Override</p><p> public String toString()</p><p> {</p><p> return coHosts;</p><p> }</p><p>}[/CODE]</p><p>[/SPOILER]</p></blockquote><p></p>
[QUOTE="BullyWiiPlaza, post: 6540, member: 543"] Nice, I need to do this too but you guys are horrible for using a dvar for each player. Use an array kind of data structure for unlimited players and less messy code. Also please us the xuids, they are the "real" way of identifying players, not the name :expressionless: [CODE]xuid = self getXuid();[/CODE] Feel free to translate the code below to GSC. Sometimes debugging in a proper language can save you some time so don't be surprised why the heck someone used a different language. [SPOILER="Java implementation example"] [CODE]public class CoHostsManager { private String coHosts; public static String delimiter = "#"; // level.coHostsDelimiter; public CoHostsManager() { coHosts = ""; // level.coHosts = getDvar("coHosts"); // this.coHosts = TestPersistentCoHosts.coHostsDvar; } public boolean isCoHost(String xuid) { return coHosts.contains(xuid); // isSubStr(xuid, coHosts) } public void addCoHost(String xuid) { if (!isCoHost(xuid)) { if (!coHosts.equals("")) { coHosts += delimiter; } coHosts += xuid; System.out.println("Co-Host added"); // self iPrintln("..."); // setDvar("coHosts", coHosts); // TestPersistentCoHosts.coHostsDvar = coHosts; } } public void removeCoHost(String excludedXuid) { if (isCoHost(excludedXuid)) { rebuildCoHosts(excludedXuid); System.out.println("Co-Host removed"); // self iPrintln("..."); } else { System.out.println("^1Not added to Co-Hosts"); // self iPrintln("..."); } } private void rebuildCoHosts(String excludedXuid) { String[] coHostsArray = coHosts.split(delimiter); // strTok(level.coHosts, level.coHostsDelimiter); coHosts = ""; for (String coHost : coHostsArray) { if (!coHost.equals(excludedXuid)) { addCoHost(coHost); } } } @Override public String toString() { return coHosts; } }[/CODE] [/SPOILER] [/QUOTE]
Verification
Post reply
Forums
Gaming
Call of Duty Classics
Call of Duty: Black Ops 2
Call of Duty: Black Ops 2 Mods and Scripts
Call of Duty: Black Ops 2 Scripts
Add Player To Co-Host List
CabConModding is now on facebook! Check the latest Updates, the Site Status and much more now!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top