Author Topic: Modified Skill Delays, with multiple skills  (Read 3159 times)

Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Modified Skill Delays, with multiple skills
« on: September 13, 2006, 09:51:25 pm »
Hi all,

By request of Capo, I've been editing my skill delay code to make it work with several delays of varying names. This allows you to limit spamming skills of different types or whatever. It's all up to the coder. The problem is that my code doesn't work. It's really bugging me now, so I'm gonna post it. Be gentle.

LPC code:

static void heart_beat();
static void create();
mapping GetSkillDelay();
int SetSkillDelay(string delay, int delaytime);

mapping skill_delays;

static void create() {
      skill_delays = ([ ]);
                skill_delays["default"] = 0;
}


mapping GetSkillDelay(){
   return skill_delays;
}

int SetSkillDelay(string delay, int delaytime){
   if(!delay || !delaytime){
      return 0;
   }
   if(delay == "") return 0;
   if(delaytime == 0) return 0;
/* I did all these checks to make sure I was getting SOMETHING. */
   skill_delays[delay] = delaytime;
   return 1;
}

static void heart_beat(){
   string key;
   int value;
    foreach(key,value in GetSkillDelay()){
       if(value > 0) value--;
       SetSkillDelay(key, value);
   }   
}


And here is the code that sends arguments to the SetSkillDelay() function...

LPC code:

this_player()->SetSkillDelay("default", 1);


As you can see, I'm sending a string and an integer to the function.

The error it returns is:
code:


*Illegal type of index
Object: /secure/save/creators/t/tigwyk (/lib/skilldelay.c) at line 24

'<function>' at /secure/save/creators/t/tigwyk (<function>) at /:0
'cmdAll' at /secure/save/creators/t/tigwyk (/lib/command.c) at line 93
'cmd' at /realms/tigwyk/cmds/blast at line 30
'SetSkillDelay' at /secure/save/creators/t/tigwyk (/lib/skilldelay.c) at line 24
Trace written to /log/runtime

Offline Aransus

  • Acquaintance
  • *
  • Posts: 2
    • View Profile
Modified Skill Delays, with multiple skills
« Reply #1 on: September 14, 2006, 08:13:40 am »

Hey Tig,



The problem you're having is that create() is only getting called when a new player object is created. So on an existing player, create() isn't running and the skill_delays mapping isn't getting initialized. Try creating a new character, that code will work fine and you'll get no errors.



If you want the skilldelay.c create() function to be called every time a player logs in, you could always add skilldelay::create() to Setup() inside /lib/player.c.



While that will eliminate the error you posted, I'm not sure if it'll end up doing exactly what you want (or doing it in the best way). In any case, I hope this helps a bit :).



Edit: FWIW, you might consider moving the call of skilldelay::heart_beat() from /lib/living.c to /lib/combat.c. If you add to living.c, you have to define a new heart_beat() function solely so that it can call 2 inherited heart_beat()'s. Putting the call inside combat.c seems a bit neater that way. Eh, just a thought :P.



-- Aransus


Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
Modified Skill Delays, with multiple skills
« Reply #2 on: September 14, 2006, 08:40:42 am »

Hi Aransus,



Thanks so much for your input. I'll play with my code a bit and see if I can clean it up. I'm glad SOMEONE was able to make sense of the problem. Hooray!