Jump to content

Script on/off problem, needs a fix i guess


Walter Fanwood
 Share

You are about to reply to a thread that has been inactive for 2720 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Well as i said, i created a script but my problem is that does not reset with the hud i use for, i tried to fix it but i gave up, only add the things i need but i cant get it.

 

the problem i have is that if im dead, it does not reset, either if i reset my hud. so i duno if it could be fixed here but i give it out as info.

 

key owner;
vector defaultcolor = <0,1,0>;
integer used = 0;

default
{
    state_entry()
    {
        integer used = 0;
        owner = llGetOwner();
        llListen(-156535255,"","","");
        llSetText("Turn on your Meter!",<1,1,1>,1.0);
    }
    
    attach(key id)
    {
        llResetScript();
    }

    listen(integer chan, string name, key id, string msg)
    {
        list temp = llCSV2List(msg);
        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE"))
        {
             if((integer)used == 0)
             {
             integer chan = -956535255;
             key target = llDetectedKey(0);
             string command = "ARMOR";
             string modifier = "2";
             string sender = "Ribbon";
             
             llOwnerSay("Your Armor increase by 2!");
             llTriggerSound("BUFF",0.8);
             llSay(chan, (string)target + " )( " + command + " )( " + modifier + " )( " + sender);

            llSetText("",defaultcolor,1.0);
            used = 1;
            llSleep(1.0);
            }
        }
    }
}

 

also maybe that helps: the comment to turn the hud on is /9on

off its /9off

Link to comment
Share on other sites

There are two issues here spring out at me

Firstly, there is nothing in the listen to react to any other keyword than the UPDATE one, so any other message will be ignored.

Secondly, the presence in a listen event of the llDetectedKey() function suggests a chunk of code has been lifted out of another event and dumped in a listen event without appreciating what is happening.

As it stands, I can see no way to make this script implement a death, because there is no description of the other messages being sent to it.

As a starting point, I suggest you add the line

llOwnerSay("Heard <" + name + "< say >" + msg + "<");

inside the listen event before the list2csv line, and then watch the output. It will tell you what other messages are being sent, and you can determine then which ones to write blocks of script for.

Have a look in the wiki at llListen() and  the listen event and look in particular at what the key passed to it signifies, then have a look at llDetectedKey() and see where they state it should be used. If this script is in a prim with another script which is detecting objects by collisions, that other script will have to pass the armour key into this script by means of a link message, or, if in a seperate prim, by chatting it on this channel.

One final point. llListen() returns an integer handle which is necessary sometimes when several channels are being used, both for working out which channel has been heard, and also for removing the listen in the event of ownership change, so declare a global integer chandle at the top of the script and add thandle = jujst in front of the llListen call

Link to comment
Share on other sites

You say you want it to reset if you're dead or if you reset your HUD.   But it's got no way of knowing, as it's written, if either of those two things have happened.

That's not the only problem, of course.  First, you say the commands are given on channel 9 but the script listens to channel -156535255.   So obviously it can't hear what you're saying (not that you could say anything on a negative channel anyway -- only objects can talk on negative channels).

Furthermore, as Profaitchikenz points out, it's expecting a message in the format owner's uuid+"UPDATE".   So even if it could hear you saying "on" and "off" on channel 9, it wouldn't know what you wanted it to do.

There's another problem, too.    That is, if it receives a message in the appropriate format, it responds only if the integer used == 0.   It then sets the value of used to 1 -- that is, you can only use it once.   Before the script can react again, it needs either to be reset or something to happen to set the value of "used" back to 0 (or FALSE).    That might be what you're trying to do, but I don't want to guess.

Let's start with first things first.   How is the script supposed to know if you're dead or you've reset your HUD?

 

Link to comment
Share on other sites

now it replays (endless...)

 

"

Heard <SPY FIGHT SYS 1.00A< say >d506d76d-8ddf-430a-b0e7-e78a57699104,UPDATE,100,100<

"

 

I also god a notecard where i add the "armor state" to it, maybe it helps a bit further

 

API Commands


Global API Channel  -  (v2.0):
   -956535255
   
   
 SYNTAX:
 targetUUID )( command )( modifier )( sendername
 
 
EXAMPLE:
 fe0f105a-3a2a-4d70-ad1e-6cac0da5388d )( damage )( 10 )( Lava flow
 
 
 COMMANDS:
 heal
 armor  (only for armor you can wear)
 ap         (use negatives to take away AP)
 damage   (requires sender)
 stun         (Does not need mod or sender to work)
 slow        (Does not need mod or sender to work)
 message       (Message in modifier)
 
 
 
 QUICK DROP SCRIPT:
 (Heal example. Mod for fast API scripts)
 
 integer chan = -956535255;
 key target = llDetectedKey(0);
 string command = "HEAL";
 string modifier = "25";
 string sender = "Stimpack";
 
 llSay(chan, (string)target + " )( " + command + " )( " + modifier + " )( " + sender);

Link to comment
Share on other sites

In your notecard it does give you a clue in the part "targetUUID )( command )( modifier )( sendername", and a little below that, it seems to list example commands that it can be given. It is a formatted message telling a certain UUID what damage it is to suffer and where this damage is originating from. Therefore the HUD or script is acting as a central coordinator for messages coming in from all sorts of scripted objects around it, and relaying them out again to other objects. 

All external objects to the HUD such as swords and armour are going to need a script inside them to listen to and speak on this channel, sending messages according to the specified format. The system probably also has such scripts, which you might not have recognised for what they are yet.

The /9 channel you mentioned in another post suggests there is a second script inside that listens to a wearer for commands such as "reset". You need to look for this, and see how it transfers the information given to it on channel 9 out to the main channel.

 

In a post above I commented that there was an llDetectedKey() function in the Listen event that could not work, From the wiki entry for llDetectedKey()

 

"llDetected* functions only work if called from within Detection events (collision, collision_start, collision_end, sensor, touch, touch_start, touch_end) or in functions called by Detection events."

 

In the heal example in the notecard, in order for that example to actually work, the lines have to be inside one of the detection events, such as a collision, sensor or touch. Therefore, in order to implement the example heal function, you would have aprim somewhere with a touch event inside it, and the person touching that prim would cause that block of code to send the formatted message, targetted at the UUID of the toucher.

 

The block of code you have pasted inside the listen event with the llDetectedKey(0) call can not operate reliably in there, and it needs to be moved into some other event.

Link to comment
Share on other sites

OK, if you are claiming to be a total noob in scripting, then I think you should step away from the complicated task of chopping around somebody else's combat system and start again in small chunks. You need to study collision events,  listen events and timer events.

 

Start with a very simple two-prim system.

Make a wall from a prim.

Make a sphere called armour, and wear it. In the script inside it, have a global variable called health with an intial assignment.

Inside the wall put a script that when it has a collision event, gets the key of the object colliding with it, calculates a random damage number, and sends that as a message on a channel, in the form "UUID, damage value, number";

inside the sphere put a listen event that listens on the channel in question. When it receives a message that begins with its own UUID, it looks at the second part of the message, and if it says "damage value" it converts the third part of the message to a float, and subtracts that from the health value.

If the new value is zero or less, the script starts a timer on a 20 second count, and after 20 seconds, when the timer event triggers, it resets the health value in the sphere to the initial value.

Walk into the wall several times, possibly with llOwnerSay lines telling you the wall's reactions to the collision event and the sphere's reactions to the message, and you should be able to knock yourself out for twenty seconds, then start again.

Once you have it working, then add in your health bar, with the sphere telling the health bar by messages what the current value is, and the health bar displaying that.

There, in a simplified form, is a test harness to investigate pretty much what you have been puzzling over, and if you follow those steps you should gain enough experience to go back to the system you have been trying to work with and get it working properly.

 The alternative, as irihapeti mentioned in another thread where you asked about health bars, is to use one of the score or so combat systems already available, but you won't be learning scripting that way, so I hope you'll persevere with the suggestions I have given above.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2720 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...