![]() |
NPC checking for player
As you all know, the onPlayerTouchsMe() only works if the player runs into the NPC.
How would I script the NPC to check if the player is in the x, y of the object. In this case, block.png PHP Code:
|
You need continuously to check the players position in a loop to see if they are within the bounds of the block. If you are looking to do it clientside...
PHP Code:
|
Quote:
|
Quote:
|
Quote:
|
don't want to seem like i'm giving advice, because I am not, and I also don't know what the OP. wants to do with this, since it's so vague and there might be a better approach, but here's something i came up with on a serverside approach to at least give an array of players in that object's coordinates.
Quote:
PHP Code:
|
Quote:
|
Quote:
|
Quote:
Well if the player was at constant motion, the onPlayerTouchsMe() would not be a problem. But it's the players that are on idle that it won't work. |
you could always make a clientside system which triggers to serverside upon damage to reduce hp or handle deaths, youd just need to make sure that it works securely (such as preventing people who modify packets invoking negative damage aka increased health) and that theres a clientside health variable to give the illusion of real time damage
if you do this then it would be easy to have a single weapon system for checking all box intersects for every enemy, rather than scripting the box intersect checks in a timeout inside all of their scripts |
Quote:
|
Quote:
PHP Code:
PHP Code:
Note that the above makes it possible for cheating players to not be hit by the block, so if you care about that, you should do everything serverside. |
So I took what you said, but modified it a bit
PHP Code:
PHP Code:
I haven't had a chance to test this but I don't see why it wouldn't work SO my next question is... How would I check local NPCs (Baddies) to trigger their "Hurt" function with that block too? I want my "damage block" to not only effect players but NPCs also. |
Looks fine to me except you probably don't want to send 20 triggers per second.
Hurting NPCs should probably be done serverside: PHP Code:
|
Quote:
|
Quote:
|
Quote:
I tried this in the clientside PHP Code:
PHP Code:
|
Is this in a class or level npc?
Also, are you going to be using this in a situation where the blocks appearance and location needs to be: A.) The same for all players in the level Or B.) Can be different for all players in the level. Some good suggestions previously listed here, but there are potentially a lot of ways to cheat this on the clientside as well. |
Quote:
|
triggerserver() does not work inside level NPCs, you would need to use triggerAction() for this case
|
I still don't really know what you're doing so it's hard to give advice, but if your NPCs are created via putnpc2, they do have a name, and you can trigger them via triggerServer (but you have to get the name clientside; normally it isn't available). That might be the best approach.
|
Quote:
Quote:
|
Allow me to clarify exactly what I'm doing.
When the player presses 'a', the player creates an NPC that I'm using as a damage block. The NPC is functional through joining a class. Perhaps it'd be easier to explain if I did step by step what I'm doing, so I can get some better, more specific advice. 1. Player presses 'A' and creates the "damage block" NPC. This is the code from the Weapon PHP Code:
2. The NPC preforms it's function, then deletes This is where I'm Having issues. I need the block to destroy serverside. This is the script from the CLASS it joined PHP Code:
|
Consider this example:
PHP Code:
|
Weapon script:
changed your this.level.putNPC2(...) to player.level.putNPC2(...), this. would refer to the weapon while player. refers to the player) PHP Code:
Class script: removed your dontBlock() as it needs to be a blocking NPC I believe fixed your triggerAction() and other stuff PHP Code:
|
[QUOTE=BlueMelon;1724944]Consider this example:
Thanks for the tip. Here's what I got PHP Code:
PROBLEM: It sometimes works, and sometimes doesn't. It seems to only destroy half the time... Anything I can modify to make it more reliable? |
Take a look at what you posted, and what callimuc and I have posted.
You are checking the collision when the npc is created. Meaning it is comparing the coordinates once... this is not what you want. |
Quote:
|
What they said ^^
Plus, its also probably noteworthy to make sure you use setTimer (0.05 or however long...) in the onTimeout function to continue the loop -- you don't have it this way in your example. Also, not necessary, but if you wanted to start the loop as immediately as it was created just call onTimeout (); in the on created function. edit: sorry, missed it on my phone. callimuc's example is spot on -- disregard my post if you follow his examples -- or just take them as an explanation for what he did. :] |
I wanna thank everyone for all the advice! I have been really learning a lot!
So far I have it running correct with the tests I have put it through. But if I run in to any trouble I will be sure to add on to this thread with my questions. |
I have everything working the way I want, but I am trying to do a check in the CLASS script to check if the baddie is a certain type.
PHP Code:
|
Quote:
|
Quote:
|
Quote:
Have you tried debugging to see where the problem is? Add echoes to the for loop to see what NPCs it's finding, and another inside the if-statement to see if the right NPCs are being considered baddies. If you haven't already, add echoes in the trigger receiving function to see if it's received at all. Add echoes before the for-loop to see if it's even being reached. When you do this it will become clear where the problem is (e.g. is the problem finding NPCs? is it identifying the right NPCs? is it triggering the NPCs?). You can't have too many echoes when debugging. |
Quote:
PHP Code:
PHP Code:
|
Switching to Clientside
So after a lot of testing and what not, I have come to realize that my damage block system works, but not at the fast pace I am looking for.
Furthermore, I am going to switch to run my damage system all via CLIENTSIDE. How would I trigger a clientside function in a weapon of another player? PHP Code:
It's also something I'd like to learn for the future. Also, I'm not sure if my check is right to find players in front. If incorrect, please assist me there too. |
Quote:
I am pretty sure Graal also allows you to triggerAction straight onto another player, something like NPC Code:triggerAction(player.x + vecx(..), player.y + vecy(..), "hit", "etc"); Assuming that's deprecated (I think it might be, or might require you to set a server option to allow it), then the first is the way to go. In either scenario, once you get to the serverside with the player already planned, just triggerClient onto that player. Something like this: (in weapon NPC): NPC Code: As for your "damage block" system that you complained isn't "fast paced" enough -- if you want fast pace, you need clientside hit detection. Make the "hurt" attack a clientsided function. If you're using graal default, that's "hitplayer()" -- if you aren't using Graal default, code in your own custom knockback. You can do something like finding out the angle between your player and the block, and then hitting your player back away from them using cos/sin. Set a temporary flag to give them immunity to re-hit (like the 'blinks' in default graal), and have the heart-removal happen clientside (even a clientr. flag can be set on the clientside, it just won't truly save until it's set on the serverside), and then trigger the heart update to the serverside. The server gets the info late -- but the client gets it immediately, and that keeps it feeling crisp. For making the NPCs hit baddies, there are two main ways to do this: 1. Have the block (or baddy) repeatedly loop through npcs[] (or better, a smaller level.list of the relevant NPCs) and compare their x/y to the others' x/y to see if they are making contact. 2. Have the block (or baddy) doing testnpc() onto itself. If you setshape(1,1,1); right before you testnpc (and then re-setshape immediately after), the testnpc will miss the npc itself and allow it to detect another NPC under it. Then you can access that NPC by doing like npcs[testnpc()]. I'd go with #1 in this case. Don't loop over the entire npcs[], though. Make it so baddies save a level variable of their presence. So, for example, at the top of the baddies class: (clientside) NPC Code: Now, when the block wants to test if a baddy is inside of its coordinates, rather than doing: NPC Code: you would instead do: NPC Code: That is easier to read, easier to access and manipulate, and more efficient because you are no longer iterating pointlessly over a bunch of unrelated NPCs that have nothing to do with baddies. |
I took what was read above into consideration. Thank you. But I am running all pvp actions via Clientside.
With that said, I am having issues and can't find out why this won't work. This is the script for the weapon "Combat" PHP Code:
PHP Code:
It's not triggering the function. I know the x1,x2 and y1,y2 and a little outa wack. I'm just testing with the player.dir == 3 |
Quote:
Think about this.x and this.y also: this. Refers to the weapon as the object. Probably not something you are going to want to do in this instance.. And player.x and player.x refers specifically the top left of the player. The way this is set up it almost seems as if you want to hurt yourself, which might be fine for testing, but you can put the same onHurt function in a class and join it to an npc that looks like a player character as well to test animations. While you're still early in the script i'd read up on vecx and vecy because it will come in handy for determining a position in front of a player. Here is a thread explaining it: http://forums.graalonline.com/forums...47#post1649547 Also, here is an old example using a mining system that might help you set up better testing procedures (the triggers and receiving of them can be applied to a combat system) http://forums.graalonline.com/forums...ad.php?t=68273 |
| All times are GMT +2. The time now is 05:20 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.