Jump to content
  • 0

NPC Visibility Variable help


Hirasu

Question


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  61
  • Reputation:   6
  • Joined:  12/23/11
  • Last Seen:  

hey i need some help with a code from @Jonne

 

 

 

diff --git a/src/map/clif.c b/src/map/clif.c
index 2731018..099466f 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -4152,11 +4152,16 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
if (!vd || vd->class_ == INVISIBLE_CLASS)
return;


- /**
- * Hide NPC from maya purple card.
- **/
- if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
- return;
+ if(bl->type == BL_NPC) {
+ /**
+ * Hide NPC from maya purple card.
+ **/
+ if (!((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
+ return;
+ // Only show NPC to people who have a certain variable set
+ if (((TBL_NPC*)bl)->visibility != 0 && ((TBL_NPC*)bl)->visibility == pc_readglobalreg(sd, "npcvisibility"))
+ return;
+ }


ud = unit_bl2ud(bl);
len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
diff --git a/src/map/npc.h b/src/map/npc.h
index ab9d084..b4b6552 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -70,6 +70,7 @@ struct npc_data {
char killer_name[NAME_LENGTH];
} tomb;
} u;
+ int visibility;
};




diff --git a/src/map/script.c b/src/map/script.c
index eda82c7..681867f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -18165,6 +18165,43 @@ static int atcommand_cleanfloor_sub(struct block_list *bl, va_list ap)
return 0;
}


+/**
+ * setvisibility <value>{, <"npc">}
+ * @param <value> the value to set it and checkf or
+ * @param <"npc"> if another NPC should be targetted
+**/
+BUILDIN_FUNC(setvisibility) {
+ struct npc_data *nd = NULL;
+
+ if (script_hasdata(st, 3)) {
+ nd = npc_name2id(script_getstr(st, 3));
+ ShowWarning("buildin_setvisibility: NPC '%s' not found. Using active NPC.\n", script_getstr(st, 3));
+ }
+ if (nd == NULL)
+ nd = map_id2nd(st->oid);
+
+ nd->visibility = script_getnum(st, 2);
+ return 0;
+}
+
+/**
+ * getvisibility {<"npc>"}
+ * @param <"npc"> if another NPC should be targetted
+**/
+BUILDIN_FUNC(getvisibility) {
+ struct npc_data *nd = NULL;
+
+ if (script_hasdata(st, 2)) {
+ nd = npc_name2id(script_getstr(st, 2));
+ ShowWarning("buildin_getvisibility: NPC '%s' not found. Using active NPC.\n", script_getstr(st, 2));
+ }
+ if (nd == NULL)
+ nd = map_id2nd(st->oid);
+
+ script_pushint(st, nd->visibility);
+ return 0;
+}
+
#include "../custom/script.inc"


// declarations that were supposed to be exported from npc_chat.c
@@ -18648,6 +18685,8 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(vip_time,"i?"),
#endif
BUILDIN_DEF(bonus_script,"si???"),
+ BUILDIN_DEF(setvisibility, "i?"),
+ BUILDIN_DEF(getvisibility, "?"),


#include "../custom/script_def.inc"

 

 

* setvisibility <value>{, <"npc">}

* @param <value> the value to set it and checkf or
* @param <"npc"> if another NPC should be targetted

 

You set the value of the NPC to a value not 0. Only players with the character variable "npcvisibility" set to this exact value can now see the NPC. It should also not effect NPCs which have no visibility set, since it ignores the value zero. You have to put this into the OnInit event, since I didn't add a saving mechanism so it will be deleted once you reload. Thus the OnInit.

 

* getvisibility {<"npc>"}

* @param <"npc"> if another NPC should be targetted
**/

An example:

// Some NPC here
OnInit:
SetVisibility(1);
End;

Only a player with the variable "npcvisibility" set to 1 can see the npc now.

 

my Script:

 

prontera,150,150,4 script testitest 110,{

 
OnInit:
SetVisibility(1);
End;
}

 

But i can see the npc with npcvisibility 0 or 1

(No Complie error || No server errors)  /hmm

 

 

Can someone help me please? /help

 

  /thx

Edited by Hirasu
Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  149
  • Reputation:   33
  • Joined:  12/24/11
  • Last Seen:  

Yea, my bad. I just realized this line is wrong:  if (((TBL_NPC*)bl)->visibility != 0 && ((TBL_NPC*)bl)->visibility == pc_readglobalreg(sd, "npcvisibility"))

 

It should be:

 if (((TBL_NPC*)bl)->visibility != 0 && ((TBL_NPC*)bl)->visibility != pc_readglobalreg(sd, "npcvisibility"))
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  15
  • Topics Per Day:  0.00
  • Content Count:  61
  • Reputation:   6
  • Joined:  12/23/11
  • Last Seen:  

Posted · Hidden by Emistry, January 8, 2015 - non-english
Hidden by Emistry, January 8, 2015 - non-english

 

Yea, my bad. I just realized this line is wrong:  if (((TBL_NPC*)bl)->visibility != 0 && ((TBL_NPC*)bl)->visibility == pc_readglobalreg(sd, "npcvisibility"))

 

It should be:

 if (((TBL_NPC*)bl)->visibility != 0 && ((TBL_NPC*)bl)->visibility != pc_readglobalreg(sd, "npcvisibility"))

Hey , danke erstmal das du mir helfen möchtest aber ich hab den code ersetzt und neu compiled aber es geht noch immer nicht 

 

mein script:

 

 

prontera,150,150,4 script testitest 110,{

 
OnInit:
SetVisibility(1);
End;
}

 hab es mit 1 und 0 getestet aber es funktioniert nicht und bekomm auch keine errors :(

ich warte auf so ein code seit 7 jahren wäre echt nett wenn du es hinbekommen würdest :)

Link to comment

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  149
  • Reputation:   33
  • Joined:  12/24/11
  • Last Seen:  

I wish I could further test, but I'm on a business trip until May :/ I will definetly check it out then again, if nobody has fixxed it until then. I know what you mean about that code, as it could add something like episodes of story to the NPCs. Sorry about the bummer for now

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  53
  • Topics Per Day:  0.01
  • Content Count:  411
  • Reputation:   261
  • Joined:  04/25/12
  • Last Seen:  

Jonne, some news?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...