Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How to handle custom swords (https://forums.graalonline.com/forums/showthread.php?t=134261797)

AlexanderK 01-21-2011 11:57 PM

How to handle custom swords
 
The thread title says it all.

I'm nearly done with my custom Item system and Inventory, but I'm still not sure how to handle custom swords.

I was thinking that I could maybe add a weapon to the player, that is called like the sword with a "-" in front of it , eg "-Sword of Doom" :D, and that has a script that reacts to the Button S, and take that weapon away when another sword is equipped.

But that seems awfully complicated. I'm sure you guys have probably thought of a much better way to do it. So which way should I do it?

DrakilorP2P 01-22-2011 12:09 AM

Use one weapon script that handles all possible swords I guess? I'm not sure I understand the question.

Soala 01-22-2011 01:08 AM

Like Maui said, you'd be better off using a single wNPC to handle the said equiping/inventory system, and have a database NPC to store/use all informations about each sword.
Using a wNPC for each sword is way too messy imo.

You could have custom variables with of course a sword attribute in your ganis. With a well organized template, manipulating the weapon's img using the weapon's name is much better, which is what most servers do. The rest should be a piece of cake next :)

cbk1994 01-22-2011 01:18 AM

My suggestion:

One database NPC named, say, Swords, formatted like so:

PHP Code:

function onInitialized() {
  
this.trigger("created"); // re-add values on start incase they were removed
}

function 
onCreated() {
  
this.sword.clearVars(); // empty variables so strays aren't left over to cause problems
  
  // Super Sword
  
this.sword.supersword.swordName "Super Sword";
  
this.sword.supersword.attackSpeed 0.2;
  
this.sword.supersword.damage 20;
  
  
// ****ty Sword
  
this.sword.****tysword.swordName "****ty Sword";
  
this.sword.****tysword.attackSpeed 1.2;
  
this.sword.****tysword.damage 1;
}

public function 
getSword(swordID) {
  return 
this.sword.(@ swordID).link();


then have a single weapon, named something like -Swords, that controls equipping of swords (have the inventory trigger it when the player equips a new sword)

PHP Code:

function onSwordEquipped(swordID) {
  
temp.sword Swords.getSword(swordID);
  
  
player.clientr.sword.swordName sword.swordName;
  
player.clientr.sword.attackSpeed sword.attackSpeed;
  
// etc..


Then in the clientside of -Swords you can read from the clientr variables.

(anyone ever realize what a weird word "sword" is?)

Fulg0reSama 01-22-2011 01:26 AM

Quote:

Originally Posted by cbk1994 (Post 1624712)
(anyone ever realize what a weird word "sword" is?)

Yes :megaeek:.

It's better than Sharp Metal Stick.

AlexanderK 01-22-2011 06:24 PM

Thanks cbk1994! I'll do it that way when I get to it.
Right now I'm doing the HUD first.
http://img28.imageshack.us/img28/787...1295713158.png
Man, I forgot how much fun Graal coul be!

fowlplay4 01-22-2011 06:33 PM

Your char seems really out of place with the rest of your graphics.

AlexanderK 01-22-2011 06:45 PM

Quote:

Originally Posted by fowlplay4 (Post 1624865)
Your char seems really out of place with the rest of your graphics.

And there goes the fun! ;)
You know, I don't care. I'm doing this for me, for fun. Because I always loved Graal (Graal 1.4 got me hooked, when there was offline multiplayer for up to 4 players, I would always make fun levels for me and my friends to play on with gamepads). I don't hire anyone, I don't hog this forum with posts about my server. It will probably never be a full-on playable server, but that's not what I'm aiming for. The way is the goal. The 50€ for 6 months Developers Gold are well spent, if you think about how short games that cost 10€ more are nowadays and the amount of time you can have with playing around on your server.

Maybe I could make custom bodies, but that's a pain in the ass. :D

fowlplay4 01-22-2011 07:08 PM

Quote:

Originally Posted by AlexanderK (Post 1624866)
And there goes the fun! ;)
You know, I don't care. I'm doing this for me, for fun. Because I always loved Graal (Graal 1.4 got me hooked, when there was offline multiplayer for up to 4 players, I would always make fun levels for me and my friends to play on with gamepads). I don't hire anyone, I don't hog this forum with posts about my server. It will probably never be a full-on playable server, but that's not what I'm aiming for. The way is the goal. The 50€ for 6 months Developers Gold are well spent, if you think about how short games that cost 10€ more are nowadays and the amount of time you can have with playing around on your server.

Maybe I could make custom bodies, but that's a pain in the ass. :D

js, could use some black lines or sprites to fit geez.

AlexanderK 01-22-2011 07:26 PM

Quote:

Originally Posted by fowlplay4 (Post 1624869)
js, could use some black lines or sprites to fit geez.

I'm sorry if you're offended by my post, I kind of overreacted. :)

But the other day I have been reading a few threads in this forum, and don't get me wrong, the scripting community is great and has been very helpful to me, but the attitude of some people in this forum is horrible. A lot of newbies get ridiculed, there is a lot of nagging, and people who rent servers are frowned upon because why would you rent a server? My post above is why.

xXziroXx 01-22-2011 07:36 PM

Quote:

Originally Posted by AlexanderK (Post 1624871)
I'm sorry if you're offended by my post, I kind of overreacted. :)

But the other day I have been reading a few threads in this forum, and don't get me wrong, the scripting community is great and has been very helpful to me, but the attitude of some people in this forum is horrible. A lot of newbies get ridiculed, there is a lot of nagging, and people who rent servers are frowned upon because why would you rent a server? My post above is why.

We only ridicule people who come here and expect freebies instead of genuinly wanting to learn.

MrOmega 01-22-2011 09:23 PM

My method to handling is a tad different. I use -sword system which handles slicing/charging/spining/updating tiles, but I have individual sword weapons. When a player selects a sword I trigger a function serverside of the sword weapon which handles the stat modifiers and sets a clientr val with the sword name/sword image/inventory position. When player selects another sword I find the sword the player has by a clientr value I set, then after it returns the mods to normal then update the clientr val and then trigger the mods in the new sword.

AlexanderK 01-25-2011 05:51 PM

Quote:

Originally Posted by cbk1994 (Post 1624712)
SUPER LONG QUOTE

I tried to do it like you suggested, but it didn't work, so I put in some echoes. It seems like the .link() doesn't survive the return. What could I do to fix that? I guess I just have to get every single value by itself, don't I?
These are the echoes:
HTML Code:

trigger1 in -Inventory
trigger2 in -SWeapons
ID:Sword1
trigger3 in database npc
damage before returning:20
damage after return:

And this is my code (which is basically yours but with different names for variables)
weapon -SWeapons:
PHP Code:

function onSWeaponEquipped(sweaponID) {
  echo(
"trigger2 in -SWeapons");
  echo(
"ID:"@sweaponID);
  
temp.sweapon sweapons.getSWeapon(sweaponID);
  echo(
"damage after return:"@temp.sweapon.damage);
  
clientr.sweapon.sweaponName sweapon.sweaponName;
  
clientr.sweapon.attackSpeed sweapon.attackSpeed;
  
clientr.sweapon.damage sweapon.damage;
  
clientr.sweapon.typus sweapon.typus;
  
clientr.sweapon.typus2 sweapon.typus2;



database npc sweapons:
PHP Code:

function onInitialized() {
  
this.trigger("created"); // re-add values on start incase they were removed
}

function 
onCreated() {
  
this.sweapon.clearVars(); // empty variables so strays aren't left over to cause problems
  
  //No Weapon
  
this.sweapon.none.sweaponName NULL;
  
this.sweapon.none.attackSpeed NULL;
  
this.sweapon.none.damage NULL;
  
this.sweapon.none.typus NULL;
  
this.sweapon.none.typus2 NULL;
  
  
// Sword 1
  
this.sweapon.Sword1.sweaponName "Sword 1";
  
this.sweapon.Sword1.attackSpeed 0.2;
  
this.sweapon.Sword1.damage 20;
  
this.sweapon.Sword1.typus "slash";
  
this.sweapon.Sword1.typus2 "normal";
  
}

public function 
getSWeapon(sweaponID) {
  echo(
"trigger3 in database npc");
  
temp.test this.sweapon.(@ sweaponID).link();
  echo(
"damage before returning:"@temp.test.damage);
  return 
temp.test;



cbk1994 01-25-2011 10:55 PM

Odd, I thought link worked like that.

This ought to work:

PHP Code:

function onInitialized() {
  
this.trigger("created"); // re-add values on start incase they were removed
}

function 
onCreated() {
  
this.sweapon.clearVars(); // empty variables so strays aren't left over to cause problems
  
  //No Weapon
  // added the below statement;
  // make sure to change the name ("SwordNone") for each sword, it doesn't
  // matter what it is, it just needs to be unique (it would be a good idea to prefix
  // it with Sword to prevent conflicts with other objects)
  
this.sweapon.none = new TStaticVar("SwordNone");
  
this.sweapon.none.sweaponName NULL;
  
this.sweapon.none.attackSpeed NULL;
  
this.sweapon.none.damage NULL;
  
this.sweapon.none.typus NULL;
  
this.sweapon.none.typus2 NULL;
  
  
// Sword 1
  
this.sweapon.Sword1 = new TStaticVar("Sword1");
  
this.sweapon.Sword1.sweaponName "Sword 1";
  
this.sweapon.Sword1.attackSpeed 0.2;
  
this.sweapon.Sword1.damage 20;
  
this.sweapon.Sword1.typus "slash";
  
this.sweapon.Sword1.typus2 "normal";
  
}

public function 
getSWeapon(sweaponID) {
  echo(
"trigger3 in database npc");
  
// removing link() from here since it now points to an actual object
  
temp.test this.sweapon.(@ sweaponID);
  echo(
"damage before returning:"@temp.test.damage);
  return 
temp.test;




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

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