Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   onActionServerside (https://forums.graalonline.com/forums/showthread.php?t=59627)

KuJi 06-25-2005 07:52 PM

onActionServerside
 
NPC Code:

function onActionServerside(command, arg) {
switch(params[0]) {
case "stats":
// player.chat = "boo";
switch (params[1]) {
case "hurt":
dmg = params[2];
hp = clientr.health[0];
clientr.health[0] = hp - dmg;
break;
}
break;
}
}



The script only works when the player.chat command is uncommented.

Anyway to fix this / is their a different way for triggeractions in GS2?

Skyld 06-25-2005 09:28 PM

Firstly, I'm not sure if you can use a switch immediately after a case.
Second, you've given the function two argument variables; why are you using params?

Velox Cruentus 06-25-2005 09:29 PM

Ew @ double switch case.

KuJi 06-25-2005 09:35 PM

*Points the finger at Loriel*

So, how is this fixable?

Python523 06-25-2005 09:50 PM

seems to not like going right from a case to another switch... a bug is my guess

KuJi 06-25-2005 09:58 PM

Then is their anyway I can do it as how I am trying to?

I am trying to make it do like this:

if (strequals(#p(0),stats)) {
if (strequals(#p(1),hurt)) // Hurt
}

How would I do something like that in gscript2 then?

Fry 06-26-2005 12:30 AM

if (foo == bar)
foo and bar are variables. to see whether foo equals "test" (the string), do
if (foo == "test")
like you'd compare integers in GS1, just put quotes around strings.

Python523 06-26-2005 12:38 AM

Quote:

Originally Posted by KuJi
Then is their anyway I can do it as how I am trying to?

I am trying to make it do like this:

if (strequals(#p(0),stats)) {
if (strequals(#p(1),hurt)) // Hurt
}

How would I do something like that in gscript2 then?

NPC Code:

function onActionServerside() {
if (params[1] == "stats") {
if (params[2] == "hurt") {
//stuff
} else if (params[2] == "stuff") {
}
} else if (params[1] == "stuff") {
}
}


KuJi 06-26-2005 12:45 AM

Hmm, that would work..but what is switch for then?

Python523 06-26-2005 01:04 AM

Quote:

Originally Posted by KuJi
Hmm, that would work..but what is switch for then?

not like switch is a graal-unique thing.. other langs have it, its purpose is to make things like more organized, also you can do something like

NPC Code:

case 1:
case 2:
case 3:
player.chat = "foo";
break;


while the elseif form of that would be much longer

KuJi 06-26-2005 03:13 AM

So it is some sort of replacement of else?

EX:
if (playerchats) {
if (strequals(#c,boo)) setplayerprop#c,boo; else
if (strequals(#c,bam)) setplayerprop#c,bam; else
if (strequals(#c,woo)) setplayerprop#c,woo;
}

Evil_Trunks 06-26-2005 05:23 AM

Quote:

Originally Posted by KuJi
So it is some sort of replacement of else?

EX:
if (playerchats) {
if (strequals(#c,boo)) setplayerprop#c,boo; else
if (strequals(#c,bam)) setplayerprop#c,bam; else
if (strequals(#c,woo)) setplayerprop#c,woo;
}

yes

Python523 06-26-2005 09:35 AM

Quote:

Originally Posted by KuJi
So it is some sort of replacement of else?

EX:
if (playerchats) {
if (strequals(#c,boo)) setplayerprop#c,boo; else
if (strequals(#c,bam)) setplayerprop#c,bam; else
if (strequals(#c,woo)) setplayerprop#c,woo;
}

This is why you learn how to code and not just memorize how things work...

KuJi 06-26-2005 05:10 PM

Err O.o?

ZeroTrack 06-28-2005 03:19 PM

Quote:

Originally Posted by KuJi
So it is some sort of replacement of else?

EX:
if (playerchats) {
if (strequals(#c,boo)) setplayerprop#c,boo; else
if (strequals(#c,bam)) setplayerprop#c,bam; else
if (strequals(#c,woo)) setplayerprop#c,woo;
}

Like so =D

PHP Code:

#//CLIENTSIDE
function onPlayerchats(){
  
test player.chat;
  switch (
test) {
    case 
"boo":
      
player.chat "Test 1";
      break;
    case 
"bam":
      
player.chat "Test 2";
      break;
    case 
"woo":
      
player.chat "Test 3";
      break;
  }


:cool: hope it helps

Inverness 06-30-2005 10:02 PM

Why set test?
And not use switch (player.chat)
???


All times are GMT +2. The time now is 06:20 PM.

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