Yeah, it’s the title that explains my question.
basically all u need to do is this
Trigger: Every Frame (roughly 50ms)
for all players (In Human Players)
then do:
for all units (in game)
then do:
if (player name of (selected player) =! player name of (selected unit))
then do:
if ((points) of (selected player) > (points) of (owner of (selected unit))
then do:
set (server-king) as (player name of(selected player))
else do:
set (server-king) as (no one)
else do:
this will basically go through all players and units in the game that dont have the same name and set the variable (server-king) to the player name of the person with the most points
Why do you check every unit in the game for every player in the game? That’s a lot of unnecessary looping. Looks like you only ever compare two players without putting the existing server-king into the question. Also you don’t need the every frame trigger if you only need to check the server king at a given moment
its not gonna work if u just do all players thats why
You’ll probably need a global variable of type player, and a script like this:
set (leader) as (undefined value)
for all players in (human players)
do:
if ((leader) == (undefined value)) OR ((points of selected player) > (points of leader))
then do:
set (leader) as (selected player)
When the loop is finished, the value of the variable leader
will be the player with the highest points.
i like to do it the more complicated way lol
Why though? That’s detrimental to your game’s performance, hard to understand, and a waste of time…
lol i just like doing things the old way in case of deprecation and future reliability
Thanks for your input, RagDev and kyle69!
Wait, if leader
is an undefined value
, and the loop says for all players in (human players)
, who will become the leader?
leader is undefined value before the loop starts. When the loop runs its first iteration, leader will be set as the selected player (see if ((leader) == (undefined value))
). Then in the next iteration, it compares the current selected player’s points to the points of the previous selected player (which is leader). As long as there is 1 or more players in the game, leader will not be undefined value when the loop finishes
Oh, so loops do everyone one at a time. I thought it did everyone at the same time.
That’s not really a thing computers can do, unless they have a multi-core processor maybe. Loops run in iterations, one by one, and that’s why there’s only one selected player at a time.