Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Vecx, Vecy and move() (https://forums.graalonline.com/forums/showthread.php?t=134264581)

pig132 09-18-2011 06:43 AM

Vecx, Vecy and move()
 
Alright so I'm working on a little toy and I have searched in and out of these forums for a good explanation of vecx and vecy and really haven't found something that relates to my problem. What I am trying to do is when my weapon is fired (it then joins the class) and after the npc is dropped it will move a certain distance in the direction of the player. This is what I currently have in the moving part:

PHP Code:

function onCreated()
{
  
this.image "bomb.png";
  
setshape(13232);

  if (
player.dir 0)
  {
    
move(-20014);
  }


Also, if I add new if (directions) no matter what the move() parameters are, it still moves to the left (dir 0).

If anyone has some tips on using vecx and vecy for this that would be appreciated. :)

Gunderak 09-18-2011 07:44 AM

try setting its dir on a timeout maybe.
as for vecx and vec i am clueless, never used it before.

Tigairius 09-18-2011 08:19 AM

I wrote a very extensive article on vecx and vecy.
http://forums.graalonline.com/forums...hp?t=134263215

Anyways, what you will need to do is pass the player's direction in as a parameter/string because I don't think the player is generally in scope for dropped objects.

After you do that, you can add:
PHP Code:

move(20*vecx(playerdirstring) - this.x20*vecy(playerdirstring) - this.y14); 


oralgnome 09-18-2011 06:09 PM

isn't it player.dir == not = ?

anyway i'm interested in this as well because i've no idea how you can pass a dir to a class like that

cbk1994 09-18-2011 06:36 PM

Quote:

Originally Posted by oralgnome (Post 1668511)
isn't it player.dir == not = ?

anyway i'm interested in this as well because i've no idea how you can pass a dir to a class like that

Yes, it should have been ==.

What do you mean by passing it to a class?

oralgnome 09-18-2011 06:39 PM

Quote:

Originally Posted by cbk1994 (Post 1668513)
Yes, it should have been ==.

What do you mean by passing it to a class?

well, player.dir is generally clientside* so you can't really use it in a class/serverside in general until you pass it serverside

relatively, you can pass a var in a weapon from the clientside to the serverside like this:

PHP Code:

function onActionServerside(cmddir){
if (
cmd == "bomb"){
        
temp.npc putnpc2(player.xplayer.y"bomb");
        
temp.npc.join("personal_pig132_bomb");
        
sendtonc(temp.dir);
  }
}

//#CLIENTSIDE

function onWeaponFired(){
    
temp.dir player.dir;
    
triggerserver("gui"this.name"bomb"temp.dir);


(With trigger.server), but how would you pass that temp.dir var to the class then?

in java you'd just redefine the var with the classname like

PHP Code:

// not gs2
     
classname.firstnum secondclass.num

and then you'd just initiate the num var in secondclass for use

how would you accomplish this in gs2?

cbk1994 09-18-2011 06:46 PM

Quote:

Originally Posted by oralgnome (Post 1668516)
well, player.dir is generally clientside* so you can't really use it in a class/serverside in general until you pass it serverside

No it's not, player.dir can be accessed serverside.

Quote:

relatively, you can pass a var in a weapon from the clientside to the serverside like this:

(With trigger.server), but how would you pass that temp.dir var to the class then?
I think you misunderstand how classes work. All a class does is extend a weapon or NPC. It doesn't stand on its own.

Class functions_bank
PHP Code:

function deposit(temp.amountToDeposit) {
  
// obviously this is just an example, don't actually use this
  
player.rupees -= temp.amountToDeposit;
  
player.bank += temp.amountToDeposit;


Weapon ATM
PHP Code:

function onCreated() {
  
this.join("functions_bank");
}

function 
onActionServerSide(temp.cmdtemp.amount) {
  if (
temp.cmd == "deposit") {
    
this.deposit(temp.amount);
  }
}

//#CLIENTSIDE
function ChatBar.onAction() {
  if (
ChatBar.text.starts("/deposit")) {
    
triggerServer("gui"this.name"deposit"player.chat.substring(9).trim());
  }


The example above shows a very simple use of classes.

When you use join(classname) on a weapon or an NPC, imagine the script of the class being copied and pasted into the weapon. You can't pass things to a class; classes extend an object. They aren't their own objects.

Quote:

in java you'd just redefine the var with the classname like

PHP Code:

// not gs2
     
classname.firstnum secondclass.num

and then you'd just initiate the num var in secondclass for use

how would you accomplish this in gs2?
Classes in Java are completely different than GScript ones. The only real similarity is that they have the same name. You can join an infinite number of classes in GScript to a single weapon or NPC.

If you need to pass data between two objects, such as two different weapons, you can do that in a few ways:

In script of -WeaponOne:
PHP Code:

temp.otherWeapon = (@ "-WeaponTwo");

// calls and triggers
temp.otherWeapon.hello("hi!"); // requires -WeaponTwo to have a "public function hello(temp.data) {" in it
temp.otherWeapon.trigger("hello""hi"); // calls "onHello(temp.data)" in -WeaponTwo.

// you can also set data directly
temp.otherWeapon.hello "hi"


oralgnome 09-18-2011 07:02 PM

Quote:

Originally Posted by cbk1994 (Post 1668517)
post

still, good to know that you can pass vars from weapon to weapon but not from weapon to class (since gs2 classes apparently extend instead of inherit)

but yeah, by 'passing vars' i literally meant re-defining one already defined

anyway, OT: yes player.dir is serverside but it can't be read from/to a class (point proven i'm guessing)

Crow 09-18-2011 07:14 PM

It seems you don't understand what a class really is.

oralgnome 09-18-2011 07:17 PM

Quote:

Originally Posted by Crow (Post 1668521)
It seems you don't understand what a class really is.

- snip -

point proven I guess. you pretty much can't use player.dir like he was using because it won't register properly/inherit from the weapon. back 2 the drawing board

still don't really understand what tig was talking about though (because I assume he was using a class to place the bomb/npc)

cbk1994 09-18-2011 07:23 PM

Quote:

Originally Posted by oralgnome (Post 1668519)
still, good to know that you can pass vars from weapon to weapon but not froanyway, OT: yes player.dir is serverside but it can't be read from/to a class (point proven i'm guessing)

Yes it can :oo:.

Again, classes just extend an existing object. If you can access the player object, then you can access the player's dir.

oralgnome 09-18-2011 07:27 PM

Quote:

Originally Posted by cbk1994 (Post 1668523)
Yes it can :oo:.

Again, classes just extend an existing object. If you can access the player object, then you can access the player's dir.

no idea why it's not working for me though

edit: my class was serverside whoops (//#CLIENTSIDE allows access to the player. object whereas previously it did not? anyway cool I guess it can be used serverside but first has to be read and not inherited first)


All times are GMT +2. The time now is 03:47 PM.

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