Thread: magic spells

Results 1 to 10 of 10
  1. #1 magic spells 
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    so im working on making all spells work perfectly, i started with a basic reducing spell called confuse which is a lvl 3 spell that reduces your opponents attack by 5%. On actual rs it you can only cast it on a player if their stats have not already been reduced which is how im struggling to make it like that.
    My current code is this:
    Spoiler for Confuse:
    case 26: // confuse
    player.setNextAnimation(new Animation(716));
    mage_hit_gfx = 104;
    player.setNextGraphics(new Graphics(102, 0, 80));
    base_mage_xp = 13;
    magic_sound = 152;
    Hit special = getMagicHit(player, getRandomMagicMaxHit(player, 70));
    delayMagicHit(2, special);
    World.sendProjectile(new NewProjectile(player, target, 103, !player.withinDistance(target, 1) ? 40 : 15, 20, 65));
    if (target instanceof Player) {
    Player p = (Player) target;
    p.getSkills().drainLevel(0, p.getSkills().getLevel(0) / 5);
    p.getPackets().sendGameMessage("Your Attack skills have been drained.");
    player.getPackets().sendGameMessage("Your spell weakened your enemy.");
    }
    player.getPackets().sendGameMessage("Opponents attack has been reduced.");
    return 5;

    How can i make it so you cant cast it again on the same opponent if his attack is already reduced?
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jan 2019
    Posts
    26
    Thanks given
    4
    Thanks received
    16
    Rep Power
    29
    Quote Originally Posted by khayam View Post
    so im working on making all spells work perfectly, i started with a basic reducing spell called confuse which is a lvl 3 spell that reduces your opponents attack by 5%. On actual rs it you can only cast it on a player if their stats have not already been reduced which is how im struggling to make it like that.
    My current code is this:
    Spoiler for Confuse:
    case 26: // confuse
    player.setNextAnimation(new Animation(716));
    mage_hit_gfx = 104;
    player.setNextGraphics(new Graphics(102, 0, 80));
    base_mage_xp = 13;
    magic_sound = 152;
    Hit special = getMagicHit(player, getRandomMagicMaxHit(player, 70));
    delayMagicHit(2, special);
    World.sendProjectile(new NewProjectile(player, target, 103, !player.withinDistance(target, 1) ? 40 : 15, 20, 65));
    if (target instanceof Player) {
    Player p = (Player) target;
    p.getSkills().drainLevel(0, p.getSkills().getLevel(0) / 5);
    p.getPackets().sendGameMessage("Your Attack skills have been drained.");
    player.getPackets().sendGameMessage("Your spell weakened your enemy.");
    }
    player.getPackets().sendGameMessage("Opponents attack has been reduced.");
    return 5;

    How can i make it so you cant cast it again on the same opponent if his attack is already reduced?
    Add a variable to player class and create getter/setter for it. For the setter, you'll want the method to have value you're setting the variable to and the time or ticks until stat returns to normal/progress back to normal. Use that time/tick you sent in method to create a task that handles changing value overtime or resetting it to normal. When the task reaches the certain amount of ticks/time or player dies/logs etc, you'll want to set the variable back to false.

    Then you'll go back to your code for the spell and check if the variable is true. If it's true, it means player is already affected by a confuse spell. In terms of flexibility, could make an array or map for skills to use in long run instead of 20+ individual variables.
    Reply With Quote  
     

  3. #3  
    Registered Member
    bracket's Avatar
    Join Date
    Aug 2009
    Posts
    5,278
    Thanks given
    1,059
    Thanks received
    1,465
    Rep Power
    5000
    Code:
    if (getLevel(Skills.ATTACK) < max drain here) {
    //stop
    }
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    Quote Originally Posted by bracket View Post
    Code:
    if (getLevel(Skills.ATTACK) < max drain here) {
    //stop
    }
    so i typed the code up like this:
    Spoiler for confuse spell:
    case 26: // confuse
    player.setNextAnimation(new Animation(716));
    mage_hit_gfx = 104;
    player.setNextGraphics(new Graphics(102, 0, 80));
    base_mage_xp = 13;
    magic_sound = 152;
    Hit special = getMagicHit(player, getRandomMagicMaxHit(player, 70));
    delayMagicHit(2, special);
    World.sendProjectile(new NewProjectile(player, target, 103, !player.withinDistance(target, 1) ? 40 : 15, 20, 65));
    if (target instanceof Player) {
    Player p = (Player) target;
    if (p.getSkills().getLevel(Skills.ATTACK) < p.getSkills().getLevel(Skills.ATTACK)); {
    player.getPackets().sendGameMessage("Your spell has no effect because the targets Attack has already been reduced.");
    }
    p.getSkills().drainLevel(0, p.getSkills().getLevel(0) / 5);
    p.getPackets().sendGameMessage("Your Attack skills have been drained.");
    player.getPackets().sendGameMessage("Your spell weakened your enemy.");
    }
    return 5;

    its sending the message "Your spell has no effect because the targets Attack has already been reduced." but its still draining attack, i must be doing it wrong, dont know how else to do it.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    Bump
    Reply With Quote  
     

  6. #6  
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    Any1 help pls?
    Reply With Quote  
     

  7. #7  
    ¯\_(ツ)_/¯


    Join Date
    Jul 2014
    Posts
    1,803
    Thanks given
    928
    Thanks received
    550
    Rep Power
    299
    You are checking if the stat was already reduced and then sending the message, but still reducing the stats after the check.
    Add a return at the end of the if statement where you check if the stat is already drained, or use an 'else' after it.

    Code:
    case 26: // confuse
    player.setNextAnimation(new Animation(716));
    mage_hit_gfx = 104;
    player.setNextGraphics(new Graphics(102, 0, 80));
    base_mage_xp = 13;
    magic_sound = 152;
    Hit special = getMagicHit(player, getRandomMagicMaxHit(player, 70));
    delayMagicHit(2, special);
    World.sendProjectile(new NewProjectile(player, target, 103, !player.withinDistance(target, 1) ? 40 : 15, 20, 65));
    if (target instanceof Player) {
    Player p = (Player) target;
    if (p.getSkills().getLevel(Skills.ATTACK) < p.getSkills().getLevel(Skills.ATTACK)); {
    player.getPackets().sendGameMessage("Your spell has no effect because the targets Attack has already been reduced.");
    } else {
    p.getSkills().drainLevel(0, p.getSkills().getLevel(0) / 5);
    p.getPackets().sendGameMessage("Your Attack skills have been drained.");
    player.getPackets().sendGameMessage("Your spell weakened your enemy.");
    }
    }
    return 5;



    One other thing is that you're not reducing your opponent's attack by 5%, you are dividing it by 5. Which means you would be reducing it by 20%
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    So if i divide it by 1.25 it shuld be correct then?
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Nov 2012
    Posts
    599
    Thanks given
    14
    Thanks received
    54
    Rep Power
    26
    Thanks for help everyone i managed to get it perfected
    Reply With Quote  
     

  10. #10  
    Banned
    Join Date
    Nov 2013
    Age
    25
    Posts
    27
    Thanks given
    6
    Thanks received
    3
    Rep Power
    0
    /1.25
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. New magic spell Book
    By LastResortpkz in forum Show-off
    Replies: 34
    Last Post: 06-26-2009, 12:11 AM
  2. Magic Spells for Pali
    By Enjoi in forum Configuration
    Replies: 19
    Last Post: 05-05-2009, 08:58 PM
  3. custom magic spells - first sprites ever made!
    By zedex ranger in forum Graphics
    Replies: 16
    Last Post: 03-31-2009, 08:09 AM
  4. Magic Spells :d
    By DefNotVastico in forum Show-off
    Replies: 4
    Last Post: 01-13-2009, 10:06 PM
  5. Magic spells text changing
    By tru3 ki11a in forum Requests
    Replies: 2
    Last Post: 01-10-2009, 05:55 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •