Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Item Creation Script (https://forums.graalonline.com/forums/showthread.php?t=134263372)

Astram 05-28-2011 02:57 PM

Item Creation Script
 
This is a little script ive been working on, not much... Also, not completed yet so expect updates but this system allows you to create weapons to fight with people! It works with melee atm.
But you will have to script the hurting etc.
Here ya go

Weapon Creation Code:
PHP Code:

function onActionServerSide()
  {
  if (
params[0] == "Generate")
    {
    echo(
"[ITEM GENERATOR]: "@params[5]@" Created "@params[1]@" Which Does "@params[2]@" Damage, Gani = "@params[3]@"!");
    
findplayer(params[5]).clientr.weps.add(params[1]);
    
savelog2("logs/Items",params[5]@" Created "@params[1]@" That does "@params[2]@" Damage, with the Gani "@params[3]@" and a freeze of "@params[4]@"!");
    
ItemDB.GenerateItem(params[1], params[2], params[3], params[4], params[5]);
    }
  }
//#CLIENTSIDE
function onPlayerChats()
  {
  if (
player.chat == "/items")
    {
    
openGenerator();
    
player.chat "";
    }
  }
function 
openGenerator() {
  new 
GuiWindowCtrl("Generator_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,130";

    
canmove true;
    
canresize false;
    
closequery false;
    
canmaximize false;
    
canminimize false;
    
destroyonhide false;
    
text "Item Generator";
    
mousescreenx;
    
mousescreeny;

    new 
GuiTextEditCtrl("Generator_TextEdit1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
18;
      
19;
    }
    new 
GuiTextCtrl("Generator_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Name";
      
width 27;
      
42;
      
35;
    }
    new 
GuiTextEditCtrl("Generator_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
115;
      
19;
    }
    new 
GuiTextCtrl("Generator_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Damage";
      
width 39;
      
135;
      
34;
    }
    new 
GuiTextEditCtrl("Generator_TextEdit3") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
216;
      
20;
    }
    new 
GuiTextEditCtrl("Generator_TextEdit4") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 80;
      
19;
      
55;
    }
    new 
GuiTextCtrl("Generator_Text4") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Freeze Time";
      
width 100;
      
28;
      
75;
    }
    new 
GuiTextCtrl("Generator_Text3") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Gani (without .gani)";
      
width 100;
      
210;
      
35;
    }
    new 
GuiButtonCtrl("Generator_Button1") {
      
profile GuiBlueButtonProfile;
      
height 34;
      
text "Generate Weapon";
      
width 320;
      
96;
    }
    
Generator_Window1.show();
  }
}

function 
Generator_Button1.onAction() {
  
temp.w_name Generator_TextEdit1.getText();
  
temp.dmg Generator_TextEdit2.getText();
  
temp.gani Generator_TextEdit3.getText();
  
temp.freeze Generator_TextEdit4.getText();
  
triggerserver("gui",this.name,"Generate",temp.w_name,temp.dmg,temp.gani,temp.freeze,player.account);
  
Generator_Window1.hide();
  
player.chat "Generated "@temp.w_name@"!";


Weapon Inventory:
PHP Code:

join("object_inventory");
function 
onActionServerSide()
  {
  if (
params[0] == "Equip")
    {
    
clientr.equipped params[1];
    }
  if (
params[0] == "getStats")
    {
    
temp.freeze ItemDB.("Item_"@params[1]@"_Freeze");
    
temp.ani ItemDB.("Item_"@params[1]@"_Gani");
    
temp.damage ItemDB.("Item_"@params[1]@"_Damage");
    
triggerclient("gui",this.name,"getStats",temp.ani,temp.damage,temp.freeze);
    }
  }
//#CLIENTSIDE
function onCreated()
  {
  
setTimer(.0051);
  }
function 
onTimeOut(timeid)
  {
    
selectedweapon NULL;
    
setTimer(.005);
    
player.chat "Time: "@params[0]@" ID: "@id;
  }
function 
onKeyPressed(codekeyscancode)
  {
  if (
key == "q")
    {
    if (
this.open == false)
      {
      
temp.wep getItems();
      
onOpenInv(temp.wep);
      
Inventory_Window.show();
      
this.open true;
      }
    else
      {
      
this.open false;
      
Inventory_Window.hide();
      }
    }
  if (
key == "d")
    {
      if (
findweapon("Test"))
        {
        
player.chat "!!! WEAPONS WORK !!!";
        
player.clientr.equipped.trigger"onWeaponFired""" );
        }
      else
        {
    
triggerserver("gui",this.name,"getStats",clientr.equipped);
    
temp.ani ItemDB.("Item_"@item@"_Gani");
    
setAni(this.gani,NULL);
    
UseItem(clientr.equipped);
    
triggeraction(player.1.5 vecx(player.dir) * 2player.vecy(player.dir) * 2"melee",player.account,this.dmg);
    
freezeplayer(this.freeze);
    }
  }
}
function 
onOpenInv(items) {
  new 
GuiWindowCtrl("Inventory_Window") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,300";

    
canmove true;
    
canresize false;
    
canclose false;
    
canminimize false;
    
canmaximize false;
    
closequery false;
    
destroyonhide false;
    
text "Inventory";
    
509;
    
203;

    new 
GuiButtonCtrl("Inventory_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Close";
      
width 320;
      
270;
    }
    new 
GuiButtonCtrl("Inventory_Button2") {
      
profile GuiBlueButtonProfile;
      
height 31;
      
text "Equip Item";
      
width 320;
      
209;
    }
    new 
GuiButtonCtrl("Inventory_Button3") {
      
profile GuiBlueButtonProfile;
      
text "Drop Item";
      
width 320;
      
240;
    }
       new 
GuiScrollCtrl("Inventory_TextList_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 155;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 320;
      
0;
      
0;

      new 
GuiTextListCtrl("Inventory_TextList") {
        
profile GuiBlueTextListProfile;
        
height 135;
        
horizsizing "width";
        
width 295;
        
clearrows();
        for (
temp.0temp.clientr.weps.size(); temp.++)
          {
          
addrow(temp.iclientr.weps[(@temp.i)]);
          }
        for (
temp.0temp.player.weapons.size(); temp.++)
          {
          if (!(
player.weapons[(@temp.e)].name.starts("-")))
            {
            
addrow(temp.temp.eplayer.weapons[(@temp.e)].name);
            }
          }
      }
    }
    
Inventory_Window.show();
  }
}

function 
getItems()
  {
  for (
clientr.weps temp.weps)
    {
    return 
temp.weps;
    }
  }
function 
Inventory_Button1.onAction() {
  
// Button "Close" has been pressed
}

function 
Inventory_Button2.onAction() {
temp.item Inventory_TextList.getSelectedText();
  
triggerserver("gui",this.name,"Equip",temp.item);
  }

function 
Inventory_Button3.onAction() {
  
// Button "Drop Item" has been pressed
}
function 
onActionClientSide()
  {
  if (
params[0] == "getStats")
    {
    
this.gani params[1];
    
this.dmg params[2];
    
this.freeze params[3];
    }
  } 

Class object_inventory:
PHP Code:

public function UseItem(item)
  {
    
temp.gani ItemDB.("Item_"@item@"_Gani");
    
setAni(temp.gani,NULL);
    
temp.dmg ItemDB.("Item_"@item@"_Damage");
    
triggeraction(player.1.5 vecx(player.dir) * 2player.vecy(player.dir) * 2"melee",player.account,item,temp.dmg);
  } 

HAVE FUN!!!
O, Say /items to open the generator =D!

Twaina 05-28-2011 03:51 PM

good job

callimuc 05-28-2011 03:51 PM

I canīt test it but:
PHP Code:

function Inventory_Button1.onAction() { 
  
// Button "Close" has been pressed 
}
//more stuff

function Inventory_Button3.onAction() { 
  
// Button "Drop Item" has been pressed 


Quote:

Originally Posted by Astram (Post 1651837)
not completed yet so expect updates

At least complete the "important" stuff or donīt you want it to be closed or dropped even if you added the buttons....

Twaina 05-28-2011 03:56 PM

screens?

PowerProNL 05-28-2011 04:41 PM

Please, if you release on Code Gallery, finish the script ATLEAST


but yea I like it, keep on working :)

xAndrewx 05-28-2011 06:45 PM

cool stuff @ Astram- you're getting better :)

Quote:

Originally Posted by Astram (Post 1651837)
Also, not completed yet so expect updates but this system allows you to create weapons to fight with people! It works with melee atm.
But you will have to script the hurting etc.

I'll make it bold for the people that replied above

fowlplay4 05-28-2011 07:32 PM

Your code styling is inconsistent and looks terrible. Please do the following:

Quote:

Originally Posted by fowlplay4 (Post 1650248)
How to style your script properly with jsbeautifer.org

Copy-paste your code into the code text area.



Settings:
- Indent with 2 spaces
- Braces with control statement
- Un-check all Checkboxes

Click 'Beautify'

Things that caught my eye:

setTimer(.005, 1); - setTimer(float): The minimum value is 0.05, and it's only one parameter. Use this.scheduleevent() if you need to pass parameters to the looping event.

PHP Code:

function getItems() 
  { 
  for (
clientr.weps temp.weps
    { 
    return 
temp.weps// only returns the first weapon.
    

  } 

I would guess you were aiming to do the following:

PHP Code:

function getItems() {
  return 
clientr.weps// returns an array of weapons.


You also have numerous amounts of active debugging code, and other logic errors. Like the fact you're sending multiple triggers in one block of code for next to no reason, and calling useItem where it doesn't exist and attempting to access the DB on the client-side.

Quote:

Originally Posted by xAndrewx (Post 1651884)
I'll make it bold for the people that replied above

That doesn't make it okay.

The code gallery shouldn't become a repository of poorly written broken scripts. Code reviews can take place outside the forums without issue but to me this sub-forum should be for proper working scripts which developers can take, use, and learn from without issue.

cbk1994 05-28-2011 08:51 PM

Quote:

Originally Posted by Emera (Post 1651897)
Perhaps a little support? Not all of us take your crap kindly. I think its really good astram. +rep

Jer is one of the people on this forum who is constantly giving scripting advice. His "crap" includes a fairly complete introductory guide, numerous specific guides, and tons of helpful posts.

The Code Gallery should be reserved for high-quality scripts. There is a forum where he can post scripts that are incomplete to get feedback on.

My reply to another of Astram's code gallery threads:

Quote:

Originally Posted by cbk1994 (Post 1650150)
Please don't release scripts like this into the code gallery. I really do appreciate your effort and that you're trying to help others, but releasing broken model scripts isn't the way to do it.

A couple things to work on:
  • Your styling is very inconsistent. This is the most crucial issue with your script.
  • The minimum clientside timeout is 0.05 seconds, not 0.0005 seconds.
  • You don't need to check for q and Q. String comparison is not case-sensitive.
  • Try to use meaningful object names rather than _Button1.
  • I would recommend using clientWidth and clientHeight instead of clientExtent.
  • Generally use foreach loops when looping through arrays like you did for displaying weapons.

Again, thanks for trying to help :). Let me know if anything I said doesn't make sense.

Clearly all that support worked pretty well since he ignored almost every point I made.

Once again, Astram, thanks for trying to help. I'm glad that new scripters have an interest in improving the learning resources available for GScript. This script shows that you are making good progress toward learning GScript.

However, posting scripts like this one in the Code Gallery does more damage than it does good. I've recommended this before and I'll recommend it again. Post your scripts in the scripting forum first so an experienced scripter can help you polish it, then post the final version in the Code Gallery.

fowlplay4 05-28-2011 08:58 PM

Quote:

Originally Posted by Emera (Post 1651897)
Perhaps a little support? Not all of us take your crap kindly. I think its really good astram. +rep

He's getting plenty of other "support" from people like you who don't know any better and with my post he's getting the much needed "criticism" that goes a long with it.

Do I really have to post "Okay, looks like you're getting a little better but..." before everything for it not be to considered negative and unhelpful?

cbk1994 05-28-2011 08:58 PM

Quote:

Originally Posted by Emera (Post 1651904)
Yeah, that sounds like support...

Perhaps it should be "wow astram your getting much better! Just a few things though, you need to work on your styling a little bit"

It's straightforward and to the point. If he's looking for someone to tell him what a great job he's doing, maybe he should arrange something with his mother.

salesman 05-28-2011 09:12 PM

In my opinion, code that is posted in the code gallery should either
  1. be something that someone else can learn from, or
  2. be something that someone else can use

Your code is neither because you don't provide any explanation of what's going on (a comment here and there wouldn't hurt!), it's terribly styled, and it's incomplete.

Like Chris said, I appreciate that you're trying to help, but unless your goal was to show us what not to do, then this does not belong in the code gallery.

Unkownsoldier 05-29-2011 02:40 PM

Quote:

Originally Posted by Emera (Post 1651904)
Yeah, that sounds like support...

Perhaps it should be "wow astram your getting much better! Just a few things though, you need to work on your styling a little bit"

You seriously need to stop thinking that the world is a kind, warm-hearted place. People aren't going to be nice to you everywhere you go, they aren't going to be your friend, and they aren't going to like you. Get over it. People are going to insult you, they are going to deny you rights you think you should have, and that will continue to happen until you prove yourself. so stfu

MattKan 05-29-2011 03:25 PM

Quote:

Originally Posted by Unkownsoldier (Post 1651991)
You seriously need to stop thinking that the world is a kind, warm-hearted place. People aren't going to be nice to you everywhere you go, they aren't going to be your friend, and they aren't going to like you. Get over it. People are going to insult you, they are going to deny you rights you think you should have, and that will continue to happen until you prove yourself. so stfu

Alas, your forums title is I am Frank.......:)

Astram 05-30-2011 02:34 PM

I will take your suggestions and critisizism as I post my next script.
And @ Fowlplayer4 setTimer(.005); works and the 1 was this little test. Would be nice if it let me edit my own post. Though it doesnt for some reason...

fowlplay4 05-30-2011 03:16 PM

Quote:

Originally Posted by Astram (Post 1652169)
Fowlplayer4 setTimer(.005); works and the 1 was this little test. Would be nice if it let me edit my own post. Though it doesnt for some reason...

It may "work" but it's not right. The minimum timeout is still one frame (0.05 seconds). Attempting to loop any faster is pointless.


All times are GMT +2. The time now is 12:52 AM.

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