![]() |
Scripting questions
Hi, I recently started scripting GS2 and I have a few questions.
1. What are classes for, like difference between weapons? 2. What is the point of npc's option when you can add npc's in level editor? Is it the same? 3. For setting things for a player, for example the hat or head would the script be something like player.attr1 = "filename"? 4. Are there any "and" or "or" words that can be used in an if statement? For example, a script like function onPlayerchats() { if (player.chat = "hello") *could you put an "and" or an "or" comparison here?* { player.chat = "hi" } |
Quote:
It would be player.attr[1] = "filename"; and is && and or is || For example: PHP Code:
|
in addition to what cyan3 said, classes are not an actual object such as an npc or weapon, but scripts which are essentially copied and pasted (dynamically) into other scripts. you can join multiple classes into one script, you can join classes within classes, and classes can be joined to multiple different types of objects which for example includes players
npcs within rc (often called database npcs) are permanent objects which are not binded to a particular level, so for example if you updated a level all npcs within it would reset to their original state whereas a database npc would retain variables which were stored on it. database npcs can also be warped into different levels and can have their scripts processed without players being in the same level |
1. Like cyan said, with classes you don't need to copy and paste the same function all the time for every script, meaning if you got a bug and you fix it inside a class, that will do the change to every script being joined to that class -> you don't need to find all the weapons/npcs and update them manually.
2. DB NPCs are used to store information. Lets say you got something like: PHP Code:
3. To change a players hat, you need to change the players attr[1] (player.attr[1] = "hat image file";) and for the players head, you need to set the player.head = "head image file"; (for trial users its limited to head0.png to head15.png, maybe even just head10.png). 4. Using && will get you the option to see if the 2nd statement is also true, while using || will check if either one of the statements is true The or check: PHP Code:
PHP Code:
The and check: PHP Code:
PHP Code:
|
So a class is kind of like a variable, where it has code that you can just type the class file instead of re-entering all the code?
Thanks for all the answers btw :D |
Let's say more of a non-changeable flag ('const flag' if you're already familiar with that)
|
http://public.zodiacdev.com/Fowlplay4
http://www.graal.net/index.php/Creation/Dev/GScript These two links have been helping me get back into gs2. |
Quote:
I have another question, (I think it would be better just to post any questions I have under this thread instead of spamming forums, not sure). I am trying to make a staff block/spawn and npc. I somewhat know how to make it, but I'm not sure how you would do it. This is my current script so far. NPC Code://#CLIENTSIDE |
Quote:
PHP Code:
|
Quote:
|
Quote:
for this example you should be assigning the variable using the 'this.' prefix, otherwise it would apply globally which would cause conflict if there were multiple copies of this npc its also good to avoid checking conditions you already know to be false, for example you can do - PHP Code:
PHP Code:
|
Well I have absolutely no clue how to trigger the server, after reading a little on it, this is what I have made (not sure if it makes sense though). Hopefully someone can help me fix/understand it D:?
Quote:
|
I am brushing up on these features as well, so I will link you directly to the resource(s) I am using...
http://forums.graalonline.com/forums...17&postcount=4 http://forums.graalonline.com/forums...84&postcount=6 Both, courtesy of cbk. :) I guess to expound based on your usage: I'd recommend creating a CLASS for your staff block. Using putnpc2 (serverside only), it will determine the position to place that block when the server is triggered. You will then join that NPC placed to the class of your staff block (ex: npc.join("class name"); ) Also, you should get into the habit of using the "echo" feature to ensure parts of your code are working correctly. Example: PHP Code:
That is an example of a working trigger to the server, that will echo "test successful" in your RC if the player with the weapon says "test", and hopefully help you understand the basic format for it better. :) Hopefully someone else can chime in as far as setting parameters to transfer to the server, as I am still messing around with that. :P |
Quote:
|
Well I haven't posted a question on here in a bit, but I ran into another problem. I want to make a script that sets the players tag. I'm not sure if this script is correct in any way/or if I over thought it. Can someone tell me whats wrong :o?
PHP Code:
|
Quote:
PHP Code:
|
Quote:
PHP Code:
|
Thanks for the reply's, they helped a lot :D
|
I have a problem I ran into when making a simple shop GUI, I have tried several things, but I can't seem to get the price text to change when I click on a different row. I posted the entire script, but I marked where I am having the problem and have tried a few things. I am not sure how I can get the row and make the text change when I click it.
http://pastebin.com/d1RrM6Kb - I kept getting an error when posting on here, I posted it on paste bin for now. I marked the part where I am having trouble with. Hopefully someone can tell me what I can use there/explain why it wont work. |
i can see two big problems
you have the onSelect function wrapped within the gui container, it should be outside of the onCreated function with the gui name before the event name you still arent comparing variables properly, it should be '==', just one '=' is for assigning variables a better way to accomplish this would be to have an array of item data, and loop through the array when building the list, the onSelect() function already returns the index of the list item you click, which can then be used to reference the price within the array PHP Code:
you will also want to avoid using such a script within level npcs if theres going to be more than one shop, because they would conflict with eachother even if they are in a different level the best method is to put gui scripts in a weapon, and then call a public function from the level npc script to the weapon script in order to invoke the display, and pass a parameter to identify the npc which called it |
slightly related to his inquiry, but I am looking for a bit more insight on putting rows / columns into a GUI display as well (similar to SQL Explorer, but not as indepth.)
Not for the same purposes, but I will be displaying data in a table format. :[ |
I am having trouble getting the rows to show now, I looked at Jakov's post and managed to get it working one time. But when I went to add an extra row it will not show now.
PHP Code:
|
you need to set the this.items array outside of the gui container, because that is otherwise applying the array variable to the container itself instead of the parent object, which is then not being found within the onSelect event
then if you just use 'thiso' within gui container like shown in my example it will reference the parent object you are also looping through the items array outside of the gui container, which is why the rows arent adding properly, and you are closing the onCreated() bracket in the wrong place http://pastebin.com/vb9hhr7y |
Quote:
|
Quote:
|
Ok, I'm really not sure. I tried everything to get this to work. It seems I am missing something obvious or something of the sort? I took my script and fix everything mentioned so far. I also threw it through the gs2 beautifier by fowlplay to make sure I could find any errors if I was just not styling it right and placing parts in wrong spots still. I could not find anything D:. This is my current script would anyone be able to find where I am messing up?
http://pastebin.com/diQgMxh8 |
Quote:
PHP Code:
|
Quote:
|
It's been a while since I've run into another problem while learning, but I am currently stuck on making a trigger to set the clientr of a player. I have tried a few things with no luck. Would anyone be able to tell me what is wrong with this?
Quote:
|
Quote:
Your trigger is fine except that it looks like you're using the code in an NPC (since you use onPlayerTouchsMe). You can't trigger NPCs the same way you trigger weapons. You would either have to do a triggerAction at the NPC's position, or a fancier trigger (like triggering a weapon or DB NPC). However, since you're using it in an NPC, you don't even need a trigger. onPlayerTouchsMe gets called serverside, too, so you can just do... PHP Code:
|
Quote:
|
Quote:
PHP Code:
|
I started working on a simple shop script, however I have already ran into another problem. I want to trigger a weapon so whenever the player clicks the object it will trigger the simple shop gui I made. How would I go about triggering a weapon from an npc :o?
|
in the item you are clicking on, you need this:
PHP Code:
ex: PHP Code:
--Hopefully someone can chime in with better examples of the above paragraph, as I have not fooled with it recently. ;] Here are a few examples and helpful posts: Skyld's Shop Script That one is somewhat outdated, but still relevant (note, the triggeraction used there has since been replaced -> use triggerClient instead) Also, it might be noted, that Skyld's example stores the items information in a Database (multiple) -- This could now be redone to support SQLite.. Also, some helpful posts for triggering: Serverside / Clientside actions explained http://forums.graalonline.com/forums...84&postcount=6 good trigger examples both ways: http://forums.graalonline.com/forums...17&postcount=4 Trigger DB from Level NPC http://forums.graalonline.com/forums...41&postcount=9 |
@Torankusu
Thank you :D, I'll play around with it and see what I can do for adding security. I''m pretty sure the ActionLeftMouse works on serverside as well, would it be better to make the trigger that triggers the weapon serverside also? |
onActionLeftMouse () or right,
Will work on serverside. You want to send serverside info to the client, so keep the trigger on serverside, and detect it in the weapon npc on clientside. (Note my usage: triggerClient [serverside to clientside] -- causes the event onActionClientside [clientside...]. My terminology might be incorrect, but look at the examples and how they are set up. Also check the other posts by cbk, they are really helpful. |
I just haven't been able to get it to work. Am I doing something wrong?
I put this into the npc PHP Code:
PHP Code:
|
Remove the < and >
|
How would you make it so it knows what row is selected on a gui text list? I tried doing a few things, would this work?
PHP Code:
http://pastebin.com/svjPXSGe |
PHP Code:
|
All times are GMT +2. The time now is 04:34 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.