Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   please help me with this gun script (https://forums.graalonline.com/forums/showthread.php?t=84343)

GULTHEX 02-21-2009 11:53 PM

please help me with this gun script
 
PHP Code:

//#CLIENTSIDE
//up
if (playerdir=0){
  
this.x=playerx-1;
  
this.y=playery-2;
}
//left
if (playerdir=1){
  
this.x=playerx-2;
  
this.y=playery;
}
//down
if (playerdir=2){
  
this.x=playerx+1;
  
this.y=playery+2;
}
//right
if (playerdir=3){
  
this.x=playerx+2;
  
this.y=playery;
}
if (
playerenters) {
  
toweapons Test;
}
if (
weaponfired){
  
setshootparams PARAMEQUALS;
  
//shoot x,y,z,angle,zangle,power,gani,ganiparams;
  
shoot this.x,this.y,playerz,(playerdir 1) * pi 2,,,dg_bullet,;
  
setani dg_m16-fire,;
  
replaceani idle,dg_m16-idle;
  
replaceani walk,walk;
  
freezeplayer 0.0383;
  
sleep 0.1;
}

if (
actionprojectile) {
  if(
strequals(#p(index),PARAMEQUALS)) {
    
setani hurt,;
    
clientr.hp -= 20;   
  }
  } 

kk the prob is that when the bullet hits people it does damage with hearts it dont minus the hp idk what the prob is it dont even say hearts in the script lol



so whats the prob

and dont nag me about the paremequals it still works

RozenMaiden 02-22-2009 04:51 PM

So thats essentially the same thread as before just with "dont nag me about paramequals" added? o.รด

Chompy 02-22-2009 05:03 PM

clientr.hp must be decreased serverside.

GULTHEX 02-22-2009 08:27 PM

so how would i do that


would i do that with a class???

[email protected] 07-31-2009 01:31 PM

This kid asked for help on a script, not how he would get some help. sheesh

Gulthex since this is my gun script, I am quite pissed, however I will show you a simple way of making it serversided.

put this at the top of the script!
PHP Code:

function onActionServerSidecmd )
{
  switch( 
cmd )
  {
    case 
"hp":
    {
clientr.hp -= 10;    //PUT WATEVER YOU WANT IT TO -
  
}
 }


Then put this at the bottom where you currently have the actionprojectile:
PHP Code:

if (actionprojectile
{
  if(
strequals(#p(index),PARAMEQUALS)) 

triggerserver("weapon"this.name"hp");   //TRIGGERS SCRIPT AT TOP
 
}


Also heres a little tip for you. after you script a script, go to rc and type :

If it's a weapon script:
PHP Code:

/style weapon WEAPON NAME 

if it's a NPC script:
PHP Code:

/style npc NPCNAME 

if it's a class:
PHP Code:

/style class CLASSNAME 

I hope this helped ;D

cbk1994 07-31-2009 01:48 PM

Quote:

Originally Posted by [email protected] (Post 1511837)
Then put this at the bottom where you currently have the actionprojectile:
PHP Code:

if (actionprojectile
{
  if(
strequals(#p(index),PARAMEQUALS)) 

triggerserver("weapon"this.name"hp");   //TRIGGERS SCRIPT AT TOP
 
}



You shouldn't be mixing GS1 and GS2 like that.

PHP Code:

function onActionProjectile(param) {
  if (
param == "gun") { // or "PARAMEQUALS", lol...
    
triggerserver("gui"name"hp");
  }


Quote:

Originally Posted by [email protected] (Post 1511837)
Also heres a little tip for you. after you script a script, go to rc and type :
[...]

You really should get into the habit of just pressing tab as you script. RC keeps your indentation for a reason. You'll find it's well worth it once you're used to scripting properly.

DustyPorViva 07-31-2009 01:59 PM

Shouldn't it be params[0]?

cbk1994 07-31-2009 02:00 PM

Quote:

Originally Posted by DustyPorViva (Post 1511851)
Shouldn't it be params[0]?

Normally, but I did this:

Quote:

Originally Posted by cbk1994 (Post 1511846)
PHP Code:

function onActionProjectile(param) { 


declaring the first parameter to be placed in the variable 'temp.param'.

DustyPorViva 07-31-2009 02:03 PM

Oh, hadn't noticed that :P ... that's very misleading though, and not something I'd suggest for readability and all.

cbk1994 07-31-2009 02:09 PM

Quote:

Originally Posted by DustyPorViva (Post 1511856)
Oh, hadn't noticed that :P ... that's very misleading though, and not something I'd suggest for readability and all.

As a general rule, the first projectile param should be the type of projectile. It'd probably be better to use something like projType (which would be, for example, gun, grenade, etc).

[email protected] 07-31-2009 03:36 PM

Well mine would work so....

DustyPorViva 07-31-2009 03:42 PM

Quote:

Originally Posted by [email protected] (Post 1511884)
Well mine would work so....

Just because it works doesn't mean it's the best way. As a scripter you need to always look for better alternatives and to be more efficient. There are tons of ways to achieve a desired outcome with scripts, and just because they can all achieve what you want doesn't mean it's the right way to go about it. Mixing GS1 and GS2 is not only a bad exercise for the scripter, it's also bad for those reading and trying to learn from the script.

This is no cut on you or anything, but more like advice.


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

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