Team Spartan Cookies & Milk Forums
HELP! with find() - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Expression 2 (https://teamscm.co.uk/forum-6.html)
+--- Thread: HELP! with find() (/thread-737.html)

Pages: 1 2


HELP! with find() - Alanzote - 19-02-2015

Hi!, I am making a transporter EGP, and I use findByClass("player") to search for players and display them on the screen, but when I press a button on the EGP, it searches for a trasporter pad, with a specific owner, this especific owner is the one we selected on the screen, but I can't use findResult(1) in the other search, so, Is there a way that I can use a variable that fixes the Entity name on it, without using findResult(NUM)? Because it is checking for the 1st pad it finds owner, not the selected one!

Thank ypu for your attention,
Alanzote.


RE: HELP! with find() - Alanzote - 20-02-2015

Anyone?


RE: HELP! with find() - Blackhawk - 20-02-2015

You can store the players in an array:
Code:
Players = findByClass("player")

Then you can access the players by their find index with:
Code:
Players[index]

I'm not 100% sure if it works exactly like that in e2 (haven't used e2 for a while).


RE: HELP! with find() - TheOneAndOnlyTee - 21-02-2015

Better to just use since it's less ops
Code:
if(changed(players()){ Players = players() }

Then just access it as Black said, also remember to persist Players:array


RE: HELP! with find() - Alanzote - 21-02-2015

(20-02-2015, 11:38 PM)Blackhawk Wrote: You can store the players in an array:
Code:
Players = findByClass("player")

Then you can access the players by their find index with:
Code:
Players[index]

I'm not 100% sure if it works exactly like that in e2 (haven't used e2 for a while).
I got an Error: "No such Operator: get array[normal]"

(21-02-2015, 04:52 AM)T-16 Wrote: Better to just use since it's less ops
Code:
if(changed(players()){ Players = players() }

Then just access it as Black said, also remember to persist Players:array
I also got an Error: "No Such function: Changed(array)"


RE: HELP! with find() - Blackhawk - 21-02-2015

This code should help you. It prints a list of all players into the chat:
Code:
@name Player-List @persist Players:array Players = players() for (I=1, Players:count()) { print(Players[I, entity]:name()) }



RE: HELP! with find() - TheOneAndOnlyTee - 22-02-2015

oh right didn't see that, Fix:
Code:
if(changed(players():count())){ Players = players() }
and if you wanted to know how you could display an entire list for your screen, Example:
Code:
@name Example Array Draw @inputs EGP:wirelink @persist Players if(first()|duped()|changed(EGP)){ EGP:egpBox(1,vec2(256,256),vec2(512,512)) EGP:egpColor(1,vec(0,164,255)) EGP:egpBox(2,vec2(256,256),vec2(492,492)) EGP:egpColor(2,vec(41,41,41)) Players = players() for(I =1,Players:count()){ EGP:egpText(2+I,Players[I,entity]:name(),vec2(50,50*I)) EGP:egpColor(2+I,vec(0,164,255)) } }



RE: HELP! with find() - Alanzote - 28-02-2015

When it prints, it shows something like that:
[Player, [1],[NAME]][Player, [2]...][Player, [3]...][Player, [5]...][Player, [7]...][Player, [8]...] as you can see it jumps some numbers.


RE: HELP! with find() - Blackhawk - 28-02-2015

As far as I know, the player index jumps some numbers because players are leaving/joining all the time, which manipulates the index. The important thing is, does it show all players or are there some names missing?


RE: HELP! with find() - Alanzote - 28-02-2015

(28-02-2015, 02:46 PM)Blackhawk Wrote: As far as I know, the player index jumps some numbers because players are leaving/joining all the time, which manipulates the index. The important thing is, does it show all players or are there some names missing?
No missing players, but I think the numbers should be allways 1,2,3,4,5... because it is bugging with my E2, so then you are selecting the wrong player.