Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPC Drop w/ value (https://forums.graalonline.com/forums/showthread.php?t=134266556)

brokk 06-01-2012 06:29 PM

NPC Drop w/ value
 
How do I set the text in the NPC of a clientr.var.

Here is the NPC script

PHP Code:

function onCreated()
{
  
showText(205188115$pref::graal::defaultfontname"c""" @(player.clientr.hp));

//all the show text stuff that comes with it
 
setTimer(0.2);
 }
 
function 
onTimeOut()
{
destroy();



and the place script

PHP Code:

      temp.npc this.level.putNPC2(player.x+4.5player.y""); 
      
temp.npc.join("healthdisplay"); 


Emera 06-01-2012 06:50 PM

Firstly, there's some things you could improve with your code. There's not really any consitancy with your styling, and instead of using a timeout you can use scheduleEvent()

Secondly, you just have to set the text of the NPC to what you want it to say using this.chat;

PHP Code:

function onCreated() {
  
this.chat player.clientr.hp;
  
scheduleEvent(2"onDestroy");
}

function 
onDestroy() {
  
this.destroy();


If that's what you mean.

Tolnaftate2004 06-01-2012 07:09 PM

There's no player within the scope of onCreated on the server-side.

If there is a player in the scope that is creating the NPC, then you can do e.g., temp.npc.chat = player.clientr.hp;.

brokk 06-01-2012 07:11 PM

Quote:

Firstly, there's some things you could improve with your code. There's not really any consitancy with your styling, and instead of using a timeout you can use scheduleEvent()

Secondly, you just have to set the text of the NPC to what you want it to say using this.chat;
but the NPC doesn't know which player. Basically when you touch a a certain NPC (let's call it npcA) it created the NPC drawing the player.hp (npcB)

so npcA is creating npcB but I want it to display the player who touched npcA their hp.
Doesn't it have to do with params?

Emera 06-01-2012 07:27 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1696129)
There's no player within the scope of onCreated on the server-side.

If there is a player in the scope that is creating the NPC, then you can do e.g., temp.npc.chat = player.clientr.hp;.

Oh crap! My bad, I wasn't thinking. Sorry for any confusion caused.

brokk 06-01-2012 07:50 PM

Quote:

Oh crap! My bad, I wasn't thinking. Sorry for any confusion caused.
Sooooo is there any solution to my problem??

Tolnaftate2004 06-01-2012 07:56 PM

Quote:

Originally Posted by brokk (Post 1696132)
Sooooo is there any solution to my problem??

Just set some property of the npc (say, player_hp) by doing temp.npc.player_hp = player.clientr.hp; when creating the npc (i.e., below putnpc2). Then, when you want to display the number, just use this.player_hp instead of player.clientr.hp in your class.

You could also just do temp.npc.showtext(...), if you wanted.


All times are GMT +2. The time now is 06:57 AM.

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