Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   "If player has" Scripting (https://forums.graalonline.com/forums/showthread.php?t=134266381)

Fysez 05-06-2012 11:14 PM

"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..:cry:

BlueMelon 05-06-2012 11:31 PM

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.

Fysez 05-06-2012 11:50 PM

Quote:

Originally Posted by BlueMelon (Post 1693857)
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=)

cbk1994 05-07-2012 12:52 AM

Quote:

Originally Posted by Fysez (Post 1693859)
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.

Fysez 05-07-2012 05:32 AM

Quote:

Originally Posted by cbk1994 (Post 1693861)
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.;)

cbk1994 05-07-2012 06:42 AM

Quote:

Originally Posted by Fysez (Post 1693897)
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.

Loakey_P2P 05-07-2012 10:37 AM

Quote:

Originally Posted by Fysez (Post 1693897)
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 .

Crow 05-07-2012 12:44 PM

Quote:

Originally Posted by Fysez (Post 1693897)
I'm not new.

Yes. Yes, you are.

Fysez 05-07-2012 11:28 PM

Quote:

Originally Posted by Loakey_P2P (Post 1693919)
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.;)

fowlplay4 05-07-2012 11:39 PM

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

Fysez 05-08-2012 05:41 AM

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???

cbk1994 05-08-2012 06:34 AM

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)

Loakey_P2P 05-08-2012 07:03 AM

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 ?

cbk1994 05-08-2012 07:53 AM

Quote:

Originally Posted by Loakey_P2P (Post 1694035)
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.

Loakey_P2P 05-08-2012 08:37 AM

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 .


All times are GMT +2. The time now is 11:24 AM.

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