Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggerserver not detected (https://forums.graalonline.com/forums/showthread.php?t=134265033)

Emera 11-13-2011 01:06 PM

Triggerserver not detected
 
I am coding a shop class for buying things on Lexia, and everything seems to be going amazingly well. The only thing I am being jammed on is adding the weapon to the player and subtracting the gold. Can somebody help me out? Here's the class. (Added to pastebin since incapsula is a douche)

http://pastebin.graalcenter.org/read...d=471071864374

callimuc 11-13-2011 03:51 PM

Maybe that?

http://pastebin.graalcenter.org/read...=1081401087146

Also I´d use clientr.gold for the players money, since using client.gold can get easily edited (as far as I heard).

cbk1994 11-13-2011 05:38 PM

The problem is that you're triggering serverside like it's a weapon. You can't do that.

Instead, something like

PHP Code:

function onCreated() {
  
this.itemName "whatever";
  
this.itemPrice 123123;
  
  
this.setShape(11616); // so it can be triggered)
}

function 
onActionPurchase() {
  echo(
player.account " wants to purchase this item!");
}

//#CLIENTSIDE
function Shop_Button1.onAction() {
  if (
client.gold client.store1 || client.gold == client.store1) {
    if (!(
hasweapon((@client.realitem)))) {
      
triggerAction(this.xthis.y"purchase"null);
    }
  }


You're trusting the clientside way too much. Any client. variables can be changed by the player; always assume they have been tampered with. You need to store the item price and name on the serverside if that's where you need to access them. I could easily purchase any item I wanted to on your server for no money at all.

While my example should work, I highly recommend you take the code out of the item class and centralize all of it in one weapon. The GUI code is easier to maintain in a single weapon, and the serverside bits are much easier to maintain. Not only can you not assume that a trigger will reach serverside when using triggerAction on a local NPC, but it's a mess whenever you need to change anything since you have to change the scripts in many levels.

Instead, just trigger a weapon when the item is clicked (see here).

Otherwise, you can keep the same code and still centralize the serverside bit by triggering a database NPC instead of the local NPC. This has huge benefits because you can be sure the trigger will reach serverside. See here.

Quote:

Originally Posted by callimuc (Post 1674092)

No, never send the player's account in a trigger. All you're doing is opening up major vulnerabilities. With your code, I could force any player online to spend their money to purchase any item I wanted them to (assuming your code would work, which it won't).

Emera 11-13-2011 08:40 PM

Quote:

Originally Posted by cbk1994 (Post 1674096)
The problem is that you're triggering serverside like it's a weapon. You can't do that.

Instead, something like

PHP Code:

function onCreated() {
  
this.itemName "whatever";
  
this.itemPrice 123123;
  
  
this.setShape(11616); // so it can be triggered)
}

function 
onActionPurchase() {
  echo(
player.account " wants to purchase this item!");
}

//#CLIENTSIDE
function Shop_Button1.onAction() {
  if (
client.gold client.store1 || client.gold == client.store1) {
    if (!(
hasweapon((@client.realitem)))) {
      
triggerAction(this.xthis.y"purchase"null);
    }
  }



I am using a class. Why are you telling me to assign item details in the class when I will be selling different items at different prices?

ffcmike 11-13-2011 08:49 PM

On a side note I don't believe the function "hasweapon" exists any more, so that condition will always be false even if you do have the weapon.

Emera 11-13-2011 09:03 PM

Quote:

Originally Posted by ffcmike (Post 1674116)
On a side note I don't believe the function "hasweapon" exists any more, so that condition will always be false even if you do have the weapon.

So then would I have to check through the players weapons manually?

ffcmike 11-13-2011 09:05 PM

Quote:

Originally Posted by Emera (Post 1674117)
So then would I have to check through the players weapons manually?

PHP Code:

if(findweapon("name") == NULL){



cbk1994 11-13-2011 09:47 PM

Quote:

Originally Posted by Emera (Post 1674115)
I am using a class. Why are you telling me to assign item details in the class when I will be selling different items at different prices?

The item details should be in the local NPC, not the class. I was basing it off your example. Again, you shouldn't be using that method anyway—see the bottom half of my post.

Tolnaftate2004 11-13-2011 10:33 PM

Quote:

Originally Posted by ffcmike (Post 1674116)
On a side note I don't believe the function "hasweapon" exists any more, so that condition will always be false even if you do have the weapon.

It still exists, but it's expecting a bareword weapon name (because it's a GS1 function).

Emera 11-14-2011 12:11 AM

OK, so the buying of the item and the GUI showing are working. Next roadblock...
When I click an item to buy, the GUI shows and that's all fine. Now if I close that and chooses another item, it shoes the previous items stats. I deleted the "previous" item and now it shows the next item, but adding another will still show the first clicked items details.
http://pastebin.graalcenter.org/read...=0106756446210
Any help?

Also, the buying of the item is all broken now too D:

cbk1994 11-14-2011 12:45 AM

Quote:

Originally Posted by Emera (Post 1674129)
OK, so the buying of the item and the GUI showing are working. Next roadblock...
When I click an item to buy, the GUI shows and that's all fine. Now if I close that and chooses another item, it shoes the previous items stats. I deleted the "previous" item and now it shows the next item, but adding another will still show the first clicked items details.
http://pastebin.graalcenter.org/read...=0106756446210
Any help?

Don't ignore the advice I gave you regarding security; anyone with a memory editor could spawn anything they wanted to. There's no excuse for storing that stuff clientside and sending it serverside.

If you're not interested in becoming a better scripter than these forums aren't for you—try hiring a scripter instead. There are a lot of people who will be willing to help you, but I doubt that will remain true if you disregard what they tell you. If you are interested in becoming a better scripter, as your user title would suggest, then I would recommend you follow advice given to you.

If you want to ignore what I said about centralizing, that's fine—you might not see the benefits of that until you've got more experience—but trusting clientside data is never acceptable, and you should not get into a habit of doing it.

Emera 11-14-2011 12:55 AM

Quote:

Originally Posted by cbk1994 (Post 1674131)
Don't ignore the advice I gave you regarding security; anyone with a memory editor could spawn anything they wanted to. There's no excuse for storing that stuff clientside and sending it serverside.

If you're not interested in becoming a better scripter than these forums aren't for you—try hiring a scripter instead. There are a lot of people who will be willing to help you, but I doubt that will remain true if you disregard what they tell you. If you are interested in becoming a better scripter, as your user title would suggest, then I would recommend you follow advice given to you.

If you want to ignore what I said about centralizing, that's fine—you might not see the benefits of that until you've got more experience—but trusting clientside data is never acceptable, and you should not get into a habit of doing it.

Can I focus on getting the damn script working before worrying about that? It's not even released to players get dammit. I'm not ignoring you. Not everything has to be instantaneous you know. I can change from clientside to serverside in a a few seconds, but until I get the code working, there isn't much point in changing it yet.

fowlplay4 11-14-2011 01:58 AM

Your code that you're showing us doesn't make any sense.

1. You create a GUI somewhere
2. You call setItem somewhere
3. You're using a client flag for gold

If you're creating a GUI in the Shop weapon, add a public function to make the window visible and populate it with the right values instead of using setItem in your level npc.

Weapon: -ShopWindow
http://pastebin.graalcenter.org/read...d=834421076809

Your class:
http://pastebin.graalcenter.org/read...d=040953102775

All I did was put your code in the right places and change a few things that cbk suggested.

xXziroXx 11-14-2011 07:28 AM

Quote:

Originally Posted by Emera (Post 1674132)
Can I focus on getting the damn script working before worrying about that? It's not even released to players get dammit. I'm not ignoring you. Not everything has to be instantaneous you know. I can change from clientside to serverside in a a few seconds, but until I get the code working, there isn't much point in changing it yet.

Why do you always get so worked up when someone questions you? Geez man, take a chill pill. And he's right - do things properly from the start and you might actually learn.

MysticalDragon 11-14-2011 05:58 PM

Quote:

Originally Posted by ffcmike (Post 1674119)
PHP Code:

if(findweapon("name") == NULL){



more of an efficient way i feel would be,
PHP Code:

 if (player.hasWeapon("")) 

since GS1 is redundant really.

ffcmike 11-14-2011 06:45 PM

Quote:

Originally Posted by MysticalDragon (Post 1674191)
more of an efficient way i feel would be,
PHP Code:

 if (player.hasWeapon("")) 

since GS1 is redundant really.

My point was more on the lines that "hasweapon" is deprecated, a relic of the function does still exist somewhere but it always returns false, it is also not a player. function.


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

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