Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Classes help (https://forums.graalonline.com/forums/showthread.php?t=78321)

SmeewN 01-12-2008 07:36 PM

Classes help
 
I am having trouble placing classes, can someone give me a good example how to putnpc2? :confused:

function onCreated()
{
setimg("snicon_blank.gif")
timeout = 2;
}
function ontimeout()
{
this.destroy();
}

This is my class's script.
I can't get putnpc2 to work on an NPC or weapon.

Switch 01-12-2008 07:44 PM

First off, merge the posts.
Second, you need a weapon to link to the class.

SmeewN 01-12-2008 07:46 PM

You don't -need- a weapon, you can use an NPC also >.> I'm having trouble with the "putnpc2" script.

Switch 01-12-2008 07:51 PM

True
I'm saying, you need something to connect to it.
From what I've seen, putnpc2() is in the NPC/Weapon that connects to it.
Also, go to the wiki and search putnpc2 or use search on the forums.

xXziroXx 01-12-2008 07:51 PM

First of all, you've missed a segfault after your "setimg("snicon_blank.gif")" :)

Here's an example on how to use putnpc2 (serverside, of course):


temp.data = putnpc(x, y, "join(\"myclassname\");");
temp.data.chat = "I was just spawned!";
temp.data.setimg("snicon_blank.gif");

Skyld 01-12-2008 08:04 PM

Quote:

Originally Posted by xXziroXx (Post 1369338)
First of all, you've missed a segfault after your "setimg("snicon_blank.gif")" :)

Syntax error.

A segmentation fault is where you try to access memory that isn't allocated to your program.

SmeewN 01-12-2008 08:17 PM

function onActiongotsplaced()
{
temp.data = putnpc2(player.x, player.y, "join(\"object\");");
temp.data.chat = "I was just spawned!";
temp.data.setimg("sn_iconblank.gif");
}

//#CLIENTSIDE

function onweaponfired()
{
triggeraction(0, 0, "gotsplaced");
}

Que?

Inverness 01-12-2008 08:19 PM

You need to have the shape of the npc set on serverside if you want it to be able to receive actions. Also you should be triggering the action on this.x and this.y not 0 and 0.

Though after looking at the script a second time I noticed its a weapon script, since you're using onWeaponFired(), in that case you need to do something different.

This script is for doing it in a weapon.
PHP Code:

function onActionServerSide() {
  if (
params[0] == "gotsplaced") {
    
//stuff
  
}
}
//#CLIENTSIDE
function onWeaonFired() {
  
triggerserver("weapon"this.name"gotsplaced");


This is for an NPC.
PHP Code:

function onCreated() {
  
setshape(13232);
}
function 
onActionGotsPlaced() {
  
// do stuff
}
//#CLIENTSIDE
function onCreated() {
  
setshape(13232);
}
function 
onWhateverEventYouNeed() {
  
triggeraction(this.xthis.y"GotsPlaced"yourparametershere);



SmeewN 01-12-2008 08:36 PM

Thanks, got it to work, awesome.

Can you pass variables to the class?

like putting:
temp.data.myvar = 0;

would make it accessable to the class?

Switch 01-12-2008 08:41 PM

if you set what that variable/string is in the class and what it does, then yes, of course, you access it VIA the weapon and change it there, or link class to class and change it within them.

Chompy 01-13-2008 12:43 AM

Quote:

Originally Posted by SmeewN (Post 1369345)
Thanks, got it to work, awesome.

Can you pass variables to the class?

like putting:
temp.data.myvar = 0;

would make it accessable to the class?

PHP Code:

temp.npc putnpc(xy"");

with(temp.npc) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";



xXziroXx 01-13-2008 01:43 AM

PHP Code:

with(putnpc(xy"")) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";


Even simpler. :)

Chompy 01-13-2008 01:48 AM

Quote:

Originally Posted by xXziroXx (Post 1369381)
PHP Code:

with(putnpc(xy"")) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";


Even simpler. :)

:) <3

SmeewN 01-15-2008 09:47 PM

Quote:

Originally Posted by Chompy (Post 1369371)
PHP Code:

temp.npc putnpc(xy"");

with(temp.npc) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";



What's id and owner?

Twinny 01-15-2008 11:28 PM

Quote:

Originally Posted by SmeewN (Post 1369982)
What's id and owner?

Just examples of setting vars in the newly created putnpc2 via the weapon/npc.

Inverness 01-16-2008 03:29 AM

You can't set the ID for level npcs, its static and read-only. And I doubt its different for ones placed with putnpc().


All times are GMT +2. The time now is 04:52 PM.

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