Need help with a spell script
So I've been trying to incorporate this mana system into my D-Mod. To do this, I've edited the fireball script. The mana system itself works perfectly like this, but I've run into a problem. Whenever I change screens, random sprites begin randomly disappearing. It makes no sense whatsoever. I've managed to track it down to the sp_kill(&t1, 1); command. If I remove it from the loop, it'll stop removing the sprites, but I need that command to make the mana system work. And I can't seem to find any other command that would serve the same purpose, except for sp_active(&t1, 0);, but in that case it'll start removing the sprites, as well. I've tried everything and I'm really stumped. Anyone know what could be causing this?
Here's the whole fireball script:
Here's the whole fireball script:
void use( void ) { &mydir = sp_dir(1, -1); if (&mana > 2) { //disallow diagonal fireballs for now if (sp_dir(1, -1) == 1) sp_dir(1, 4); if (sp_dir(1, -1) == 3) sp_dir(1, 6); if (sp_dir(1, -1) == 7) sp_dir(1, 4); if (sp_dir(1, -1) == 9) sp_dir(1, 6); &basehit = sp_dir(1, -1); &basehit += 320; sp_seq(1, &basehit); sp_frame(1, 1); //reset seq to 1st frame sp_kill_wait(1); //make sure dink will punch right away sp_nocontrol(1, 1); //dink can't move until anim is done! &magic_level = 0; draw_status(); &mholdx = sp_x(1, -1); &mholdy = sp_y(1, -1); //freeze(1); wait(100); if (&mydir == 1) { &mholdx -= 30; &junk = create_sprite(&mholdx, &mholdy, 11, 504, 1); sp_seq(&junk, 504); sp_mx(&junk, -6); sp_my(&junk, +2); } if (&mydir == 4) { &mholdx -= 30; &junk = create_sprite(&mholdx, &mholdy, 11, 504, 1); sp_seq(&junk, 504); sp_dir(&junk, 4); } if (&mydir == 6) { // &mholdy -= 10; &mholdx += 30; &junk = create_sprite(&mholdx, &mholdy, 11, 506, 1); sp_seq(&junk, 506); sp_dir(&junk, 6); } if (&mydir == 3) { &mholdx += 30; &junk = create_sprite(&mholdx, &mholdy, 11, 506, 1); sp_seq(&junk, 506); sp_mx(&junk, +6); sp_my(&junk, +2); } if (&mydir == 2) { &junk = create_sprite(&mholdx, &mholdy, 11, 502, 1); sp_seq(&junk, 502); sp_dir(&junk, 2); } if (&mydir == 7) { &mholdx -= 30; &junk = create_sprite(&mholdx, &mholdy, 11, 504, 1); sp_seq(&junk, 504); sp_mx(&junk, -6); sp_my(&junk, -2); } if (&mydir == 8) { &junk = create_sprite(&mholdx, &mholdy, 11, 508, 1); sp_seq(&junk, 508); sp_dir(&junk, 8); } if (&mydir == 9) { &mholdx += 30; &junk = create_sprite(&mholdx, &mholdy, 11, 506, 1); sp_seq(&junk, 506); sp_mx(&junk, +6); sp_my(&junk, -2); } //create fake shadow effect playsound(17, 8000,0,&junk,0); sp_timing(&junk, 0); sp_speed(&junk, 6); sp_strength(&junk, 20); sp_range(&junk, 10); //this makes it easier to hit stuff sp_flying(&junk, 1); sp_script(&junk, "dam-fire"); //when the fireball hits something, it will look to this script, this way //we can burn trees when appropriate &mshadow = create_sprite(&mholdx, &mholdy, 15, 432, 3); sp_brain_parm(&mshadow, &junk); sp_que(&mshadow, -500); //will be drawn under everything //set fireball to not be able to damage Dink or the shadow sp_brain_parm(&junk, 1); sp_brain_parm2(&junk, &mshadow); &mana -= 3; goto loop; } unfreeze(1); goto loop; } void disarm(void) { &magic_cost = 0; sp_kill(&t1, 1); kill_this_task(); } void arm(void) { Debug("Preloading fireball"); int &basehit; int &mholdx; int &mholdy; int &junk; int &mshadow; int &mydir; &magic_cost = 100; preload_seq(322); preload_seq(324); preload_seq(326); preload_seq(328); preload_seq(502); preload_seq(504); preload_seq(506); preload_seq(508); //tree burn preload_seq(20); //explosion preload_seq(70); int &t1; loop: sp_kill(&t1, 1); &t1 = say_xy("&mana / 100", -50,455); sp_kill(&t1, 0); wait(200); goto loop; } void pickup(void) { Debug("Player now owns this item."); kill_this_task(); } void drop(void) { Debug("Item dropped."); kill_this_task(); }
It kills random sprites because when you change screens, the text sprite &t1 stops existing. "&t1" (or &crap, or &text, or any variable name) is just a stand-in for the sprite's sprite number, so when you change screens, it kills some sprite that just happens to have the same sprite number that &t1 had.
To fix, you could do something like this:
If &crap doesn't equal &player_map, that means they changed screens during the wait(200), &t1 doesn't exist anymore, and so we shouldn't try to kill it.
Alternatively, this might work:
To fix, you could do something like this:
loop: if (&crap == &player_map) sp_kill(&t1, 1); &t1 = say_xy("&mana / 100", -50,455); sp_kill(&t1, 0); int &crap = &player_map wait(200); goto loop;
If &crap doesn't equal &player_map, that means they changed screens during the wait(200), &t1 doesn't exist anymore, and so we shouldn't try to kill it.
Alternatively, this might work:
loop: &t1 = say_xy("&mana / 100", -50,455); sp_kill(&t1, 200); wait(200); goto loop;