Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Onwater and Keypressed problems (https://forums.graalonline.com/forums/showthread.php?t=87636)

sssssssssss 08-27-2009 11:29 PM

Onwater and Keypressed problems
 
PHP Code:

function onKeyPressed() {
  if (
onwater(player.x,player.y)){
    if (
keydown(5)) {
      
setlevel2("testtourny.nw"22);
    }
  }


Ok, what am i missing? Pretty sure its a gs2 thing.

DustyPorViva 08-27-2009 11:32 PM

setlevel(2) is serverside.

Also, you may want to detect at player.x+1.5 and playery+2, which is the 'center' of the player.

Chompy 08-27-2009 11:33 PM

I would of done the key check before the water check (:
If this is for an event or something, it would of been easier to alter the player's x/y.

DustyPorViva 08-27-2009 11:37 PM

Quote:

Originally Posted by Chompy (Post 1519011)
I would of done the key check before the water check (:

Indeed. No need to check for water if the player isn't even pressing 'S'. Or could even have both in one if statement.

sssssssssss 08-28-2009 12:55 AM

PHP Code:

function onKeyPressed() {
  if (
keydown(5)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
setlevel2("testtourny.nw"22);
    }
  }


This is the entire script, so it is serverside. Also, didn't change anything to change the order of onwater or keydown. And keydown 5 should be A.

DustyPorViva 08-28-2009 01:00 AM

keypressed/keydown are clientside.

And keydown(5) is 'S' :) 6 is 'A'.

sssssssssss 08-28-2009 01:13 AM

keydown( key ) the specified key is pressed (0..10: up,left,down,right,S,A,D,M,tab,Q,P)

doesnt work that way anymore?
and forgot about that clientside, :)

DustyPorViva 08-28-2009 01:15 AM

5 has always been sword and 6 has always been grab :) If it has ever stated otherwise it was wrong. Easier way to find out what is the right button is to open your control options and the buttons are listed from top to bottom in their numerical order, starting at 0. I actually didn't know about this until someone else posted, but it has come in handy a lot for those keys that I don't use often(like Q/P and such).

sssssssssss 08-28-2009 01:27 AM

PHP Code:

function warpPlayerw(pobjdest)
  {
  
pobj.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {testtourny.nw22};
      
triggeraction(this.0.5this.0.5"warpPlayerw"temp.accttemp.dest);

    }
  }


still getting nothing.

WhiteDragon 08-28-2009 01:30 AM

Quote:

Originally Posted by sssssssssss (Post 1519040)
PHP Code:

function warpPlayerw(pobjdest)
  {
  
pobj.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {testtourny.nw22};
      
triggeraction(this.0.5this.0.5"warpPlayerw"temp.accttemp.dest);

    }
  }


still getting nothing.

You sent up the account name, not the player object. Do a findplayer(acct) on the account serverside once you have it.

LoneAngelIbesu 08-28-2009 01:42 AM

This is pretty unrelated, but I have a question about onKeyPressed(). I've seen plenty of people using that action in conjunction with keydown(). Isn't this redundant, since onKeyPressed() has parameters that provide which key is pressed? Why not use a simple check with the parameters, rather than a function?

WhiteDragon 08-28-2009 01:46 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1519044)
This is pretty unrelated, but I have a question about onKeyPressed(). I've seen plenty of people using that action in conjunction with keydown(). Isn't this redundant, since onKeyPressed() has parameters that provide which key is pressed? Why not use a simple check with the parameters, rather than a function?

Yes it is somewhat redundant, but onKeyPressed() gives you the keycode, while keydown() gives you an "action number" which is mapped to a keycode via the settings on the player's client.

It may be possible to access the settings data via. some obscure way, but I'm not sure about that.

sssssssssss 08-28-2009 01:47 AM

PHP Code:

function warpPlayerw(pobjdest){
  
temp.warp findplayerbycommunityname(pobj);
  
warp.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {testtourny.nw22};
      
triggeraction(this.0.5this.0.5"warpPlayerw"temp.accttemp.dest);

    }
  }


still nada. I think I did it right and understood you, if not, please explain in detail. :/

WhiteDragon 08-28-2009 01:49 AM

Quote:

Originally Posted by sssssssssss (Post 1519047)
PHP Code:

function warpPlayerw(pobjdest){
  
temp.warp findplayerbycommunityname(pobj);
  
warp.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {testtourny.nw22};
      
triggeraction(this.0.5this.0.5"warpPlayerw"temp.accttemp.dest);

    }
  }


still nada. I think I did it right and understood you, if not, please explain in detail. :/

Yeah, you got that correct.
I just noticed another error was that you didn't put testtourny.nw in quotes, which you need to do for all strings, otherwise it'll try to read it as a variable.

DustyPorViva 08-28-2009 01:49 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1519044)
This is pretty unrelated, but I have a question about onKeyPressed(). I've seen plenty of people using that action in conjunction with keydown(). Isn't this redundant, since onKeyPressed() has parameters that provide which key is pressed? Why not use a simple check with the parameters, rather than a function?

keydown() checks for the player's configuration, while keypressed uses keyboard layout. For example, keydown(5) checks for the player's key configured to 'sword', which may not always be set to 'S'.

sssssssssss 08-28-2009 01:53 AM

Put quotes, still nothing.

LoneAngelIbesu 08-28-2009 01:58 AM

Quote:

Originally Posted by DustyPorViva (Post 1519049)
keydown() checks for the player's configuration, while keypressed uses keyboard layout. For example, keydown(5) checks for the player's key configured to 'sword', which may not always be set to 'S'.

Oh, I see. Thanks for the explanation. :)

DustyPorViva 08-28-2009 02:02 AM

Because triggeractions do not simply call functions, but calls a function specified for triggeractions:
function onactionWhatTriggerWasCalled() {}

would be called with:

triggeractionaction(x,y,"WhatTriggerWasCalled",x,y ,z);

I think.

sssssssssss 08-28-2009 02:04 AM

your right, cant believe i forgot that, its onActionActionHey. now its:

PHP Code:

function onActionWarpPlayerw(pobjdest){
  
temp.warp findplayerbycommunityname(pobj);
  
warp.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onKeyPressed(6) {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {"testtourny.nw"22};
      
triggeraction(this.0.5this.0.5"WarpPlayerw"temp.accttemp.dest);
    }
  }


but still, not working.

DustyPorViva 08-28-2009 02:08 AM

You also need to setshape(1,32,32) // or whatever the size you want on the serverside(onCreated() is where it should be called) for the server to be able to recognize the NPC.

Ideally, what you can also do is set up a system weapon to have triggers for warping the player, and simply do something like this on the clientside:

triggerServer("gui","-System","WarpPlayer",player.account,dest); // you don't have to use temp.var after you declared the variable a temp.

sssssssssss 08-28-2009 02:09 AM

PHP Code:

function onCreated() {
  
this.setshape(13232);
}
function 
onActionWarpPlayerw(pobjdest){
  
temp.warp findplayerbycommunityname(pobj);
  
warp.setlevel2(dest[0], dest[1], dest[2]);
}

//#CLIENTSIDE
function onCreated() {
  
this.setshape(13232);
}
function 
onKeyPressed(6) {
  if (
keydown(6)) {
    if (
onwater(player.x+1.5,player.y+2)){
      
temp.acct player.account;
      
temp.dest = {"testtourny.nw"22};
      
triggeraction(this.0.5this.0.5"WarpPlayerw"temp.accttemp.dest);
    }
  }


nada y nada still.

DustyPorViva 08-28-2009 02:12 AM

Debug that motha'!
Start putting player.chat = "test" or something in various places to find out where the script is losing its purpose.

Also, it should just be:

function onKeyPressed() {
if (keydown(6)) {

}
}

Otherwise you're basically defining(or trying to) 6 as a variable for the first parameter of the keypressed function, which may be screwing things up.

Also, temp.warp is not a very descriptive variable name as it's actually referring to a player, so should be something more reflective... at least something like temp.p or such.

fowlplay4 08-28-2009 02:29 AM

On a side note, there's probably a better way to accomplish what you're trying to do, which appears to be some sort of warp the player somewhere if they are in water, the script could easily be replaced by using level warps.

Also your script is incredibly insecure. You don't need to send any extra parameters at all.

PHP Code:

function onActionWarpPlayerw() {
  
// Don't really need this array either
  
temp.dest = {"testtourny.nw"22};
  
player.setlevel2(dest[0], dest[1], dest[2]);


Then for your triggeraction all you would need is:

triggeraction(this.x + 0.5, this.y + 0.5, "WarpPlayerw", "");

sssssssssss 08-28-2009 02:38 AM

My hero. Thank u everyone. I feel dumb, always forget stupid things like putting a 6 in that function

Gambet 08-28-2009 03:32 AM

I thought I explained triggerAction() to you in multiple posts in the last thread that you asked about it? You should really look back on those posts in the future.

Also, some of you are really bad at helping people with scripting problems, haha. I can't believe it took so long for someone to mention the onActionActionname() bit that he was missing when reading the function called by the triggerAction(). :p

DustyPorViva 08-28-2009 03:35 AM

Quote:

Originally Posted by Gambet (Post 1519083)
I thought I explained triggerAction() to you in multiple posts in the last thread that you asked about it? You should really look back on those posts in the future.

Also, some of you are really bad at helping people with scripting problems, haha. I can't believe it took so long for someone to mention the onActionActionname() bit that he was missing when reading the function called by the triggerAction(). :p

I noticed it when he first posted it, lol. I didn't post anything at first though because I wasn't sure of the syntax because it's been so long since I've used triggeraction. I was hoping someone else would notice it :P

Mark Sir Link 08-28-2009 03:50 AM

Quote:

Originally Posted by fowlplay4 (Post 1519066)
Also your script is incredibly insecure. You don't need to send any extra parameters at all.

since it's being triggered on the clientside, yes. I believe he was still working serverside only when I wrote the function he was trying to use (not in this script I think).

sssssssssss 08-28-2009 05:13 AM

Quote:

Originally Posted by Gambet (Post 1519083)
I thought I explained triggerAction() to you in multiple posts in the last thread that you asked about it? You should really look back on those posts in the future.

have been looking back at those posts, lol, trust me. Just went in and looked through again. My problem wasent triggers, that was just a minor accident i did in the code. My problem was working with level triggers and setlevel2. I'm not an advanced scripter, trying to learn as I go. Again thought, thank you now, past, and future to everyone. Would have took me forever to get things like cant use triggerserverside in a level npc. :)


All times are GMT +2. The time now is 09:14 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.