Tuesday, June 30, 2009

Melee Weapon Example Script

The first section of your script should set specific variables as follows:

key gCreatorKey="place your API key here";
string gObjectName="Place the unique name of this weapon here";
string gAPIType="M";
string gEffectedStat="Z";
string gAPIRace="ALL";
string gEmote="%a hits %d over the head";
string gVicEmote="%d cringes in pain";
string gPart="0";
string gPartDur="0";
string gTPart="0";
string gTPartDur="0";
gEffectedStat="Z";
string gCheckURL="http://sl.rpcombat.com/APIcheck.cfm";
integer gAvatarChannel;
string gPass;
key http_request_id;
integer bulletname; //ignored for melee

integer initialHUDChannel = -39485739;
integer initialHUDListener;
These are the the default options for a melee weapon script. Insert your own license key and an object name you select in the first two fields. Other options included here:
  • gAPIType: M is for melee. Other options are included in the detailed sample scripts.
  • gAPIRace="ALL"; You can make weapons and API objects which will target specific races. A good example of this might be a cross which effects vampire types
  • gEmote: This is what the owner's meter will say when the weapon procs
  • gVicEmote: this is what the target's meter will say
  • gPart, gPartDur: this is for selecting specific particle effects. At this time, best to keep these set to zero, we'll shortly have a particle preview box which will allow you to select and use specific particle effects built into the meter
  • gCheckURL: this is the url your script will go to in order to determine the avatar channel and password
Once you have set these options, include the following global functions:
string crypt(string str){
 return llXorBase64StringsCorrect(llStringToBase64(str),llStringToBase64(gPass));
}
string decrypt(string str){
 return llBase64ToString(llXorBase64StringsCorrect(str,llStringToBase64(gPass)));
}
getChannel()
{
 http_request_id=llHTTPRequest(gCheckURL + "?cKey=" + llEscapeURL(gCreatorKey) + "&obn=" + llEscapeURL(gObjectName) + "&crKe=" + llEscapeURL(llGetCreator()) + "&scKey=" + llEscapeURL(llGetInventoryCreator(llGetScriptName())), [],"");
}
doProc(key target)
{
 string msg="V||" + (string)target + "^" + gAPIType + "|" + gAPIRace + "|" + gEffectedStat + "|" + gEmote + "|" + gVicEmote + "|" + gPart + "|" + gPartDur + "|" + gTPart + "|" + gTPartDur;
 llRegionSay(gAvatarChannel, crypt(msg));
}

In State_entry() we're going to to do one thing: query to find out if the owner has an RPCS meter, and open a listener on a known channel for a response. The purpose of this is that there is no point in licensing an enhanced weapon for someone who is not wearing the meter.

   state_entry() {
       initialHUDListener=llListen(initialHUDChannel, "", "", "");
       llRegionSay(initialHUDChannel, "QUERY|RPCS");
   }
   listen(integer channel,string name,key id,string message) {
       if (channel==initialHUDChannel) {
           if (llGetOwnerKey(id)==llGetOwner()) {
         
               if (message=="RPCS" || message=="RPCS|RESET") {
                getChannel();   
               }
           }
       }
   }

Note that your listener on the default known channel is looking for two things: an acknowledgement that we are wearing RPCS, or a reset command. Any time you get either one of those, you call the getChannel function which will retreive the avatar channel and encryption key.

Next we handle the http response, assigning a avatar specific channel to communicate with the owner, and an encryption password. Note that RPCS uses individual unique channels for each wearer: your API script will only be able to communicate with the owner of the weapon. Everything else is handled by the meter.

   http_response(key id,integer h_status,list meta,string body) {
       if (h_status==200)
       {
           list response=llCSV2List(llStringTrim(body, STRING_TRIM));
               if (llList2String(response, 0)=="MSG") {
                   llOwnerSay(llList2String(response, 1));
               } else if (llList2String(response, 0)=="GO") {
                   gAvatarChannel=llList2Integer(response, 1);
                   gPass=llStringTrim(llList2String(response, 2), STRING_TRIM);
               }
       }   
   }

Finally we tell the meter that this is an enhanced weapon. I'm doing this on restart/relog and when the weapon is drawn by sending a linked message to the API script. Note that the meter will not retain indefinately that you are using an enhanced weapon: you have to _resend_ the proc every 300 seconds. I stop it from sending the command when the weapon is sheathed by sending a linked message with num 4343, then on drawing the weapon send 4242 and start the timer again.

   link_message(integer linknum, integer num, string str, key id) {
       if (num==4242) {doProc(NULL_KEY); llSetTimerEvent(300);}
       else if (num==4343) {llSetTimerEvent(0.0);}
   }
   timer () {
       doProc(NULL_KEY);   
   }
Feel free to grab a test key from the Content Creators section on the website and test it out!

1 comments:

Liace Parx said...

*** Important ***

To register the script with the meters, you need to add the following to YOUR EXCISTING melee script
For draw add: llMessageLinked(LINK_THIS, 4242, "", "");
For steath add: llMessageLinked(LINK_THIS, 4343, "", "");

*** Important ***

Post a Comment