PDA

View Full Version : Classes help


SmeewN
01-12-2008, 07:36 PM
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
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.

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

This is for an NPC.

function onCreated() {
setshape(1, 32, 32);
}
function onActionGotsPlaced() {
// do stuff
}
//#CLIENTSIDE
function onCreated() {
setshape(1, 32, 32);
}
function onWhateverEventYouNeed() {
triggeraction(this.x, this.y, "GotsPlaced", your, parameters, here);
}

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
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?


temp.npc = putnpc(x, y, "");

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

xXziroXx
01-13-2008, 01:43 AM
with(putnpc(x, y, "")) {
join("classname");
id = 1;
nick = "CLasSNaMe";
owner = "Chompy";
}


Even simpler. :)

Chompy
01-13-2008, 01:48 AM
with(putnpc(x, y, "")) {
join("classname");
id = 1;
nick = "CLasSNaMe";
owner = "Chompy";
}


Even simpler. :)

:) <3

SmeewN
01-15-2008, 09:47 PM
temp.npc = putnpc(x, y, "");

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

What's id and owner?

Twinny
01-15-2008, 11:28 PM
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().