Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-06-2012, 11:14 PM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
"If player has" Scripting

I'm trying to make it so that "If this player has this weapon, Then you can do this".
For instance, You find a guy. This guy gives you a key. You go up to a door (without this key) and it doesn't work.
But you go up to it (with this key) and it opens linking to another level.

That was just an example. I want this to work for many things like, You buy this item, And you are then able to have access to a room.

All I can think of script-wise is
findweapon("key");

then I have NO idea at ALL what script would come come after for searching this players weapons. It's got to be like, Find the weapon, If found, The door will open, If not, it will say "You are not Authorized" or something.
Help? I have no clue what to do..
Reply With Quote
  #2  
Old 05-06-2012, 11:31 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
You could check a clientr variable...

player.clientr.quest_dungeonkey = 1;

..

if(player.clientr.quest_dungeonkey) {
// next level
}else{
// Not authorized
}

Obviously you would change the names to something that would keep your clientr variables organised.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #3  
Old 05-06-2012, 11:50 PM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Quote:
Originally Posted by BlueMelon View Post
You could check a clientr variable...

player.clientr.quest_dungeonkey = 1;

..

if(player.clientr.quest_dungeonkey) {
// next level
}else{
// Not authorized
}

Obviously you would change the names to something that would keep your clientr variables organised.
At the same time I want to learn. Player.clientr.quest would mean what?
Is dungeonkey the name of the item in the script you've listed?
What's variable 1 for?
The rest of it I can figure out with this=)
Reply With Quote
  #4  
Old 05-07-2012, 12:52 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Fysez View Post
At the same time I want to learn. Player.clientr.quest would mean what?
Is dungeonkey the name of the item in the script you've listed?
What's variable 1 for?
The rest of it I can figure out with this=)
You should probably start at the beginning. We're happy to help you with GScript's quirks or other complicated stuff, but there's no point in explaining the simple stuff again when it's already been explained before. The tutorial I linked you to is a good resource for getting started.
__________________
Reply With Quote
  #5  
Old 05-07-2012, 05:32 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Quote:
Originally Posted by cbk1994 View Post
You should probably start at the beginning. We're happy to help you with GScript's quirks or other complicated stuff, but there's no point in explaining the simple stuff again when it's already been explained before. The tutorial I linked you to is a good resource for getting started.
I'm not new. And I wouldn't have posted this thread if I didn't search already how to do this. That's why i'm asking. Questions are good and are meant to be asked. So if you don't have the answer yourself, Just... Don't even comment.
Reply With Quote
  #6  
Old 05-07-2012, 06:42 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Fysez View Post
I'm not new. And I wouldn't have posted this thread if I didn't search already how to do this. That's why i'm asking. Questions are good and are meant to be asked. So if you don't have the answer yourself, Just... Don't even comment.
Lacking an understanding of player attributes would place you squarely in the "new" category. If you don't want our help, we won't force it on you—but if you are having trouble with the simple stuff, then you should read the guide I referenced.

The reason I didn't post an explanation of variables is because doing so would be redundant and a waste of my time. That information has already been compiled into Jer's scripting guide.

If you're not interested in becoming a better scripter, and are just interested in getting things done, this is not the forum for you.
__________________
Reply With Quote
  #7  
Old 05-07-2012, 10:37 AM
Loakey_P2P Loakey_P2P is offline
SL Oldbie
Loakey_P2P's Avatar
Join Date: Apr 2006
Location: U.S.A
Posts: 137
Loakey_P2P is an unknown quantity at this point
Send a message via AIM to Loakey_P2P Send a message via Yahoo to Loakey_P2P
Quote:
Originally Posted by Fysez View Post
I'm not new. And I wouldn't have posted this thread if I didn't search already how to do this. That's why i'm asking. Questions are good and are meant to be asked. So if you don't have the answer yourself, Just... Don't even comment.
error 1 : you cant seem to figure out how to make a door open . first off, they done told you that you can do the same thing by simply setting a flag and checking the value . secondly, basic gs check if(hasweapon(#w, )){ tho it may have changed with the gs2 conversion .

error 2 : if you weren't new you would already know how to use flags,values and find weapons .

error 3 : if your gonna insult the community members expect to spend a lot of your time looking up said info on the net or through a series of trial and error in game to work out how to do something cause you done pissed off the people trying to help you .
__________________
Shaded Legend Playerworld
-Past accounts - LoakeyTheElf - Loakey_P2P
-Past Servers - Rune - Sparitoria - Shaded Legends
-Past Sl Jobs * ET/LAT/NAT/LAT Admin/Developer/Admin/Head Admin/Asst. Manager/Manager
-Current Job - Retired

*Sorry you must have mistaken me for someone that cares .
Reply With Quote
  #8  
Old 05-07-2012, 12:44 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Fysez View Post
I'm not new.
Yes. Yes, you are.
__________________
Reply With Quote
  #9  
Old 05-07-2012, 11:28 PM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Quote:
Originally Posted by Loakey_P2P View Post
error 1 : you cant seem to figure out how to make a door open . first off, they done told you that you can do the same thing by simply setting a flag and checking the value . secondly, basic gs check if(hasweapon(#w, )){ tho it may have changed with the gs2 conversion .

error 2 : if you weren't new you would already know how to use flags,values and find weapons .

error 3 : if your gonna insult the community members expect to spend a lot of your time looking up said info on the net or through a series of trial and error in game to work out how to do something cause you done pissed off the people trying to help you .
1. I know how to make a door open, Just not on weapon.
2. I'm not new to scripting, I'm newer to NPC scripting
3. I didn't insult, I simply stated that if he wasn't going to help, It's a waste of everyone's time to even look at his posts. They don't help, And I know they don't because if he posts a link, It ends up having nothing at all to do with the question asked. I read the link, And it had no reference what-so-ever. So "Pissing off the people trying to help you" Doesn't work, Because he's not help.
Reply With Quote
  #10  
Old 05-07-2012, 11:39 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
This is the gist of storing a 'key' as a flag instead of using a weapon.

Key NPC:

PHP Code:
function onPlayerTouchsMe() {
  
clientr.key true// This can be found in the script flags tab of your attributes

Door NPC:

PHP Code:
function onPlayerTouchsMe() {
  if (
clientr.key) {
    
hide();
    
sleep(3);
    
show();
  }

Also 1 is the same as true in GS2.

Documentation:
clientr variable explanation
Logic and conditional statements
__________________
Quote:
Reply With Quote
  #11  
Old 05-08-2012, 05:41 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Alright so I did have a little help.
But for some reason even the help couldn't find this problem?

function onActionserverside(NULL) {
switch (params[0]) {
case "givekey": {
if (clientr.quest1 == NULL){
clientr.quest1=1;
clientr.items.key1=1;}
}
break;
}
}
//#CLIENTSIDE
function onPlayertouchsme() {
player.chat = "Test";
message Test;
triggerserver("gui", name, "givekey");
}

This doesn't set anything into my flags. Why???
Reply With Quote
  #12  
Old 05-08-2012, 06:34 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Once again, please put your code in PHP tags. Cleaning up a little bit and commenting some basic problems:
PHP Code:
function onActionServerSide(NULL) { // camel case; don't use NULL here, use some named argument, e.g. "cmd"
  
switch (params[0]) { // don't use params[0], use your named argument like "cmd"
    
case "givekey"// general consensus is don't use braces here, they're misleading since they don't do anything
      
if (clientr.quest1 == NULL) { // no reason to do this check
        
clientr.quest1 1;     // use true instead of 1 in this case, it's
        
clientr.items.key1 1// clearer to those trying to read your script
      
}
    break;
  }
}

//#CLIENTSIDE
function onPlayerTouchsMe() { // camel case
  
player.chat "Test";
  
this.chat "Test"// don't use GS1; in addition, don't use message, even in GS2 (set this.chat instead)
  
triggerserver("gui"this.name"givekey");

Now that the code is clean and readable, we can talk about why it's not working. I'm guessing you're putting this in a weapon script, but even if you are putting it into an NPC, it won't work.

Assuming it's in a weapon, when would onPlayerTouchsMe ever get called? A weapon isn't an object in-game; it's a background script that runs on the client. It has no physical representation, and hence nothing to touch. This will never be called.

So, the best way to do this is to move your code into an NPC. Then, when the NPC is touched, you'll notice that the player and the NPC both say "Test", but that the trigger never reaches serverside.

If you've read about triggers, you'll know why. The trigger is being sent to a weapon with the NPC's name, but that weapon doesn't exist. In addition to that, level NPC names are arbitrary and somewhat unpredictable.

Normally you'd need to trigger serverside on the NPC instead, but this is a pain. In your case, it's actually a lot simpler than that: onPlayerTouchsMe is called serverside in addition to clientside, so there's no need to communicate between them. We can simplify your code:

PHP Code:
function onPlayerTouchsMe() {
  
player.chat "I completed the quest!";
  
  
// set the player flags
  
player.clientr.quest1 true// prefixing with player. is somewhat less ambiguous
  
player.clientr.items.key1 true;

Then if we want to check if the player has completed the quest later on...

PHP Code:
if (player.clientr.quest1) {
  
player.chat "You've already completed the quest!";
} else {
  
player.chat "You haven't completed the quest yet!";

(if your onPlayerTouchsMe still isn't being called on the serverside, make sure to give it a proper shape—normally this isn't necessary if you're using an image for the NPC)
__________________
Reply With Quote
  #13  
Old 05-08-2012, 07:03 AM
Loakey_P2P Loakey_P2P is offline
SL Oldbie
Loakey_P2P's Avatar
Join Date: Apr 2006
Location: U.S.A
Posts: 137
Loakey_P2P is an unknown quantity at this point
Send a message via AIM to Loakey_P2P Send a message via Yahoo to Loakey_P2P
i fail to see why it even needs to trigger serverside or be done from a weapon for that matter . if your worried about someone hacking the flag through client you might as well just stop now cause it is gonna happen at some point and trying to prevent even one person from doing so is just wasting time .

add npc to level, set img to a key . insert code
PHP Code:
function onPlayertouchsme(){
  if(!
client.haskey == 1){
    
client.haskey=1;
  } else {
    
hide();
  }

add npc to level, set image to door . insert code
PHP Code:
function onPlayertouchsme(){
  if(
client.haskey == 1){
    
hide();
    
sleep(1.5);
    
show();
    unset(
client.haskey);
  } else {
    
show();
  }

is that not good enough ?
__________________
Shaded Legend Playerworld
-Past accounts - LoakeyTheElf - Loakey_P2P
-Past Servers - Rune - Sparitoria - Shaded Legends
-Past Sl Jobs * ET/LAT/NAT/LAT Admin/Developer/Admin/Head Admin/Asst. Manager/Manager
-Current Job - Retired

*Sorry you must have mistaken me for someone that cares .
Reply With Quote
  #14  
Old 05-08-2012, 07:53 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Loakey_P2P View Post
i fail to see why it even needs to trigger serverside or be done from a weapon for that matter . if your worried about someone hacking the flag through client you might as well just stop now cause it is gonna happen at some point and trying to prevent even one person from doing so is just wasting time .

add npc to level, set img to a key . insert code
PHP Code:
function onPlayertouchsme(){
  if(!
client.haskey == 1){
    
client.haskey=1;
  } else {
    
hide();
  }

add npc to level, set image to door . insert code
PHP Code:
function onPlayertouchsme(){
  if(
client.haskey == 1){
    
hide();
    
sleep(1.5);
    
show();
    unset(
client.haskey);
  } else {
    
show();
  }

is that not good enough ?
This is wrong in so many ways. Please ignore this post and read mine instead.
__________________
Reply With Quote
  #15  
Old 05-08-2012, 08:37 AM
Loakey_P2P Loakey_P2P is offline
SL Oldbie
Loakey_P2P's Avatar
Join Date: Apr 2006
Location: U.S.A
Posts: 137
Loakey_P2P is an unknown quantity at this point
Send a message via AIM to Loakey_P2P Send a message via Yahoo to Loakey_P2P
that's for clearing up why . it may not be perfect but i threw it together in less then a minute . it's a lot simpler and when you wanna teach someone to ride a bide you might not want to take off the training wheels right away.... or just throw em on a motorbike .
__________________
Shaded Legend Playerworld
-Past accounts - LoakeyTheElf - Loakey_P2P
-Past Servers - Rune - Sparitoria - Shaded Legends
-Past Sl Jobs * ET/LAT/NAT/LAT Admin/Developer/Admin/Head Admin/Asst. Manager/Manager
-Current Job - Retired

*Sorry you must have mistaken me for someone that cares .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 06:14 PM.


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