Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Gonna be lazy Need help with a script

Kume Grant
Registered User
Join date: 30 Aug 2005
Posts: 7
12-20-2006 21:44
Ok. I've tried and tried and tried but i just CAN'T understand this script...

So I need someoen to help.
What i'm trying to do is make an HUD that does the following

*click* List of spells

Ice/ Fire/ wind/ water/

*click one* List of names

john doe/ noname mgee/ OU812 ROXORZ

*click name* Cast spell through channel 3 chat

/3 ice <name put here through script chat thingy>


well this is the best I can describe it... IO tried and tried to understand the scripts needed and it's ust giving me a migrane...

Wiki's been little help.
RaH Wollongong
Registered User
Join date: 11 Jul 2006
Posts: 19
12-20-2006 21:52
Do you want a hud or a menu?

If you are using a hud you should make it first, then think about the problems you want to solve.

You need a list of spells, have a prim with a script that lists spells, you will be most likely using linked messages to pass data between the hud objects.

You need something that detects avatars within a given distance.

Then you will need to aim at them, more specifically select or target them.

The last part adding the chat is easy. It would take me too long to sit and write out for you, but take smaller steps to the goal.
Clayton Cinquetti
Registered User
Join date: 17 May 2005
Posts: 38
12-20-2006 22:26
I have an example of a HUD that displays the text "Click HUD for dialog of options". Once you click on it a dialog pops up with a list of options. Depending on what option you select the text changes. The example is on my blog at www.secondlifehowto.com. I've also submitted the text to the scripting library on this forum, but as this section is moderated it hasn't shown up yet.

At any rate, try the tutorial on my blog and after that you should be a lot closer to being able to do what you want to do.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-21-2006 00:00
Getting a list of names item was covered yesterday Here.

Do your spells need keys or names? or is this an addon to an existing spell book system?

Below is a modified version of the previously mentioned post with hard coded spellnames.
Adding additional menu's for the spells held within notecards would not be difficult.

This will use s single button /object ratehr than a HUD. To make a HUD varaiation replace the spell menu with spell buttons. You could expand to have spell classes / elements as the HUD buttons calling dialogs with specific spells, i.e. Fire calls a menu with firebolt, firestorm and torch, then spell itself could be used to determine if it needs to be targettted or is an are effect.

CODE

// Configurable Settings
float Range = 10; // 10 meters
float Rate = 5; // in seconds
integer SpellChannel = 3;
list SpellNames = [ "Ice","Fire","Wind","Water"];
string Spell;

// Detected list variables
list detected_list;
list detected_names;

// Dialog Handler
integer Listening;
integer ListenChannel;

key owner = NULL_KEY;

// Functions
UpdateListen(key id)
{
CancelListen();
Listening = llListen(ListenChannel,"",id,"");
llSetTimerEvent(30);
}

CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}

// Owner Conversation Dialog
ChooseTarget(key id)
{

string text = "Cast " + Spell + " at ? ";
ListenChannel = (integer)llFrand(2147483646) + 1;
list AVList;
// Simple version - put AV names directly on Buttons
integer len = llGetListLength(detected_list);
if(len == 0)
{
text += "\n\nNO ONE HERE BUT US CHICKENS!";
}
else
{
if(len > 12)len = 12;
AVList = llList2List(detected_names,0,len - 1);
}

llDialog(id,text,AVList,ListenChannel);
UpdateListen(id);
}



// Select Spell Dialog
StartConversation(key id)
{

string text = "Which Spell ?";
ListenChannel = (integer)llFrand(2147483646) + 1;
llDialog(id,text,SpellNames,ListenChannel);
UpdateListen(id);
}


default
{
state_entry()
{
owner = llGetOwner();
llSensorRepeat("", "", AGENT, Range , PI, Rate);
}

on_rez(integer num) { llResetScript(); }

changed(integer change)
{
// Test for a changed inventory
if (change & CHANGED_OWNER)
{
llResetScript();
}

}


no_sensor()
{
detected_list = [];
detected_names = [];
}

sensor( integer number_detected )
{
integer i;
string name;
detected_list = [];
detected_names = [];
for( i = 0; i < number_detected; i++ )
{
key id = llDetectedKey( i ) ;
if(id != owner )
{
// Limit name to 24 Characters
name = llGetSubString(llDetectedName( i ), 0 , 24);;

detected_list += id;
detected_names += name;
}
}
}

timer()
{
CancelListen();
}

touch_start(integer total_number)
{
// Owner
key id = llDetectedKey(0);
if( (id == owner))
{
StartConversation(id);
}
}

listen( integer channel, string name, key id, string message )
{
integer index = llListFindList(detected_names, [ message ] );
if(index >= 0)
{
llSay(SpellChannel,Spell + " " + message);
}
else
{
index = llListFindList(SpellNames, [ message ] );
if(index >= 0)
{
Spell = message;
ChooseTarget(id);
}
}
}
}

Kume Grant
Registered User
Join date: 30 Aug 2005
Posts: 7
12-22-2006 16:18
From: Newgate Ludd
Getting a list of names item was covered yesterday Here.

Do your spells need keys or names? or is this an addon to an existing spell book system?

Below is a modified version of the previously mentioned post with hard coded spellnames.
Adding additional menu's for the spells held within notecards would not be difficult.

Thsi will ue asingle button /object ratehr tahna HUG. To make a HUD varaiation repalce teh spell menu with spell buttons. You could expand to have spell classes / elements as teh HUD buttons calling dialogs with specific spells, i.e. Fire calls a menu with firebolt, firestorm and torch, tehn spell itself could then be used to determine if it needs to be targettted or is an are effect.

CODE

// Configurable Settings
float Range = 10; // 10 meters
float Rate = 5; // in seconds
integer SpellChannel = 3;
list SpellNames = [ "Ice","Fire","Wind","Water"];
string Spell;

// Detected list variables
list detected_list;
list detected_names;

// Dialog Handler
integer Listening;
integer ListenChannel;

key owner = NULL_KEY;

// Functions
UpdateListen(key id)
{
CancelListen();
Listening = llListen(ListenChannel,"",id,"");
llSetTimerEvent(30);
}

CancelListen()
{
if(Listening > 0) llListenRemove(Listening);
Listening = 0;
llSetTimerEvent(0);
}

// Owner Conversation Dialog
ChooseTarget(key id)
{

string text = "Cast " + Spell + " at ? ";
ListenChannel = (integer)llFrand(2147483646) + 1;
list AVList;
// Simple version - put AV names directly on Buttons
integer len = llGetListLength(detected_list);
if(len == 0)
{
text += "\n\nNO ONE HERE BUT US CHICKENS!";
}
else
{
if(len > 12)len = 12;
AVList = llList2List(detected_names,0,len - 1);
}

llDialog(id,text,AVList,ListenChannel);
UpdateListen(id);
}



// Select Spell Dialog
StartConversation(key id)
{

string text = "Which Spell ?";
ListenChannel = (integer)llFrand(2147483646) + 1;
llDialog(id,text,SpellNames,ListenChannel);
UpdateListen(id);
}


default
{
state_entry()
{
owner = llGetOwner();
llSensorRepeat("", "", AGENT, Range , PI, Rate);
}

on_rez(integer num) { llResetScript(); }

changed(integer change)
{
// Test for a changed inventory
if (change & CHANGED_OWNER)
{
llResetScript();
}

}


no_sensor()
{
detected_list = [];
detected_names = [];
}

sensor( integer number_detected )
{
integer i;
string name;
detected_list = [];
detected_names = [];
for( i = 0; i < number_detected; i++ )
{
key id = llDetectedKey( i ) ;
if(id != owner )
{
// Limit name to 24 Characters
name = llGetSubString(llDetectedName( i ), 0 , 24);;

detected_list += id;
detected_names += name;
}
}
}

timer()
{
CancelListen();
}

touch_start(integer total_number)
{
// Owner
key id = llDetectedKey(0);
if( (id == owner))
{
StartConversation(id);
}
}

listen( integer channel, string name, key id, string message )
{
integer index = llListFindList(detected_names, [ message ] );
if(index >= 0)
{
llSay(SpellChannel,Spell + " " + message);
}
else
{
index = llListFindList(SpellNames, [ message ] );
if(index >= 0)
{
Spell = message;
ChooseTarget(id);
}
}
}
}



The spells use channel 3 and target via partial name to target a person
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-23-2006 02:14
From: Kume Grant
The spells use channel 3 and target via partial name to target a person


Well the script as written should address all that. However it is duplicating effort as the spell will use a sensor to find the specific target from its name. If you have access to the spell code we could simplify it and integrate the menu system to improve responce and reduce the lag.
Mevo Syaka
Ganja Guru
Join date: 12 Dec 2006
Posts: 33
03-30-2007 08:42
How would I use the spell on the persons name I had selected from the target menu?
_____________________
FourTwenty Headshop



Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-31-2007 02:06
From: Mevo Syaka
How would I use the spell on the persons name I had selected from the target menu?


That would be totally dependant on the spell system.
The original idea here was you would select a spell, and then a target which would then produce the correct output to activate an existing spell system. This obviously would need to be tailored to the system in use.