Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-18-2011, 06:43 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
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.
Reply With Quote
  #2  
Old 09-18-2011, 07:44 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
try setting its dir on a timeout maybe.
as for vecx and vec i am clueless, never used it before.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #3  
Old 09-18-2011, 08:19 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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); 
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 09-18-2011, 06:09 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
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

Last edited by oralgnome; 09-18-2011 at 06:25 PM..
Reply With Quote
  #5  
Old 09-18-2011, 06:36 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oralgnome View Post
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?
__________________
Reply With Quote
  #6  
Old 09-18-2011, 06:39 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
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?
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?
Reply With Quote
  #7  
Old 09-18-2011, 06:46 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oralgnome View Post
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"
__________________
Reply With Quote
  #8  
Old 09-18-2011, 07:02 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
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)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:21 PM..
Reply With Quote
  #9  
Old 09-18-2011, 07:14 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
It seems you don't understand what a class really is.
__________________
Reply With Quote
  #10  
Old 09-18-2011, 07:17 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by Crow View Post
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)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:28 PM..
Reply With Quote
  #11  
Old 09-18-2011, 07:23 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oralgnome View Post
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 .

Again, classes just extend an existing object. If you can access the player object, then you can access the player's dir.
__________________
Reply With Quote
  #12  
Old 09-18-2011, 07:27 PM
oralgnome oralgnome is offline
doesnt afraid of anything
oralgnome's Avatar
Join Date: Sep 2011
Posts: 34
oralgnome is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
Yes it can .

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)
__________________
Quote:
Originally Posted by CaySedaiSim View Post
Is there a GS2 for retards book..?

Last edited by oralgnome; 09-18-2011 at 07:39 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:37 AM.


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