Mirage Source
Question about attacking - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17)
+---- Thread: Question about attacking (/showthread.php?tid=194)



Question about attacking - halla - 18-07-2006

Where is the code where it finds out if the player is beside the NPC so he is able to attack. Im adding something where you click a NPC and it brings up a form, but where I had it I could click anywhere it would bring up the form.

So wheres this code so I can place it in there and it will only bring up the Form when I click the NPC and im right beside him.


- Rian - 18-07-2006

Search the server side code for this:

Your target is now

and that should find you the right stuff. You'll then need to send a packet to the client to bring the form up


- Gilgamesch - 18-07-2006

its in playersearch i think..the packet s:

"search" (server side) thats where a player or npc is been targetted, so you need to add:

if getplayerx(index) = MapNpc(Player bla bla target code thingy).x - 1 or
getplayerx(index) = MapNpc(Player bla bla target code thingy).x +1 and
getplayery(index) = MapNpc(Player bla bla target code thingy)y. -1 or
getplayery(index) = MapNpc(Player bla bla target code thingy)y. +1 then

your code


thats just out of my midn..i am really tiered right now, if you cant find it or need some help just post it here


bye


- halla - 19-07-2006

Thanks guys I will look into it. I was looking client side think that was my problem.

I found it... I was just ysing....


Code:
frmBattle.Visible = True

but sine that forms on the client not server it wont compile. I added it to the packet so it would send that to client to do when it targets...

So is there another way to do this or what am I doing wrong.


- Matt - 20-07-2006

I'm not sure what you're trying to do. I assume, you are sending a packet to the server to start a battle, and when the server recieves that packet, trying to open the form client side, by calling the function server side?

If so, just send a packet back to the client, and send a variable with a value, and do an if check or something, that if the parse = 1 then frmbattle.visible = true

If that's what you're trying to do, I don't really understand your posts all that much, sorry if I'm wrong. ^_^


- halla - 20-07-2006

well I added a code where you right click a npc and you attack it. I want it where when you click the npc that you open up a form.

I had it working but it would open the form when I click anywhere thats why I wanted to know about just when I click npc


- SheepDog - 20-07-2006

Do it all client side.. but only open the form if there is an NPC on that tile.


- halla - 21-07-2006

Yeah I was trying to find where it targets the npc and I was lead to the server side. Which I did find it but when I put that in it said the form wasnt there.


- halla - 21-07-2006

What did I do wrong here I think it shold work but when I click NPC it targets thembut doesnt open the Form... heres code.

Server:
Code:
' Check for an npc
        For i = 1 To MAX_MAP_NPCS
            If MapNpc(GetPlayerMap(Index), i).Num > 0 Then
                If MapNpc(GetPlayerMap(Index), i).x = x And MapNpc(GetPlayerMap(Index), i).y = y Then
                    ' Change target
                    Player(Index).Target = i
                    Player(Index).TargetType = TARGET_TYPE_NPC
                    BattleOpen = 1
                    Call PlayerMsg(Index, "Your target is now a " & Trim(Npc(MapNpc(GetPlayerMap(Index), i).Num).Name) & ".", Yellow)
                Else
                BattleOpen = 0
                    Exit Sub
                
                End If
            End If
        Next i
        
        Exit Sub
    End If

CLIENT SIDE:
Code:
' Open Battle Form
        If BattleOpen = 1 Then
        frmBattle.Visible = True
        Else
        frmBattle.Visible = False
        End If

Also I have on each...

Code:
Dim BattleOpen As Long



- Dark Echo - 21-07-2006

I think grim wrote a really good tutorial for clicking, and i think theres also a good tutorial on npc name on hover.. Have you tried looking at those?


- Matt - 21-07-2006

Server -

Code:
' Check for an npc
        For i = 1 To MAX_MAP_NPCS
        dim packet as string ' Might already be defined, don't know, if so, delete this
            If MapNpc(GetPlayerMap(Index), i).Num > 0 Then
                If MapNpc(GetPlayerMap(Index), i).x = x And MapNpc(GetPlayerMap(Index), i).y = y Then
                    ' Change target
                    Player(Index).Target = i
                    Player(Index).TargetType = TARGET_TYPE_NPC
                    BattleOpen = 1
                    Call PlayerMsg(Index, "Your target is now a " & Trim(Npc(MapNpc(GetPlayerMap(Index), i).Num).Name) & ".", Yellow)
                Else
                BattleOpen = 0
                packet = "Battle" & Sep_Char & BattleOpen & Sep_Char & End_Char
                Call SendData(Index, packet)
                    Exit Sub
              
                End If
            End If
        Next i
      
        Exit Sub
    End If

Client -

Code:
If LCase(Parse(0)) = "battle" Then
        ' Open Battle Form
        BattleOpen = Val(Parse(1))
        If BattleOpen = 1 Then
        frmBattle.Visible = True
        Else
        frmBattle.Visible = False
        End If

That should work, if not, it's not something hard to fix. Good luck.


- halla - 21-07-2006

Thanks I will work at it

All good so far except...

Code:
If LCase(Parse(0)) = "battle" Then

When trying to compile Client highlights Parse there and says Argument not optional.

Also on client I changed SendData to SendDataTo

I will keep looking into it but if you know whats wrong before I find it please post. Thanks for all the help so far.


- Matt - 21-07-2006

Put that in handle data, I believe, where all the other packets are. It should work then.


- halla - 21-07-2006

oh my bad I put it in the gameloop thought it would have to go there guess im wrong

EDIT:

well I still had to fix some more stuff but I got it working. Thanks for all the help. If anyone wants the working code for some reason let me know and I will post.


- Matt - 22-07-2006

Well, a packet was added, therefore, handle data would be the choice place.

Congrats on getting it to work. ^_^