Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Destroying an NPC via mouseclick

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
Fenrir-Lunaris
WUT




Joined: 03 Feb 2003
Posts: 1747

PostPosted: Mon Jul 14, 2008 11:36 am    Post subject: Destroying an NPC via mouseclick Reply with quote

I'm developing a minigame where you can use the {MOUSE} to fire at enemies and destroy them with a simple click, similar to that minigame in Mario paint where you swatted flies. Since this is my first experience with manipulating the mouse, here's a short run of what I've got, and where things break down.


A brief technical demonstration of what's going on. Enemies rush at you with deadly weapons, who'll kill you in one hit and send you back to the start of the level/nearest safe point. You use the mouse to shoot and kill them before they can touch you. Simple and easy, right?

Code:
script, mouse script, begin
  # Must be called before any other mouse command
  init mouse
  variable (avoid warning) # Kludge to suppress the "infinite loop" compiler warning
  avoid warning := true
  # Infinite loop, yes, there's a reason
  while (avoid warning) do, begin
    # You can put an appropriate condition here, or "true" (or "avoid warning" to avoid the warning)
    if (tag:Mouse active) then, begin
      # In the next line, change the "0" to the ID of the mouse NPC
      put NPC (0, mouse pixel x + camera pixel x, mouse pixel y + camera pixel y)
      if (mouse button(left button)) then, begin
        variable (NPC, Num NPC, i)
        num NPC := NPC at pixel (mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, 1)
        for (i,0,Num NPC -- 1,1) do, begin
          NPC := npc at pixel(mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, i)
          if(get NPC ID(NPC) == 8) then, begin
            FOE8
          end
     if(get NPC ID(NPC) == 9) then, begin
            FOE9
          end
     if(get NPC ID(NPC) == 10) then, begin
            FOE10
          end
        end
        # Check what's been clicked
      end
    end
    # Let game.exe breathe
    wait
  end
end


NPC 0 has a little crosshairs to lock onto any foe on screen, and if the script is working, it'll recognize which NPC is being targeted, then run a smaller script to determine what to do with it...

Code:
script,FOE8,begin
 suspend NPCs  #I don't really want anything moving around for a second
 tweak palette (40,-10,-10)
 update palette
 play sound (sfx:Slash8Bit,false,true)
 wait (1)
 reset palette
 update palette #All this is to basically make the screen flash
 Alter NPC (8,NPCstat:picture,14)
 wait (1)#the NPC VERY briefly changes its sprite to explode
 set tag (tag:FOE8,on)#And this tag kills the NPC
 resume NPCs
end


The script is doing one of two things, which I'm not positive I understand what's going on. Either the NPC crosshairs is not lining up at all with the desired NPCs to trigger the proper script.... ...OR, there's an error in each NPC script that somehow is preventing them from running. I'd much rather not even bother with the ACCURACY of whether the mouse's crosshairs are exactly lined up with the NPC "enemy", so long as it's on the same tile It also has to be specific as to what NPC is being targeted, since there are "friendlies" also on each map who you don't want exploding for no apparent reason.
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Tue Jul 15, 2008 1:23 am    Post subject: Reply with quote

You script is nearly correct, only I spot 2 problems:

Code:
num NPC := NPC at pixel (mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, 1)
should be
Code:
num NPC := NPC at pixel (mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, get count)

Where on earth did you get the 1?

And, I'm assuming that you want to target with the center of the crosshair NPC. So you'll want to subtract 10 pixels from the x,y location of the crosshair (or equivalently, add 10 to the x,y arguments of NPCatpixel)

Also, of course, that 'avoid warning' hack is pointless. So your script would look like

Code:
script, mouse script, begin
  # Must be called before any other mouse command
  init mouse
  while (true) do, begin
    # You can put an appropriate condition here, or "true" (or "avoid warning" to avoid the warning)
    if (tag:Mouse active) then, begin
      # In the next line, change the "0" to the ID of the mouse NPC
      put NPC (0, mouse pixel x + camera pixel x -- 10, mouse pixel y + camera pixel y -- 10)
      if (mouse button(left button)) then, begin
        variable (NPC, Num NPC, i)
        num NPC := NPC at pixel (mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, get count)
        for (i,0,Num NPC -- 1,1) do, begin
          NPC := npc at pixel(mouse pixel x + camera pixel x, mouse pixel y + camera pixel y, i)
          if(get NPC ID(NPC) == 8) then, begin
            FOE8
          end
          if(get NPC ID(NPC) == 9) then, begin
            FOE9
          end
          if(get NPC ID(NPC) == 10) then, begin
            FOE10
          end
        end
        # Check what's been clicked
      end
    end
    # Let game.exe breathe
    wait
  end
end

_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group