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:
|
All times are GMT +2. The time now is 01:56 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.