Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Putnpc clientside (https://forums.graalonline.com/forums/showthread.php?t=134268939)

JohnnyChimpo 12-21-2013 04:11 AM

Putnpc clientside
 
What are the methods to place an NPC where only one client can see it. Basically im trying to display an NPC for one person, but others can not see or interact with it.

Tim_Rocks 12-21-2013 04:57 AM

What I did in the past was assigned an account to an attribute. Then on the clientside, just have a check to see if the player is equal to the attribute. For better reliability though, it may be helpful to use a timeout script in case you plan on changing the attribute to another player. Hope this helps.

PHP Code:

function onCreated() {
  
this.attr[5] = "Tim_Rocks";  //Your account would go here;
}

//other functions here, just make sure to have the proper checks.

//#CLIENTSIDE
function onCreated() {
  if (
player.account != this.attr[5]) {
    
this.hide();
  } else {
    
this.show();
  }



JohnnyChimpo 12-21-2013 10:57 PM

Okay thanks for the suggestion. I still dont think it will fit my needs though. In short i am trying to make a shop, only display items to certain players. What players get displayed the shop items are based off of variables in a sql database(per individual player). The trouble im having is, when i place the npcs (putnpc2) and connect it to my item class, i am not able to access the clientdata(sql). I cannot triggeraction clientside from serverside, nor triggerClientside from server side in a putnpc2. I think i might be going about this wrong, but i dont see any better way, besides possibly using showimg.

Tim_Rocks 12-21-2013 11:30 PM

My suggestion should work. Here, I will prove it to you.

I would add the putNPC2 in a weapon of some sort.
PHP Code:

function onPlayerChats() {
  if (
player.chat == ":dropitem") {
    
    
with (putNPC2(player.3player.1"join item;")) { //I would change this to your class.
      
this.owner player.account;
    }
  
    
player.chat "I dropped the item!";
  }


The class for the item will look like this, only you will be able to see it.
PHP Code:

function onCreated() {
  
this.attr[5] = this.owner;
  
  
this.setimg("block.png");
}

function 
onActionGrab() {
  if (
player.account != this.owner) {
    return; 
//Prevents other players from taking the item.
  
}
  
  
player.chat "Item added!";
  
  
//Item adding will go here.
  
  
this.destroy();
}

//#CLIENTSIDE
function onCreated() {
  if (
player.account != this.attr[5]) {
    
this.hide();
  } else {
    
this.show();
  }


Hopefully this was helpful.

Admins 12-22-2013 01:54 PM

It could be possible to just add a normal shop npc and when you click/grab it then it's opening a GUI. You would just need normal triggerclient() for that.

fowlplay4 12-22-2013 04:07 PM

Quote:

Originally Posted by JohnnyChimpo (Post 1724334)
Okay thanks for the suggestion. I still dont think it will fit my needs though. In short i am trying to make a shop, only display items to certain players. What players get displayed the shop items are based off of variables in a sql database(per individual player). The trouble im having is, when i place the npcs (putnpc2) and connect it to my item class, i am not able to access the clientdata(sql). I cannot triggeraction clientside from serverside, nor triggerClientside from server side in a putnpc2. I think i might be going about this wrong, but i dont see any better way, besides possibly using showimg.

You shouldn't need to use putnpc2. You should have one vendor NPC, and when they touch/click or whatever to open the shop window, it determines the items that they're selling and triggerclient's to the weapon NPC that handles displaying your shop GUI.

JohnnyChimpo 12-22-2013 04:09 PM

Quote:

Originally Posted by Stefan (Post 1724383)
It could be possible to just add a normal shop npc and when you click/grab it then it's opening a GUI. You would just need normal triggerclient() for that.

Right because you'd be using the onActionRightClick/onPlayerTouchsme, which focuses that player allowing you to reference that player specifically. But how about a shop NPC ( level NPC, connected to a class), wants to lay items out in the level (putnpc2). If you want to show everyone thats easy, you just leave it at that. However if you want to drop items, individually for each player, so say, there is a set w,x,y,z of items. Player 1 walks in and the only items on the table he/she will see, is w,x. However in that same moment, player 2 walks in but player 2 will see y,z. And NOT w,x. OR more strictly they will see exactly what they should and nothing that they shouldnt. Is this possible?

Sage_Shadowbane 12-29-2013 03:06 AM

Quote:

Originally Posted by JohnnyChimpo (Post 1724385)
Right because you'd be using the onActionRightClick/onPlayerTouchsme, which focuses that player allowing you to reference that player specifically. But how about a shop NPC ( level NPC, connected to a class), wants to lay items out in the level (putnpc2). If you want to show everyone thats easy, you just leave it at that. However if you want to drop items, individually for each player, so say, there is a set w,x,y,z of items. Player 1 walks in and the only items on the table he/she will see, is w,x. However in that same moment, player 2 walks in but player 2 will see y,z. And NOT w,x. OR more strictly they will see exactly what they should and nothing that they shouldnt. Is this possible?

99% sure that Tim's method would work for what you're trying to do.

100Zero100 01-14-2014 04:25 AM

Tim's method would work, but it still isn't ideal. In fact, I'd go so far as to say it's downright bad. Putnpc2's tend not to destroy 100% responsibly, so you'd need to code in redundant garbage collecting for them. That's also a lot of unnecessary nonsense.

Stefan/fp4 are right on the money here. The way you would do it is as follows:

(in weapon)

(on serverside):
onplayerenters -> recognize shop level -> get NPC list from SQL DB -> triggerclient that info to the weapon

(on clientside):
onactionclientside -> the item list is a param -> use that item list to set up what NPCs the shop should be selling in the GUI or for the "laid out" npcs (more on that later)

You could optionally remove it as a weapon NPC entirely and just make it a level NPC or DB NPC as follows:

(serverside):
onplayerenters -> retrieve what NPCs that player should have from an SQL DB -> save the list of those npcs to the player (eg, player.client.npcs)

(clientside, in same level npc):
onplayerenters -> timeout until the player.client.npcs flag is set -> once set, take that list of NPCs as the list of NPCs the player can buy -> you can stop timeout'ing now. The timeout should only occur 0-2 times, just long enough for the info to reach you from the server. -> clear the client. flag now, otherwise the flag will conflict next time you enter the level.

Note: While using client. flag is obviously insecure, that shouldn't matter because purchasing the NPC will send a trigger to serverside, which, for security purposes, needs to verify (again) that the player is authorized to purchase that NPC, anyway.

You said you want to lay out the items in the level itself, rather than using a GUI. That's a bit harder but still not impossible. For example:

1. Have ~10 generic "shop item" NPCs that haven't had their this.item defined yet (and they're invisible) in the level. I say "10" but you can use whatever you feel is the "limit" for NPCs. If it's going to sell 30 different NPCs, you can put 30. It doesn't matter.

2. Use the methods I discussed before (either or) to get your "list" (ie, string array) of NPC names. You can optionally pass icons as well, or the icons can be included in the clientside ahead of time, corresponding with names of course.

3. Do something like: "for (temp.npc: npcs) { if (npc.isItem && npc.itemName == nil) {" -- that will find NPCs that are those "invisible items" I told you about (as long as they have this.isItem = true; in their script) and will only define them to be an NPC if they haven't already been defined (assuming definition of this.itemName).

An even slightly more efficient way of doing that would be for the "item" NPCs to load themselves into a level. array on created (in clientside), and then the #3 step can loop among something like "for (temp.npc: level.items) {" rather than looping over ALL level NPCs.

Any of those methods would be greatly superior to using putnpc2.


All times are GMT +2. The time now is 03:09 AM.

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