Post by Dread Hudson on Jan 30, 2014 3:33:25 GMT -8
Because it's 2014 and motherfuckers need to get with the times. Raideur and I have both been providing full perms example scripts with 90% of the work done so that people stop being hue.
wiki.secondlife.com/wiki/LlCastRay
"Cast a ray from start to end and report collision data for intersections with objects"
AKA "is this laser hitting something between point X and Y?"
AKA "How to make your explosives NOT go through walls"
AKA "How to make instahitting sniper rounds (But not full auto rounds or I'll shit in your pancake mix and force you to eat it because building a list 10 times a second is a really bad idea.)"
First in foremost, What is llCastRay? How do I use it? Here's a handy dandy example llCastray script.
Sensor based Raycast explosive
& the AT that use used within this Sensor based explosion!
with a simple, basic bean, looping rezzer. Starts when the alpha is changed.
Or - if you want to use the Agentlist method
& its paired AT core
With the exact same looping rezzer as the previous AT core.
Look at it, copy and paste it, learn from it, Lets just all try getting along on the fact that blowing people up through solid objects is a really lame thing to do. SLMC Pls.
wiki.secondlife.com/wiki/LlCastRay
"Cast a ray from start to end and report collision data for intersections with objects"
AKA "is this laser hitting something between point X and Y?"
AKA "How to make your explosives NOT go through walls"
AKA "How to make instahitting sniper rounds (But not full auto rounds or I'll shit in your pancake mix and force you to eat it because building a list 10 times a second is a really bad idea.)"
First in foremost, What is llCastRay? How do I use it? Here's a handy dandy example llCastray script.
list rc;//wow much list very amaze, llCastRay returns data in list format for the sake of organization.
default
{
touch_start(integer total_number)
{
rc = llCastRay(llGetPos(),llDetectedPos(0),[RC_MAX_HITS,1,RC_REJECT_TYPES,RC_REJECT_PHYSICAL]);//First vector is start pos, second is end pos, third list is rules. - Source: http://wiki.secondlife.com/wiki/LlCastRay#options
//Rules are as follows
//[ RC_REJECT_TYPES ] Mask used to ignore specific types of objects (and avatars).
//FLAGS ARE AS FOLLOWS:
//RC_REJECT_AGENTS, value of 1
//RC_REJECT_PHYSICAL, value of 2
//RC_REJECT_NONPHYSICAL, value of 4
//RC_REJECT_LAND, value of 8
//[ RC_DATA_FLAGS ] Described in the RC_DATA_FLAGS section.
//FLAGS ARE AS FOLLOWS:
//RC_GET_NORMAL, value of 1
//RC_GET_ROOT_KEY, value of 2
//RC_GET_LINK_NUM, value of 4
//[ RC_MAX_HITS ] Returns an Integer, Maximum number of hits to return. Maximum value is 256. To avoid performance issues, keep it small.
//[ RC_DETECT_PHANTOM ] Integer, if !=0/FALSE the Raycast will detect PHANTOM and VOLUME DETECT
//objects.
//STATUS CODE - At the end of each return list, there is an integer returned, this a
//combination of STATUS CODE and HITS RETURNED. You can get this with a simple -1
//in a List2Integer. If the STATUS CODE is under 0, (ie -1,-2,-3), the Raycast has
//failed. if the STATUS CODE is 0, you didn't hit anything, because it had 0 hit reports.
//Again, consult http://wiki.secondlife.com/wiki/LlCastRay for any information you need
//and or forget.
if(llList2Key(rc, 0) == llDetectedKey(0) ||llList2Integer(rc, -1)<0)//If the key of the hit object is the target, or if the return is less than 0 (In this case, something went wrong in the sim), passes the command.
{
llOwnerSay("yes");
}
}
}
Sensor based Raycast explosive
key agent;
vector pos;
vector vel;
integer bit;
integer i;
integer hits=0;
integer hex;
list rc;
default
{
state_entry()
{
llVolumeDetect(TRUE);//Dont make your explosions non phantom,
//this forces that. And dont even TRY making a collision event based explosive or i will shit in your cheerios.
}
on_rez(integer n)
{
if(n==1)
{
llSensor("","",AGENT,5,TWO_PI);
}
}
sensor(integer n)
{
for(i=0;i<n;++i)
{
agent=llDetectedKey(i);//Who are we hitting?
pos=llDetectedPos(i);//Where are they?
vel=llDetectedVel(i);//How fast are they going?
bit=llGetAgentInfo(agent);//Are they sitting? @ line 32
rc=llCastRay(llGetPos(),pos,[RC_MAX_HITS,1,RC_REJECT_TYPES,RC_REJECT_PHYSICAL]);//Castray from me to them
if(llList2Key(rc,0)==agent||llList2Integer(rc,-1)<=0)//Did I hit them? Phys base shouldn't matter. Alternatively, did the RC fail with a status code?
{
if(bit&0x0020&&hits==0)//Are you sitting? Can we deliver any more AT?
{
hex=(integer)("0x" + llGetSubString(llMD5String((string)llDetectedKey(i),0), 0, 3));//Thanks, Raideur, for this method. Compresses a key to a hex, and
//then compares with an agentlist in the AT prim.
llRezObject("[AT]15",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,hex);//Hex goes in the rez params, see the [AT]15 prim for further info.
++hits;//No more hits left!
llOwnerSay("Delivering 15 AT to: "+llKey2Name(agent));
}
else
{
llRezObject("EXAMPLE PHYSICAL DAMAGE",pos+(vel*.2),ZERO_VECTOR,ZERO_ROTATION,1);//Rezzes damage on their location + a fraction of their velocity.
llOwnerSay("Hit: "+llKey2Name(agent));
}
}
}
llDie();
}
no_sensor()
{
llDie();
}
}
& the AT that use used within this Sensor based explosion!
key t=NULL_KEY;
list agents;
key agent;
list d;
integer i;
integer l;
vector pos;
float alpha;
integer dmg=15;
integer hex;
default
{
on_rez(integer n)
{
llSetAlpha(0,0);
if(n!=0)
{
agents=llGetAgentList(AGENT_LIST_REGION,[]);
l=llGetListLength(agents);
for(i=0;i<l;++i)
{
agent=llList2Key(agents,i);
hex=(integer)("0x" + llGetSubString(llMD5String((string)agent,0), 0, 3));
if(hex==n)
{
t=llList2Key(agents,i);
i=l;
llSetTimerEvent(.05*llGetRegionTimeDilation());
}
}
if(t==NULL_KEY)llDie();
}
}
timer()
{
d=llGetObjectDetails(t,[OBJECT_POS]);
pos=llList2Vector(d,0);
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>,PRIM_POSITION,pos]);
if(llVecDist(pos,llGetPos())<1)llSetAlpha(.1,0);
else llSetAlpha(0,0);
if(!(llGetAgentInfo(t)&AGENT_ON_OBJECT))llDie();
}
object_rez(key id)
{
if(dmg>0)
{
--dmg;
}
else
{
llSetAlpha(0,0);
llDie();
}
}
}
with a simple, basic bean, looping rezzer. Starts when the alpha is changed.
default
{
changed(integer c)
{
if(c&CHANGED_COLOR)
{
llSleep(.1*llGetRegionTimeDilation());
@loop;
llRezAtRoot("[AT_DMG]",llGetPos()+<0,0,3.5>,<0,0,-150>,ZERO_ROTATION,1);
llSleep(.025*llGetRegionTimeDilation());
if(llGetAlpha(0))jump loop;
}
}
}
Or - if you want to use the Agentlist method
key agent;
list data;
list agents;
list d;
vector pos;
vector vel;
integer i;
integer l;
integer hits=0;
default
{
state_entry()
{
llVolumeDetect(1);//Just for forcing phantom, so people don't muck it up from lazy.
}
on_rez(integer n)
{
if(n==1)//Is it rezzed out for editing?
{
agents=llGetAgentList(AGENT_LIST_REGION,[]);
i;
l=llGetListLength(agents);
for(i=0;i!=l;++i)
{
data=llGetObjectDetails(llList2Key(agents,i),[OBJECT_POS,OBJECT_VELOCITY]);//Gets the Position & Velocity of an avatar
pos=llList2Vector(data,0);
vel=llList2Vector(data,1);
agent=llList2Key(agents,i);
if(llVecDist(llGetPos(),pos)<5)//Maximum distance! Are they currently within this area?
{
if(llGetAgentInfo(agent)&AGENT_ON_OBJECT&&hits==0)//Are they sitting and can we deliver any more AT prims? Prevents multiple AT rezzes from hitting passengers. Doesn't raycast AT to a position because of non physical vehicle fuckery.
{
llRezObject("[AT]15",pos,ZERO_VECTOR,ZERO_ROTATION,i+1);//reference the AT provided, cross references position on Agentlist.
++hits;
llOwnerSay("Delivering 15 AT to: "+llKey2Name(agent));
}
else
{
if(llVecDist(llGetPos(),pos)<1)//If under 1m, kill them. essentially a Blast wave in which people will die, behind cover or not. Keep this low unless you want people to shit in your mouth, because a massive non raycasted area defeats the purpose of raycasted explosives.
{
llRezObject("EXAMPLE PHYSICAL DAMAGE",pos+(vel*.2),ZERO_VECTOR,ZERO_ROTATION,1);//Rezzes the killprim on the avatars location + their velocity so it's "Lead" to whats most likely their position after the slight delay of rezzing.
llOwnerSay("Hit: "+llKey2Name(agent));
}
else
{
d=llCastRay(llGetPos(),pos,[RC_MAX_HITS,1,RC_REJECT_PHYSICAL,TRUE]);
if(llList2Key(d,0)==agent||llList2Integer(d,-1)<=0)//If the Castray hits the agent, or if sim performance is too low for the raycast to work, kill them.
{
llRezObject("EXAMPLE PHYSICAL DAMAGE",pos+(vel*.2),ZERO_VECTOR,ZERO_ROTATION,1);
llOwnerSay("Hit: "+llKey2Name(agent));
}
}
}
}
}
//llSleep(1*llGetRegionTimeDilation());
llDie();//When finished with your explosion event, Die. Can be delayed with a llSleep if you want an "Effect" to linger, wont kill any longer.
}
}
}
& its paired AT core
key t=NULL_KEY;
list agents;
list d;
vector pos;
float alpha;
integer dmg=15;//How many shots does this AT have?
default
{
on_rez(integer n)
{
llVolumeDetect(1);//Forces phantom, so people don't do dumb stuff. Solid objects in the center of a physical object is a HORRIBLE IDEA, it causes collision lag out
//the ass and is just a general douchebag move to the vehicle's operator.
llSetAlpha(0,0);
if(n!=0)
{
agents=llGetAgentList(AGENT_LIST_REGION,[]);
t=llList2Key(agents,n-1);
llSetTimerEvent(.05*llGetRegionTimeDilation());//How often the movement will be for tracking on an avatar.
}
}
timer()
{
d=llGetObjectDetails(t,[OBJECT_POS]);
pos=llList2Vector(d,0);
if(!(llGetAgentInfo(t)&AGENT_ON_OBJECT))llDie();//Is your target not on an object? If they aren't, Die. If they are, pass to the movement.
else
{
llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>,PRIM_POSITION,pos]);
if(llVecDist(pos,llGetPos())<1)llSetAlpha(.1,0);//Are you on the position? If so, let it trigger. If not, stop triggering.
else llSetAlpha(0,0);
}
}
object_rez(key id)
{
if(dmg>0)
{
--dmg;
}
else
{
llSetAlpha(0,0);
llDie();
}
}
}
With the exact same looping rezzer as the previous AT core.
default
{
changed(integer c)
{
if(c&CHANGED_COLOR)
{
llSleep(.1*llGetRegionTimeDilation());
@loop;
llRezAtRoot("[AT_DMG]",llGetPos()+<0,0,3.5>,<0,0,-150>,ZERO_ROTATION,1);
llSleep(.025*llGetRegionTimeDilation());
if(llGetAlpha(0))jump loop;
}
}
}
Look at it, copy and paste it, learn from it, Lets just all try getting along on the fact that blowing people up through solid objects is a really lame thing to do. SLMC Pls.