![]() |
Newbie scripter needs advice.
I am very new to scripting and need help. This is the first script I've ever made and it doesn't work. What is wrong with this script? for some reason when I put the sleep() command in there it makes that player.chat variable command not work correctly.
PHP Code:
|
message should look like
PHP Code:
PHP Code:
Functions need to be wrapped in parenthesis. Also, strings(a series of characters like "asdfghjkl") need to be in qoutes otherwise the computer recognizes them as refering to a variable. examples: PHP Code:
examples of functions with variables: PHP Code:
PHP Code:
PHP Code:
If you don't understand this I recommend reading twinny's tutorial, its easy and explains most of this in a much less complicated way. Then move onto fowlplay's tutorial that covers more advanced topics. |
Welcome to the Scripting forums.
You're mixing GS1 and GS2 together which is a bad and I believe the script isn't working as intended because you didn't make it client-side. I personally consider message() deprecated. You can just edit the npc's text directly like you do with the player's. I.e: this.chat = "Hello World!"; I've made a quick revision to your script with my suggested changes: PHP Code:
Graal Bible / Wiki: http://wiki.graal.net/index.php/Creation/Dev/GScript The tutorials that skillmaster mentioned can be found here: Twinny's scripting guide fowlplay4's scripting guide Read through them, search the forums when you encounter problems, and feel free to look through Code Gallery scripts. We're also here to help. Good luck! |
The sleep was breaking it because a sleep on serverside causes the player to fall out of scope.
You can put the player object in a temporary variable first if you'd still like to do it on serverside (although in this case there's no reason to -- Jer's example should do exactly what you want it to). PHP Code:
|
Thank you so much guys! The script works perfectly! Not to mention I actually understand how it works, which is good! So thanks! You guys are awesome! :D
|
More scripting issues.
I don't mean to bother you guys with too many of my problems, but I've yet another script that I cannot figure out.
PHP Code:
|
PHP Code:
You should do something like: PHP Code:
|
Well name is one of those pre-defined/engine variables that you can't use.
Instead use something else like this.npc_name. Also starts() is a string/object function. You call it like this: I've also included how to extract the player's input using tokenize and substring. PHP Code:
string.substring(start_position, [length]) - extracts a section of a string, if you don't specify a length it extracts everything from the starting position. string.tokenize([token]) - splits the string into multiple tokens based on the token you passed to it. If you don't specify a token it uses a blank space. For your scenario here it's best to just use substring because then the player won't be required to use quotations. Quote:
|
Thanks very much! Just to clarify, it's putting ("/setname ".length()) after player.chat.substring that causes the "/setname" part of the players chat to not effect the whole name? If you don't have time to explain, I understand, I know I'm being an endless font of questions right now, but how exactly does that work? It'd be good to know for future scripts.
|
Quote:
|
Quote:
Basically the length of "/setname " is the position in the string where the player's input starts. I.e: /setname test would return: test You can also trim your input as well but I wouldn't worry about that right now. |
Ah, I get it! Thank you so much, you have been loads of help! I plan to eventually implement a script like this for a name system for pets on my server once I get better at scripting, so I'm glad I can understand it now! Thanks very much, it means a lot! :)
|
This is a script I made for my server so I could randomly make people say stuff if they annoyed me. Just for a bit of fun. It doesn't work, however, and I have no clue as to what is wrong with it. From everything I've learned it seems that it should work. Please help me if you have time, it would be greatly appreciated! :)
PHP Code:
|
*shakes head*
|
Quote:
Read the snippets I have linked here on Client<->Server interaction if you actually are interested in learning: http://public.zodiacdev.com/index.ph...er_Interaction |
Quote:
|
I'll stop asking for so much help, sorry if it was bugging you, I didn't mean to do that! Thank you so much for that tutorial, it's the biggest I've ever found!! After I read that I shouldn't even have to ask for help anymore! :D
|
| All times are GMT +2. The time now is 04:23 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.