How to use GUIPlayer in this code

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

User avatar
alividerci
Posts: 363
Joined: 11 Feb 2012, 07:03

Re: How to use GUIPlayer in this code

Post by alividerci »

steeffeen wrote:
alividerci wrote:I do not understand how I act .. can you show me how to do it
thx
i don't really want to support your way of programming, copy-pasting all the code that others suggest.. but here is your first step anyways:

client-side script:

Code: Select all

declare netwrite Ident Net_GUIPlayerId for UI;
Net_GUIPlayerId = GUIPlayer.Id;
server-side script:

Code: Select all

declare netread Net_GUIPlayerId for UI = NullId;
if (Players.existskey(Net_GUIPlayerId)) {
declare GUIPlayer <=> Players[Net_GUIPlayerId];
}
thx i trying do something
p.s i am not like a pro in programming now
User avatar
steeffeen
Translator
Translator
Posts: 2463
Joined: 14 Oct 2012, 16:22
Location: Germany

Re: How to use GUIPlayer in this code

Post by steeffeen »

alividerci wrote:p.s i am not like a pro in programming now
that's no problem, everybody is starting some-when and somehow, but if you ask me the better way to learn stuff is by doing it yourself
    Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

    ManiaControl, FancyManiaLinks
    User avatar
    Eole
    Nadeo
    Nadeo
    Posts: 1265
    Joined: 26 Apr 2011, 21:08

    Re: How to use GUIPlayer in this code

    Post by Eole »

    What are trying to achieve exactly Alividerci? Could you give us more details so we can help you. If you can't explain it well in english maybe you can ask someone to translate it for you. But currently it's really difficult to understand what you're trying to do, and so it's difficult to guide you.

    It seems there's one concept you didn't understand. There is a big difference between the script of your game mode and the script of a Manialink UI. The first is executed on the server and the second on the client.
    It works like that:
    - The server loads your game mode script and executes it.
    - At some point in the mode you create an UI.
    - By default nothing happen and nobody can see it.
    - You must "attach/send" this UI to the players.
    - When you do that the Manialink UI string is sent by the server to the players that must display this interface.
    - The interface arrives on the PC of the players and then the script that is located inside this Manialink is executed on the PC of the player.

    That's why the GUIPlayer variable exists only inside the interface. It represent your player when the code is executed on your PC. It can't exists on the game mode script because the server is not a player: he doesn't spawn nor have any armors, etc.

    It's difficult to explain but it's important to understand that concept.
    Contribute to the ManiaPlanet documentation on GitHub
    A question about ManiaScript? Ask it here!
    User avatar
    alividerci
    Posts: 363
    Joined: 11 Feb 2012, 07:03

    Re: How to use GUIPlayer in this code

    Post by alividerci »

    steeffeen wrote: that's no problem, everybody is starting some-when and somehow, but if you ask me the better way to learn stuff is by doing it yourself
    naturally :thumbsup:
    User avatar
    alividerci
    Posts: 363
    Joined: 11 Feb 2012, 07:03

    Re: How to use GUIPlayer in this code

    Post by alividerci »

    ok i am give some photos
    player
    http://img839.imageshack.us/img839/355/36368637.png
    GUIPlayer( :? )
    http://img607.imageshack.us/img607/9279/91160824.png
    i think your understand what i want to do
    User avatar
    Eole
    Nadeo
    Nadeo
    Posts: 1265
    Joined: 26 Apr 2011, 21:08

    Re: How to use GUIPlayer in this code

    Post by Eole »

    There's a player that is spawned on the first screenshot and a player that spectates the first one on the second screenshot.
    The first player have 0-0-0-1 ammo and you want that the player who spectates him in the second screenshot see that he has 0-0-0-1 ammo and not 0-0-0-0. That's what you're trying to do?
    Contribute to the ManiaPlanet documentation on GitHub
    A question about ManiaScript? Ask it here!
    User avatar
    steeffeen
    Translator
    Translator
    Posts: 2463
    Joined: 14 Oct 2012, 16:22
    Location: Germany

    Re: How to use GUIPlayer in this code

    Post by steeffeen »

    i think so, i guess i would do it by declaring the net variables for each player himself instead of his UI
    then you can access them via GUIPlayer
      Game Mode and Title Pack Creator, Developer, ShootMania-Player & more

      ManiaControl, FancyManiaLinks
      User avatar
      alividerci
      Posts: 363
      Joined: 11 Feb 2012, 07:03

      Re: How to use GUIPlayer in this code

      Post by alividerci »

      Eole wrote:There's a player that is spawned on the first screenshot and a player that spectates the first one on the second screenshot.
      The first player have 0-0-0-1 ammo and you want that the player who spectates him in the second screenshot see that he has 0-0-0-1 ammo and not 0-0-0-0. That's what you're trying to do?
      exactly!!!
      for word
      this we get UI each player when we will play

      Code: Select all

      declare UI <=> UIManager.GetUI(_Player);
      maybe i can to get for other action(change _Player)?
      User avatar
      Eole
      Nadeo
      Nadeo
      Posts: 1265
      Joined: 26 Apr 2011, 21:08

      Re: How to use GUIPlayer in this code

      Post by Eole »

      Okay. To do that you need to learn something you new.

      You can declare netwrite/netread variables for three types of objects:
      - UI
      - Player
      - Team

      Each one have different characteristics.
      Lets say you have this code somewhere in your game mode script:

      Code: Select all

      declare I = 0;
      foreach (Player in Players) {
        I += 1;
        // Declare a variable for UI
        declare UI <=> UIManager.GetUI(Player);
        if (UI != Null) {
          declare netwrite Integer UI_Variable for UI;
          UI_Variable = I;
        }
      
        // Declare a variable for Player
        declare netwrite Integer Player_Variable for Player;
        Player_Variable = 1000 + I;
      }
      // Declare a variable for team
      declare netwrite Integer Team_Variable for Teams[0];
      Team_Variable = -10;
      
      And now you create an UI with this code inside it and send it to three players: Player1, Player2 and Player3

      Code: Select all

      declare netread Integer UI_Variable for UI;
      log(UI_Variable);
      
      Each UI will log something different. Player1 will log 1, Player2 -> 2 and player3 -> 3. Because you read a variable declared for UI and in a manialink script you can only access your own UI. You can't access to the value of UI_Variable for Player2 if you're Player1. You must use another method.

      If you create an UI with this code:

      Code: Select all

      foreach (Player in Players) {
        declare netread Integer Player_Variable for Player;
        log(Player_Variable);
      }
      
      Then Player1 will log 1001,1002,1003. Player2 -> 1001,1002,1003. Player3: 1001,1002,1003. You can access to all the variables declared for a player from any UI.
      Alternatively if you use this code:

      Code: Select all

      declare netread Integer Player_Variable for InputPlayer;
      log(Player_Variable);
      
      Player1 will log 1001, Player2 -> 1002 and Player3 -> 1003. InputPlayer represents yourself, so you access to the value of Player_Variable that you save in your player.

      Code: Select all

      declare netread Integer Player_Variable for GUIPlayer;
      log(Player_Variable);
      
      If Player1 spectates Player3 then it will logs 1003. If Player2 spectates Player1 it will logs 1001. Because GUIPlayer represents the player you're spectating.

      And the last one with this code in your UI:

      Code: Select all

      declare netread Integer Team_Variable for Teams[0];
      log(Team_Variable);
      
      With this one the three UI will log the same value of -10.

      To sum it up:
      - declare netwrite MyVariable for UI -> only the player owning this UI can access this variable. If you change the value only one player will see something change. Use this if only you must have access to the value. Eg: My best time in a Time Attack mode.
      - declare netwrite MyVariable for Player -> the UI can access to all the players and so access to any variable declared for Player. If you change the value of this variable it will be shared with all other players. Use this if you want a value specific to a player to be shared with all other players. Eg: My number of ammo.
      - declare netwrite MyVariable for Teams[0] -> the UI can access this variable and it's shared between all players. Use this if you want to share a common value with all other players. Eg: The current score on the map.

      So in your case you must use a netwrite for Player.
      Contribute to the ManiaPlanet documentation on GitHub
      A question about ManiaScript? Ask it here!
      User avatar
      alividerci
      Posts: 363
      Joined: 11 Feb 2012, 07:03

      Re: How to use GUIPlayer in this code

      Post by alividerci »

      if i understand correctly then i must write >>>

      Code: Select all

      declare netread Text Weapon_UI for UI;
      declare netread Text Weapon_UI for GUIPlayer;
      i am right?
      Post Reply

      Return to “ManiaScript”

      Who is online

      Users browsing this forum: No registered users and 0 guests