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 12-03-2008, 04:38 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Custom Projectile

PHP Code:
function onPlayerChats() {
  if (
player.chat == ":destroy")
    
this.destroy();
}
//#CLIENTSIDE
function onCreated() {
  
setimg("era_pl9-bullet.png");
  
setshape(1,32,32);
  
setTimer(0.05);
  
this.owneraccount player.account;
  
this.dird player.dir;
  
this.spread random(-client.spread,client.spread);
  
scheduleevent(5,"Destroy","");
}
function 
onTimeOut() {
  
this.+= vecx(this.dird) + (player.dir in {02} ? this.spread/16 0);
  
this.+= vecy(this.dird) + (player.dir in {13} ? this.spread/16 0);
  
setTimer(0.05);

I am trying to make a custom projectile.
Well, it works fine unill now, the only part that is missing, is the damage part.

Well, I am stuck, how can I make it damage on Hit, without using shoot()?
Reply With Quote
  #2  
Old 12-03-2008, 05:26 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
You'll have to detect in a timeout if the projectile is on a player/npc, and thus... BOOM.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 12-03-2008, 05:26 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
I'd probably do something like this in the timeout loop:

PHP Code:
for (plplayers) {
  if (
this.x in |pl.xpl.3| && this.y in |pl.ypl.y3|) {
    
//hit stuff
  
}

I think you'd do something similar for NPCs.

Last edited by Codein; 12-03-2008 at 07:51 PM..
Reply With Quote
  #4  
Old 12-04-2008, 02:12 AM
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
Might be easier or more efficient to use findnearestplayer()
__________________
Reply With Quote
  #5  
Old 12-04-2008, 11:53 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by Codein View Post
I'd probably do something like this in the timeout loop:

PHP Code:
for (plplayers) {
  if (
this.x in |pl.xpl.3| && this.y in |pl.ypl.y3|) {
    
//hit stuff
  
}

I think you'd do something similar for NPCs.
You're a genius dude.

Thanks.
Reply With Quote
  #6  
Old 12-04-2008, 12:04 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
PHP Code:
for (temp.0temp.2temp.i++) {
  for (
temp.objnpcs players) {
    if (
this.x in |obj.xobj.3| && this.y in |obj.yobj.y3|) {
      
//hit stuff
    
}
  }

There, now you have a loop for both players and NPC's.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 12-04-2008, 12:13 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by xXziroXx View Post
PHP Code:
for (temp.0temp.2temp.i++) {
  for (
temp.objnpcs players) {
    if (
this.x in |obj.xobj.3| && this.y in |obj.yobj.y3|) {
      
//hit stuff
    
}
  }

There, now you have a loop for both players and NPC's.
Why would I need a loop for the player and for the Projectile?
o_O
Reply With Quote
  #8  
Old 12-04-2008, 12:15 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
Quote:
Originally Posted by Pelikano View Post
Why would I need a loop for the player and for the Projectile?
o_O
So you're saying your projectiles will only be able to damage players, and not NPC's? If that's the case, by all means, use Codein's loop, but otherwise you'd need mine.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #9  
Old 12-04-2008, 12:18 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Well, I don't have any NPCs
Reply With Quote
  #10  
Old 12-04-2008, 06:39 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
you will if you're making an era type server, trust me.
Reply With Quote
  #11  
Old 12-04-2008, 06:53 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
I'd also use a gani for the bullet, rather than it being a static image.

Last edited by Codein; 12-04-2008 at 11:31 PM..
Reply With Quote
  #12  
Old 12-13-2008, 08:30 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Well.
Thanks again, I got another question tho:

I am trying to make the projectile destroy after 3 seconds, so I'm using:

scheduleevent(3,"StarDestroy","");

function onStarDestroy() {
triggeraction(this.x + 6/16, this.y + 6/16, "StarDestroy", nil);
}

function onActionStar() {
this.destroy();
}

And it doesnt work x_X, am I triggering it wrong, or what? :o
Reply With Quote
  #13  
Old 12-13-2008, 08:49 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Why are you triggering an action to destroy it? Just destroy it in the function.
Reply With Quote
  #14  
Old 12-14-2008, 12:40 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Uhm..
Well, because when I use this.destroy(); clientside, it doesn't really destroy it o_O
Reply With Quote
  #15  
Old 12-14-2008, 12:51 PM
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 Pelikano View Post
Uhm..
Well, because when I use this.destroy(); clientside, it doesn't really destroy it o_O
Then just do something like this:

PHP Code:

function onCreated() {
  
setTimer(3);
}

function 
onTimeout() {
  
destroy();
}
//#CLIENTSIDE

// All your clientside code here 
__________________
Reply With Quote
  #16  
Old 12-14-2008, 01:26 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Good idea, but I'm using a function onCreated Clientside already and I need that function onCreated Clientside, because I start a timer clientside with that function, which is needed oO

Also "destroy();" would destroy the whole script I heard xD
Reply With Quote
  #17  
Old 12-14-2008, 01:31 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Pelikano View Post
Good idea, but I'm using a function onCreated Clientside already and I need that function onCreated Clientside, because I start a timer clientside with that function, which is needed oO
You can have an onCreated() serverside and an onCreated() clientside at the same time.

Quote:
Originally Posted by Pelikano View Post
Also "destroy();" would destroy the whole script I heard xD
It should only destroy the NPC, not the entire script.
Reply With Quote
  #18  
Old 12-14-2008, 01:33 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Really?
Awesome, thank you.
I'll try that

Works perfect.
Thanks.
Reply With Quote
  #19  
Old 12-14-2008, 02:56 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Ok another thing.
I decided to move the projectile serverside, because I was told that I had to do it like that, so it looks somewhat like this:

PHP Code:
function onCreated() {
  
setimg("shuriken_icon.gif");
  
setshape(1,12,12);
  
this.dird player.dir;
  
this.spread random(-client.spread,client.spread);
  
dontblock();
  
scheduleevent(3,"StarDestroy","");
  
setTimer(0.1);
}
function 
onTimeOut() {
  if (!
onwall(this.6/16 vecx(this.dir)*7/16this.6/16 vecy(this.dir)*7/16)) { 
    
this.+= vecx(this.dird) + (player.dir in {02} ? this.spread/16 0);
    
this.+= vecy(this.dird) + (player.dir in {13} ? this.spread/16 0);
    
setTimer(0.1);
  }
  
triggeraction(this.6/16 vecx(this.dir)*8/16,this.6/16 vecy(this.dir)*8/16,"StarDamage",nil);

Well, it does not work at all anymore!
The projectile gets spawned in front of my player, yes, but it doesn't move anymore.
While debugging I figured out that "this.spread" and "this.dird" are both 0 now and won't get set to what I want them to get set oO

x_X
Anyone?
Reply With Quote
  #20  
Old 12-14-2008, 03:14 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
That's because "onCreated" serversided in a local NPC isn't an event triggered related to a player, so "player" equals NULL.

You'll need to pass the player object through your putnpc function, similar to this:

PHP Code:
temp.foobar putnpc2(xy"");
foobar.owner player
Then you can just replace "player" with "this.owner" in the script.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #21  
Old 12-14-2008, 03:20 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
I don't get it
Reply With Quote
  #22  
Old 12-14-2008, 03:25 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
Post the part of your code that you use to spawn projectiles please.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #23  
Old 12-14-2008, 03:27 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
function onActionServerSide() {
putnpc2(params[0],params[1],"join bullet;");
}
Reply With Quote
  #24  
Old 12-14-2008, 03:30 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Pelikano View Post
function onActionServerSide() {
putnpc2(params[0],params[1],"join bullet;");
}
Yeah. You should do this:

PHP Code:
function onActionServerside() {
  
temp.proj putnpc2(params[0], params[1], NULL);
  
temp.proj.owner player;
  
temp.proj.join("bullet");
 

Then, for the dir, type this.owner.dir instead of player.dir.
Reply With Quote
  #25  
Old 12-14-2008, 03:32 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
Change that, too...

PHP Code:
function onActionServerSide() {
  
temp.npc putnpc2(params[0],params[1],"");
  
npc.owner player;
  
npc.join("bullet");

... and your projectile script too...

PHP Code:
function onCreated() {
  
setimg("shuriken_icon.gif");
  
setshape(1,12,12);
  
this.dird this.owner.dir;
  
this.spread random(-this.owner.client.spreadthis.owner.client.spread);
  
dontblock();
  
scheduleevent(3,"StarDestroy","");
  
setTimer(0.1);
}

function 
onTimeOut() {
  if (!
onwall(this.6/16 vecx(this.dir)*7/16this.6/16 vecy(this.dir)*7/16)) { 
    
this.+= vecx(this.dird) + (this.owner.dir in {02} ? this.spread/16 0);
    
this.+= vecy(this.dird) + (this.owner.dir in {13} ? this.spread/16 0);
    
setTimer(0.1);
  }
  
triggeraction(this.6/16 vecx(this.dir)*8/16,this.6/16 vecy(this.dir)*8/16,"StarDamage",nil);

__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #26  
Old 12-14-2008, 03:34 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Yes I know.. it works fine.
But I don't understand it lol x_X

Why "this.ower"?

What's this? x_X:

"temp.proj.owner = player;"


Why "NULL"?!

Wtf?! temp.proj.join("bullet");
Reply With Quote
  #27  
Old 12-14-2008, 03:35 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Can't I just set "this.dird" and "this.spread" in a "function onCreated" Clientside and then send it to the server?

If I can do that, how do I send it to the server using triggeraction?

Omg I am so confused lol
Reply With Quote
  #28  
Old 12-14-2008, 03:39 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Pelikano View Post
Yes I know.. it works fine.
But I don't understand it lol x_X

Why "this.ower"?

What's this? x_X:

"temp.proj.owner = player;"


Why "NULL"?!

Wtf?! temp.proj.join("bullet");
The player object is being assigned to temp.proj.owner. Then, in the NPC, you can access the player object who created it, through this.owner.
Reply With Quote
  #29  
Old 12-14-2008, 03:39 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
Quote:
Originally Posted by Pelikano View Post
Why "this.ower"?
You can name it whatever you want, I chose owner to represent it's the person who spawned it.

Quote:
Originally Posted by Pelikano View Post
"temp.proj.owner = player;"
As I said, you can't access "player" in a serversided onCreated(), since it's not an event related to a player but rather when the script is executed the first time.

Quote:
Originally Posted by Pelikano View Post
Why "NULL"?!
NULL and "" is the same thing, more or less. In this case it doesn't matter which you use.

Quote:
Originally Posted by Pelikano View Post
Wtf?! temp.proj.join("bullet");
Yes, let me explain:

temp.npc = putnpc(x, y, ""); - This spawns an NPC on the coordinates x and y. By doing it like this you can change the values of the spawned NPC by accessing "temp.npc".

npc.owner = player - This sets the this.owner in the projectile to the player object, so you can access data from the player who spawned the projectile.

npc.join("bullet"); - This joins the newly spawned NPC to your projectile class.


Just try the code I gave you man, it'll work.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #30  
Old 12-14-2008, 03:42 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Thank you.

I'll read this 50 times now untill I understand it

Also what you gave me doesn't work.
Reply With Quote
  #31  
Old 12-14-2008, 03:59 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
Quote:
Originally Posted by Pelikano View Post
Also "destroy();" would destroy the whole script I heard xD
By the way, that only happens if you use destroy() serversided in a Weapon or DB NPC.
__________________
Follow my work on social media post-Graal:Updated august 2025.
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 10:49 PM.


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