as you can tell, im very new to scripting that most people get annoyed with my posts, but please bare with me haha.
im using the wod script set, with asgard features integrated into it. and there is custom music in the asgard script set id like to make a command for.
i want to make a command that calls the script of a song such as ".sing soothingsong", but it needs to check that you have the song slip, the skill needed for it and the instrument.
would anyone be able to give me an example of such a script that i can learn from, rather then just telling me the answer? as of next year i plan to start a diploma of software engineering, and i want to actually learn how scripts work so that i can understand further how to script. please and thankyou,
mat
making a command to call a script
Moderator: POL Developer
-
- Grandmaster Poster
- Posts: 178
- Joined: Tue Sep 08, 2009 1:57 am
Re: making a command to call a script
Well first bit you want to do is use Start_Script()
It takes in the path to the script then a single argument afterwards. Many use an array to pass multiple pieces of information, or a struct, or a dictionary.
First check the script you're going to start and make sure it can receive say an array and put its indices into the variables it needs to.
Once you determine how it will receive the information, you need to determine the path for Start_Script()
If it is in a package you want to do :packagename: before the file name, and add any sub directories below it.
Example.... :sing:soothingsong
You dont need the .ecl on the end.
If say the shard is in a deprecated file structure and everything is inside of scripts/misc/ you would do Start_Script("::misc/filename", arguments);
The "::" refers to the root area
Next goes back to what the started script wants to receive.
In a typical use script, two arguments get passed - a mobile reference for the one using the item, and the item.
Program UseScript(user, item)
When you do Start_Script() and pass that data, everything will be inside of user and item will be empty.
So ways to handle this:
It takes in the path to the script then a single argument afterwards. Many use an array to pass multiple pieces of information, or a struct, or a dictionary.
First check the script you're going to start and make sure it can receive say an array and put its indices into the variables it needs to.
Once you determine how it will receive the information, you need to determine the path for Start_Script()
If it is in a package you want to do :packagename: before the file name, and add any sub directories below it.
Example.... :sing:soothingsong
You dont need the .ecl on the end.
If say the shard is in a deprecated file structure and everything is inside of scripts/misc/ you would do Start_Script("::misc/filename", arguments);
The "::" refers to the root area
Next goes back to what the started script wants to receive.
In a typical use script, two arguments get passed - a mobile reference for the one using the item, and the item.
Program UseScript(user, item)
When you do Start_Script() and pass that data, everything will be inside of user and item will be empty.
So ways to handle this:
Code: Select all
Start_Script(":sing:soothingsong", array{user, item});
--------
Program UseScript(user, item)
item := user[2];
user := user[1];
endprogram
Code: Select all
var arguments := struct;
struct.+user := user;
struct.+item := item;
Start_Script(":sing:soothingsong", arguments);
--------
Program UseScript(user, item)
item := user.item;
user := user.user;
endprogram
Re: making a command to call a script
Create sing.src in pol/scripts/textcmd/player:
Create pirate.src in pol/scripts for this snippet to work.
Now try:
.sing pirate
Code: Select all
// that will be your .sing command
// import the required modules
use uo; // uo for sendsysmessage()
use os; // os for start_script()
program sing(who, song)
// run the skill checking function
if(not HasSongSlip(who))
// the function returns 0 on failure, so we write he error message
SendSysMessage(who, "You can't sing without a song slip!")
// returning from the script, could use "exit" as well
return;
endif
// starting a song script with the name song+".ecl" in the same folder
var song_script := start_script("::"+song, who);
// start_script returns error if a script file doesn't exist
if( song_script==error )
// once again the error message, so the player get confused
SendSysMessage(who, "You don't know that song!");
// extra output for staff characters (i.e game masters)
if(who.cmdlevel)
SendSysMessage(who, "Error: "+song_script.errortext); // the error datatype has .errortext member to indicate the error message
endif
return;
endif
endprogram
// I have no idea what a song slip is..
function HasSongSlip(who)
// do your song slip checks here
// and return 0 if the player doesn't have a song slip
return(1);
endfunction
Code: Select all
// a sample song script
use uo;
program song( who )
SendSysMessage(who, "Drink and the devil had done for the rest...");
endprogram
.sing pirate
-
- Grandmaster Poster
- Posts: 178
- Joined: Tue Sep 08, 2009 1:57 am
Re: making a command to call a script
ok, so ive been a bit busy working for the past 7 days so i havnt had much time to do anything, but its my day off today!!!! ive just got 2 scripts to fix that im having a tiny bit of trouble with and then im going to do a bit of testing with all the asgard features i put into my WOD script set, and then ill get to work on this.
thankyou so much austin and andenixa for helping me, very soon i will post up the script i will make from your suggestions/intrustions
thankyou so much austin and andenixa for helping me, very soon i will post up the script i will make from your suggestions/intrustions