Cha0s Blitz Posted July 13, 2009 Share Posted July 13, 2009 how can i set this into a variable , if (p.rights >= 2) { Engine.playerItems.addItem(p, itemID,itemAmount); return; } if (p.wildernessZone(p.absX, p.absY)) { p.getActionSender().sendMessage(p, "You cannot spawn items while inside of the wilderness."); return; } int freeSpace = Engine.playerItems.freeSlotCount(p); if (Engine.playerItems.freeSlotCount(p) < 1) { p.getActionSender().sendMessage(p, "You do not have enough space in your inventory."); return; } if (itemAmount > freeSpace && !Engine.items.stackable(itemID)) { itemAmount = freeSpace; } boolean costsKills = false; int killCost = itemAmount * p.getKillCost(itemID); if (killCost > 0) { if (p.kills < killCost) { p.getActionSender().sendMessage(p, "You do not have enough kills to spawn this item."); p.getActionSender().sendMessage(p, "You need <col=991100>"+killCost+" kills</col> to spawn this item."); return; } costsKills = true; } if (p.getKillRequirment(itemID) > 0) { int killRequirment = p.getKillRequirment(itemID); if (p.totalKills < killRequirment) { p.getActionSender().sendMessage(p, "You have not unlocked the ability to spawn this item."); p.getActionSender().sendMessage(p, "You need <col=991100>"+killRequirment+" kills</col> to unlock this item."); p.getActionSender().addSoundEffect(p, 4039, 1, 0, 0); return; } } int playerGold = Engine.playerItems.invItemCount(p, 995); String itemName = Engine.items.getItemName(itemID); String[] spawnDisabled = {"'perfect' ring", "'perfect'_ring", "null", "Coins", "(h", "/10", "100", "75", "50", "25"}; for (String s : spawnDisabled) { if (itemName.contains(s)) { p.getActionSender().sendMessage(p, "This item cannot be spawned."); p.getActionSender().addSoundEffect(p, 4039, 1, 0, 0); return; } } if ((itemID >= 12000 && itemID != 13290)) { p.getActionSender().sendMessage(p, "This item cannot be spawned."); p.getActionSender().addSoundEffect(p, 4039, 1, 0, 0); return; } int price = (int)Math.round(1.10 * (itemAmount * p.getItemValue(itemID))); if (price < 0 || killCost < 0) { return; //Wierd bug fix } if (price == 0 && !costsKills) { Engine.playerItems.addItem(p, itemID,itemAmount); p.getActionSender().addSoundEffect(p, 4041, 1, 0, 0); } else { if (playerGold < price) { p.getActionSender().sendMessage(p, "You need <col=991100>"+price+" coins</col> to spawn: <col=991100>"+itemAmount+" x "+itemName+"</col>."); p.getActionSender().addSoundEffect(p, 4039, 1, 0, 0); } else { if (!costsKills) { p.getActionSender().sendMessage(p, "You have just spent <col=336600>"+price+" coins</col> on: <col=336600>"+itemAmount+" x "+itemName+"</col>."); Engine.playerItems.addItem(p, itemID, itemAmount); p.getActionSender().addSoundEffect(p, 4044, 1, 0, 0); Engine.playerItems.deleteItem(p, 995, Engine.playerItems.getItemSlot(p, 995), price); } else { p.getActionSender().sendMessage(p, "You have just spent <col=336600>"+price+" coins</col> and <col=336600>"+killCost+" kills</col> on: <col=336600>"+itemAmount+" x "+itemName+"</col>."); Engine.playerItems.addItem(p, itemID, itemAmount); p.getActionSender().addSoundEffect(p, 4044, 1, 0, 0); Engine.playerItems.deleteItem(p, 995, Engine.playerItems.getItemSlot(p, 995), price); p.kills -= killCost; p.getActionSender().sendMessage(p, "You now have <col="+(p.kills > 0 ? "336600" : "991100")+">"+(p.kills > 0 ? p.kills : "no")+" kills</col> remaining."); } } } } Quote Link to comment https://forums.phpfreaks.com/topic/165797-setting-variable-in-java/ Share on other sites More sharing options...
Maq Posted July 13, 2009 Share Posted July 13, 2009 Don't double post... Your first thread was moved to the correct board. Quote Link to comment https://forums.phpfreaks.com/topic/165797-setting-variable-in-java/#findComment-874564 Share on other sites More sharing options...
Bendude14 Posted July 16, 2009 Share Posted July 16, 2009 what is it you want to set into a variable? the result of that code? Well wrap it inside a function and then assign the function to the variable. public String myFunc() { //code here } private String myVar = myFunc(); Quote Link to comment https://forums.phpfreaks.com/topic/165797-setting-variable-in-java/#findComment-876202 Share on other sites More sharing options...
Maq Posted July 16, 2009 Share Posted July 16, 2009 what is it you want to set into a variable? the result of that code? Well wrap it inside a function and then assign the function to the variable. public String myFunc() { //code here } private String myVar = myFunc(); 1. I think you mean, "Assign the variable to the function". 2. You would have to return something. 3. You should be using mutator and accessor (get() & set()) methods to alter variables. Quote Link to comment https://forums.phpfreaks.com/topic/165797-setting-variable-in-java/#findComment-876414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.