Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-21-2013, 04:11 AM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
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.
Reply With Quote
  #2  
Old 12-21-2013, 04:57 AM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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();
  }

__________________
Reply With Quote
  #3  
Old 12-21-2013, 10:57 PM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
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.
Reply With Quote
  #4  
Old 12-21-2013, 11:30 PM
Tim_Rocks Tim_Rocks is offline
a true gentlemen
Tim_Rocks's Avatar
Join Date: Aug 2008
Location: USA
Posts: 1,863
Tim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to beholdTim_Rocks is a splendid one to behold
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.
__________________
Reply With Quote
  #5  
Old 12-22-2013, 01:54 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #6  
Old 12-22-2013, 04:07 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by JohnnyChimpo View Post
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.
__________________
Quote:
Reply With Quote
  #7  
Old 12-22-2013, 04:09 PM
JohnnyChimpo JohnnyChimpo is offline
Registered User
JohnnyChimpo's Avatar
Join Date: Jun 2004
Posts: 105
JohnnyChimpo is on a distinguished road
Quote:
Originally Posted by Stefan View Post
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?
Reply With Quote
  #8  
Old 12-29-2013, 03:06 AM
Sage_Shadowbane Sage_Shadowbane is offline
Graal Developer
Sage_Shadowbane's Avatar
Join Date: Mar 2004
Posts: 585
Sage_Shadowbane will become famous soon enough
Quote:
Originally Posted by JohnnyChimpo View Post
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.
Reply With Quote
  #9  
Old 01-14-2014, 04:25 AM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
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.
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 08:14 PM.


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