Problem with variables

Started by LueLusten on Tue, 07/25/2017 - 14:35

Topic category: Bugs and solutions

Last seen on 22:52, 27. Oct 2017
Joined Nov 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Problem with variables
Tue, 07/25/2017 - 18:25 (edited)

I have a command what when a user does /claim the will claim a new set of times one time in the game, but the problem is when I create a new
world it has cashed the old settings and still says the user as already used the command.

Execute command below:

          public void execute(MinecraftServer server, ICommandSender var1, String[] cmd){           int i = var1.getPosition().getX();           int j = var1.getPosition().getY();           int k = var1.getPosition().getZ();           EntityPlayer entity = (EntityPlayer)var1;                      World world = null;           WorldServer[] list = server.worldServers;           for(WorldServer ins : list){           if(ins.provider.getDimension()==entity.worldObj.provider.getDimension())           world = ins;           }           if(world==null)           world = list[0];                       if(mcreator_VarList%MAINMODNAME%.Claimed){                          var1.addChatMessage(new TextComponentString(TextFormatting.DARK_RED+"[Starter Pack]"+TextFormatting.WHITE+" We are sorry "+var1.getName()+" but you have already claimed your starter pack"));                     }                     if(!mcreator_VarList%MAINMODNAME%.Claimed){                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.LEATHER_HELMET, 1));                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.LEATHER_CHESTPLATE, 1));                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.LEATHER_LEGGINGS, 1));                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.LEATHER_BOOTS, 1));                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.WOODEN_SWORD, 1));                          if(entity instanceof EntityPlayer)((EntityPlayer)entity).inventory.addItemStackToInventory(new ItemStack(Items.BREAD, 15));                          var1.addChatMessage(new TextComponentString(TextFormatting.DARK_RED+"[Starter Pack]"+TextFormatting.WHITE+" Your starter pack has now been claimed"));                          mcreator_VarList%MAINMODNAME%.Claimed = true;                     }                                }

How do I have it so if the user creates a new world it's no longer cashed

Edited by Klemen on Tue, 07/25/2017 - 18:25
Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Acutally it is not even a bug
Tue, 07/25/2017 - 14:52

Acutally it is not even a bug. They are global variables, so it is their function - stay global for the whole game session, because they are just saved in an instance of  mcreator_VarList. So you can do the dirty way of resetting the variables on disonnecting. This way would almost surely solve the problem for Singleplayer, but for LAN and Multiplayer it would be even much messier.
So the best thing to do is stop using the global variables for player/world specific data and use IExtendedEntityProperties, PERSISTED_NBT_TAG, or WorldSavedData, depending on your needs.

Last seen on 22:52, 27. Oct 2017
Joined Nov 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:Acutally it is not even a bug
Tue, 07/25/2017 - 15:09

@#1 I am bloody new to coding side to things, are you able to drop us a code that will show us how to do that, since that's not part of the MCreator, I know I going to have to code it but not really sure how, painful thing is any new classes I add MCrator just deletes :( sad days If I was able to remember code I would do it the right way but sadly I limited to the tool 

Any help would be gratful, and will I have import new options in to file?

Last seen on 22:52, 27. Oct 2017
Joined Nov 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Also it wont work if I make
Tue, 07/25/2017 - 15:11

Also it wont work if I make it do it on disconcting as the command needs to say active in that world so I gussing we have to save it to the world data folder or something

 

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
As far as I do not know even
Tue, 07/25/2017 - 15:32

As far as I do not know even what Minecraft version do you use it is hard to say any code + also as I said, there are multiple ways to do it depending on your actual needs , so if you, for example, want reset the ability for the player on death , use IExtendedEntityProperties , if not better use some other option.

Also pro tip, I have started coding in a version of MCreator where was not any option of custom classes, however the simplest way to do so is just creating a random element (I prefer most "Overlay") remove its content and use this class.
 

Last seen on 22:52, 27. Oct 2017
Joined Nov 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
RE:As far as I do not know even
Tue, 07/25/2017 - 15:36

@#3 Nice work around for the classes thanks I have to use that later for another idea, no we want it to only one once in the life time of the player joining that world far as I know, I am helping someone create a simple start up kit command so they use /claim and this works and then they do it again it says nope, but problem as you can see it works if you restart the game again and to use it on a new world you need to restart the game again lol

I just tried looking for users making one time commands in forge to study the code and not been able to find anything.

Last seen on 22:52, 27. Oct 2017
Joined Nov 2016
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I am using 1.7.1 (1.10.2)
Tue, 07/25/2017 - 15:37

I am using 1.7.1 (1.10.2)

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Well, you can get player
Tue, 07/25/2017 - 21:01

Well, you can get player NBTTagCompound using getEntityData() and then use getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG) to get the persisted NBTTagCompound, where you can read and write the boolean.