Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Problem using a level NPC that's joined to a class (https://forums.graalonline.com/forums/showthread.php?t=134264114)

Adddeeee 08-09-2011 08:27 PM

Thank you very much! Now I think I understand the DB NPC :)

Although, I still have problems with the PlayerTouchsMe. It seems as if the player touches the NPC when the player is located to the top left of the NPC.

This is the NPC script:

PHP Code:

join("shop");

//#CLIENTSIDE

function onCreated()
{
  
showcharacter();
  
nick "Candy"//Sets the nickname of the character
  
ap 100//Sets the ap of the character. Also affects the colour of the nickname
  
headimg "head722.gif"//What head image to use
  
bodyimg "body8.png";   //What body image to use
  
colors[0] = "orange";     //Sets the skin colour
  
colors[1] = "lightblue";     //Sets the coat colour
  
colors[2] = "yellow";     //Sets the sleeves colour
  
colors[3] = "darkred";     //Sets the shoes colour
  
colors[4] = "lightgreen";     //Sets the belt colour
  
shieldimg "no-shield.gif"//Sets the shield image
  
shieldpower 1//Must have this or the shield won't show



and this is the shop class:

PHP Code:

function onCreated()
{
   
setShape(13232);
   
this.shop_id "basicshop";
}

function 
onPlayerTouchsMe()
{
  
this.listofitems DB_Items.getShopItems(this.shop_id);
  
triggerclient("gui""-shopcontrol"this.listofitemsthis.xthis.y);         


Am I missing something that causes the PlayerTouchsMe to fire when I'm located to the top left of the NPC?

cbk1994 08-09-2011 08:30 PM

You're setting the shape to a 32px by 32px block, which doesn't perfectly fit the character. Try something like 38x48 (change the setShape). I can't remember exactly what it should be, so just change the values until it's working as you want it to, being sure to update the level in-between changes.

Adddeeee 08-09-2011 08:32 PM

Ah okay, I thought 32x32 pixels was the default character size :O

Isn't the "hit box" drawn from the upper left corner of the NPC to the lower right corner as a rectangle with the size specified in setShape?

fowlplay4 08-09-2011 08:53 PM

For normal NPCs 48 by 48 will do fine on server-side, and you're right on about the hit box.

The point of your shop class is to make it accept any shop id, so in your NPC you should be setting the shop id not in the class itself. I.e:

PHP Code:

function onCreated() {
  
this.shopid "basicshop";
  
this.join("shop");


In your class you can then do a check like this..

PHP Code:

// Undefined shops default to the basic shop
if (this.shop_id == NULLthis.shop_id "basicshop"


Adddeeee 08-09-2011 09:03 PM

Yepp :) I did that just to check if it worked. I'm going to setup different shop IDs and add them to the different NPCs before joining the class.

But if I set the setshape to 48, 48 wouldn't I touch the NPC even when I'm far away from it?

EDIT: NOticed that it worked just fine :) But what about the 32, 32 hit box?

Feels like I need an explanation why the hit box is 32,32 while the NPC should be set to 48,48? Is it because the NPCs image blocks the player?

fowlplay4 08-09-2011 09:20 PM

Quote:

Originally Posted by Adddeeee (Post 1662725)
Yepp :) I did that just to check if it worked. I'm going to setup different shop IDs and add them to the different NPCs before joining the class.

But if I set the setshape to 48, 48 wouldn't I touch the NPC even when I'm far away from it?

It's in pixels, so no. I don't think it will be touched until the "wall" of your player collides with it on the server-side.


All times are GMT +2. The time now is 03:34 PM.

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