Quote:
Originally Posted by i8bit
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:
//#CLIENTSIDE function onKeyPressed(code, key){ if (key == "s"){ if (player.x in |this.x-2, this.x + 1| && player.y in |this.y-1, this.y + 3|) { //Trigger Clientside function in other player's "System/Health" weapon } } }
Can anyone fill in that line for me please? 
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.
|
If you want to find a player *in front* you would use the vecx() and vecy() functions. vecx(player.dir) returns -1 for left, +1 for right, and 0 for up/down. Thus, doing player.x + vecx(player.dir) will aim 1 in front of the player either left or right, while doing player.y + vecy(player.dir) will aim 1 in front of player either up or down.
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:
function onActionServerside(act, acc) {
if (act == "hit") {
temp.pl = findplayer(acc);
temp.dist = ((player.x - pl.x) ^ 2 + (player.y - pl.y) ^ 2) ^ 0.5;
if (dist < 4) { // This check is just for general security, to make sure a lagger isn't just conquering people, or a hacker isn't hitting people from 500 miles away
pl.triggerClient("weapon", this.name, "hit", player.account);
}
}
}
//#CLIENTSIDE
function onKeyPressed(keycode, key) {
if (key == "s") { (you should consider using "if (keydown(5)) {" or whatever instead, in case the player wishes to change their 'default' sword key
// Some algorithmic stuff here to detect the hitbox that I'm not going to include, assume they are "pl"
if (other player in hitbox -- this is the stuff we've spoken about elsewhere) {
triggerServer("weapon", this.name, "hit", pl.account);
}
}
}
function onActionServerside(temp.act, temp.info) {
if (act == "hit") {
// Hit the player here
// "info" in this case would be the account of the player who landed the hit.
}
}
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:
function onCreated() {
level.baddies.add(this);
}
Now, when the block wants to test if a baddy is inside of its coordinates, rather than doing:
NPC Code:
for (temp.npc: npcs) {
if (npc.isBaddie) {
// compare npc.x and npc.y to this.x and this.y
}
}
you would instead do:
NPC Code:
for (temp.baddie: level.baddies) {
// compare baddie.x and baddie.y to this.x and this.y
}
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.