Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   serverside triggeraction in class placed with putnpc2 (https://forums.graalonline.com/forums/showthread.php?t=62796)

prozac424242 12-15-2005 07:16 PM

serverside triggeraction in class placed with putnpc2
 
Here is my situation:
A weapon places a class with putnpc2.
The same weapon also does a triggeraction which the class npc recieves clientside with paramaters. That works.

What does not work is when the action is detected clientside in the class, the class npc is supposed to do a triggeraction serverside on itself, becasue the addweapon command has to be done serverside. Why does the putnpc2 class not do a triggeraction on itself, but this same code works in a weapon?

actiondrop gets called succesfully, but the serverside part in the class here does not get called at all. #p(1) in the actiondrop is the weapon name passed from the weapon. The class is called weaponpickup

PHP Code:

if (actionserverside)
{
addweapon #p(0);
destroy;
}

//#CLIENTSIDE
if (actiondrop)
{
//code not reated to my problem removed - this part works
}

if (
playertouchsme)  
{
triggeraction 0,0,serverside,weaponpickup,#p(1); //also tried doing it on x and y


Any help would be greatly appreciated.

Rick 12-15-2005 07:32 PM

Because it's not a weapon. You have to triggeraction the x/y of the NPC.

Why not just check for playertouchsme on serverside?

prozac424242 12-15-2005 07:53 PM

triggeraction on the x and y did not work. the triggeraction does not happen at all with actionserverside.

Even something as simple as this does not work in a putnpc2 class npc
PHP Code:

if (actionserverside)
{
message i say #p(0);
}

//#CLIENTSIDE
if (playertouchsme)
{
triggeraction x,y,serverside,hi there;


playertouchsme done serveride does not carry over the variable that was set clientside. (#p(1) from the actiondrop)

Skyld 12-15-2005 07:56 PM

You will probably need to give the NPC a shape (setshape on the serverside), and triggeraction onto that surface.

Also, I would add some additional security to that addweapon, such as a clientr.flag check, or even specifying the weapon name on the serverside instead of #p(n).

prozac424242 12-15-2005 08:13 PM

I actually did try using a setshape when the npc is created, and doing a triggeraction on the x and y.
But no matter what I do, the big problem is that any variable set clientside is not carried over to the serverside part of the script, be it in playertouchsme or a triggeraction.

ApothiX 12-15-2005 09:13 PM

What exactly is happening? Is it triggering the action and not getting the parameters, or not triggering at all?

If it's not triggering at all, you might want to try to use x+1.5, y+1.5 to make sure it hits on an actual pixel, and not a transparent part. (I'm not sure if this still applies, but I use it anyway :P)

[EDIT]
You should also try using a different event name, such as 'pickup' and do:
if(actionpickup) {
instead of:
if(actionserverside) {

Lance 12-16-2005 12:36 AM

That is not only horribly insecure but horribly inefficient as well. Instead of trying to circumvent the "No, you can't add any weapon you want clientside" security, you should try to do it right.

Perhaps instead you should use the standard put-the-npc-then-use-with-and-set-the-flag method. This is even easier in GS2.

gs1 example:
NPC Code:
setstring this.fruit,strawberry;
putnpc2 somex,somey,{ join fruits; };
with(npcs[npcscount-1]) {
setstring this.img,#s(thiso.fruit).png;
}



this.img in the placed NPC will be strawberry.png :)

Other than that, you were using a reserved action name (actionserverside is reserved for weapon npcs, actionserver[anythingelse] is reserved for control-npc). Please take the secure approach, though. Explicitly specify the weapon name, don't trust the client.

Rick 12-16-2005 12:38 AM

Quote:

Originally Posted by prozac424242
But no matter what I do, the big problem is that any variable set clientside is not carried over to the serverside part of the script, be it in playertouchsme or a triggeraction.

That'd be like, totally insecure, maaaan.

prozac424242 12-16-2005 07:14 AM

hmm

aparently my "problem" with coming up with this script idea is that I do not expect the worst from people right off the bat ... as many who post here apparently do. forget it then. thanks for the help but im not going to use code that, even when explained to me, I don't understand how it works (the code Lance posted) I just can't wrap my mind around through where the npcscount and that count-1 can be a constant referal point but to different putnpc2 class items that are separate from the npc which is controlled by the player performing the putnpc2 action.

[moves on to something that might actually be usefull]

Lance 12-16-2005 08:02 AM

Quote:

Originally Posted by prozac424242
hmm

aparently my "problem" with coming up with this script idea is that I do not expect the worst from people right off the bat ... as many who post here apparently do. forget it then. thanks for the help but im not going to use code that, even when explained to me, I don't understand how it works (the code Lance posted) I just can't wrap my mind around through where the npcscount and that count-1 can be a constant referal point but to different putnpc2 class items that are separate from the npc which is controlled by the player performing the putnpc2 action.

[moves on to something that might actually be usefull]

If you just add an NPC with putnpc, it will have the highest index in the npcs array. If you immediately access that NPC, you can set flags.

Rick 12-16-2005 08:48 AM

Quote:

Originally Posted by prozac424242
I just can't wrap my mind around through where the npcscount and that count-1 can be a constant referal point but to different putnpc2 class items that are separate from the npc which is controlled by the player performing the putnpc2 action.

[moves on to something that might actually be usefull]

The reason for this is because the NPC server is not threaded. It may seem like that, but it really isn't.

HOWEVER:

With GScript2 you have a new alternative, this will probably be easier to understand:

HTML Code:

this.fruit = "strawberry";
temp.npc = this.level.putNPC2(somex, somey, "join fruits;");
temp.npc.img = this.fruit @ ".png";

OR:

HTML Code:

this.fruit = "strawberry";

with (this.level.putNPC2(somex, somey, "join fruits;"))
{
  this.img = thiso.fruit @ ".png";
}


ApothiX 12-16-2005 08:07 PM

Quote:

Originally Posted by prozac424242
[moves on to something that might actually be usefull]

I think learning how to interact with NPCs is quite a useful thing o_o


All times are GMT +2. The time now is 09:11 PM.

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