Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-28-2011, 02:57 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
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!
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 05-28-2011, 03:51 PM
Twaina Twaina is offline
Registered User
Join Date: Dec 2010
Posts: 59
Twaina has a little shameless behaviour in the past
good job
Reply With Quote
  #3  
Old 05-28-2011, 03:51 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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 View Post
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....
__________________
MEEP!
Reply With Quote
  #4  
Old 05-28-2011, 03:56 PM
Twaina Twaina is offline
Registered User
Join Date: Dec 2010
Posts: 59
Twaina has a little shameless behaviour in the past
screens?
Reply With Quote
  #5  
Old 05-28-2011, 04:41 PM
PowerProNL PowerProNL is offline
Retired Zone Manager
PowerProNL's Avatar
Join Date: Feb 2008
Location: Holland
Posts: 266
PowerProNL can only hope to improve
Send a message via AIM to PowerProNL
Please, if you release on Code Gallery, finish the script ATLEAST


but yea I like it, keep on working
__________________
Graal Mail: [email protected]
McPowerProNL, I'm loving it
Reply With Quote
  #6  
Old 05-28-2011, 06:45 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
cool stuff @ Astram- you're getting better

Quote:
Originally Posted by Astram View Post
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
__________________
Reply With Quote
  #7  
Old 05-28-2011, 07:32 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Your code styling is inconsistent and looks terrible. Please do the following:

Quote:
Originally Posted by fowlplay4 View Post
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 View Post
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.
__________________
Quote:
Reply With Quote
  #8  
Old 05-28-2011, 08:51 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Emera View Post
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 View Post
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.
__________________

Last edited by cbk1994; 05-28-2011 at 10:20 PM.. Reason: spellin
Reply With Quote
  #9  
Old 05-28-2011, 08:58 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
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?
__________________
Quote:

Last edited by fowlplay4; 05-28-2011 at 10:09 PM.. Reason: engrish
Reply With Quote
  #10  
Old 05-28-2011, 08:58 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Emera View Post
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.
__________________
Reply With Quote
  #11  
Old 05-28-2011, 09:12 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
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.
__________________
Reply With Quote
  #12  
Old 05-29-2011, 02:40 PM
Unkownsoldier Unkownsoldier is offline
Ignorance has no future
Join Date: Sep 2008
Posts: 1,287
Unkownsoldier is on a distinguished road
Quote:
Originally Posted by Emera View Post
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
__________________
Look beyond the monitor.
Reply With Quote
  #13  
Old 05-29-2011, 03:25 PM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan
Quote:
Originally Posted by Unkownsoldier View Post
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.......
__________________
Quote:
Originally Posted by Satoru Iwata
On the other hand, free-to-play games, if unbalanced, could result in some consumers paying extremely large amounts of money, and we can certainly not expect to build a good relationship with our consumers in this fashion. In order to have a favorable long-term relationship, we would like to offer free-to-play games that are balanced and reasonable.
Quote:
Originally Posted by Unximad
Eurocenter Games remains attached to the values of indies game developer and to the service our playerbase community.
Reply With Quote
  #14  
Old 05-30-2011, 02:34 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
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...
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #15  
Old 05-30-2011, 03:16 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
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.
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:31 AM.


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