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 01-12-2008, 07:36 PM
SmeewN SmeewN is offline
Registered User
Join Date: Dec 2007
Posts: 5
SmeewN is on a distinguished road
Classes help

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

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.

Last edited by SmeewN; 01-12-2008 at 07:51 PM..
Reply With Quote
  #2  
Old 01-12-2008, 07:44 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
First off, merge the posts.
Second, you need a weapon to link to the class.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #3  
Old 01-12-2008, 07:46 PM
SmeewN SmeewN is offline
Registered User
Join Date: Dec 2007
Posts: 5
SmeewN is on a distinguished road
You don't -need- a weapon, you can use an NPC also >.> I'm having trouble with the "putnpc2" script.
Reply With Quote
  #4  
Old 01-12-2008, 07:51 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
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.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #5  
Old 01-12-2008, 07:51 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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");
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 01-12-2008, 08:04 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by xXziroXx View Post
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.
Reply With Quote
  #7  
Old 01-12-2008, 08:17 PM
SmeewN SmeewN is offline
Registered User
Join Date: Dec 2007
Posts: 5
SmeewN is on a distinguished road
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?
Reply With Quote
  #8  
Old 01-12-2008, 08:19 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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);

__________________
Reply With Quote
  #9  
Old 01-12-2008, 08:36 PM
SmeewN SmeewN is offline
Registered User
Join Date: Dec 2007
Posts: 5
SmeewN is on a distinguished road
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?
Reply With Quote
  #10  
Old 01-12-2008, 08:41 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
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.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #11  
Old 01-13-2008, 12:43 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by SmeewN View Post
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";

__________________
Reply With Quote
  #12  
Old 01-13-2008, 01:43 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
PHP Code:
with(putnpc(xy"")) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";

Even simpler.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #13  
Old 01-13-2008, 01:48 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
with(putnpc(xy"")) {
  
join("classname");
  
id 1;
  
nick "CLasSNaMe";
  
owner "Chompy";

Even simpler.
<3
__________________
Reply With Quote
  #14  
Old 01-15-2008, 09:47 PM
SmeewN SmeewN is offline
Registered User
Join Date: Dec 2007
Posts: 5
SmeewN is on a distinguished road
Quote:
Originally Posted by Chompy View Post
PHP Code:
temp.npc putnpc(xy"");

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

What's id and owner?
Reply With Quote
  #15  
Old 01-15-2008, 11:28 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by SmeewN View Post
What's id and owner?
Just examples of setting vars in the newly created putnpc2 via the weapon/npc.
Reply With Quote
  #16  
Old 01-16-2008, 03:29 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
You can't set the ID for level npcs, its static and read-only. And I doubt its different for ones placed with putnpc().
__________________
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 04:52 PM.


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