Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
archiv:opensim:downloads:scripts:simple_radar [2024/01/24 16:39] – Externe Bearbeitung 127.0.0.1 | archiv:opensim:downloads:scripts:simple_radar [Unbekanntes Datum] (aktuell) – Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ===== Simple Radar ===== | ||
+ | |||
+ | < | ||
+ | //Sable Till - Radar/ | ||
+ | //You can get a copy of the license this script is under at http:// | ||
+ | //Copyright (C) 2006 Sable Till | ||
+ | |||
+ | //This program is free software; you can redistribute it and/or | ||
+ | //modify it under the terms of the GNU General Public License | ||
+ | //as published by the Free Software Foundation; either version 2 | ||
+ | //of the License, or (at your option) any later version. | ||
+ | |||
+ | //This program is distributed in the hope that it will be useful, | ||
+ | //but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
+ | // | ||
+ | //GNU General Public License for more details. | ||
+ | |||
+ | //You should have received a copy of the GNU General Public License | ||
+ | //along with this program; if not, write to the Free Software | ||
+ | // | ||
+ | |||
+ | string status=" | ||
+ | list people; | ||
+ | integer maxScanDistance; | ||
+ | vector color = < | ||
+ | integer maxPeople = 8; | ||
+ | integer scanType = AGENT; | ||
+ | integer scanFreq=1; | ||
+ | |||
+ | integer count(string name) { | ||
+ | integer i = llListFindList(people, | ||
+ | if(i ==-1){ | ||
+ | people+=[name, | ||
+ | return 0; | ||
+ | } else { | ||
+ | integer count = llList2Integer(people, | ||
+ | people=llListReplaceList(people, | ||
+ | return count; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //calculate time strings with proper units that are sensibly rounded | ||
+ | string time(integer cnt) { | ||
+ | if(cnt> | ||
+ | return (string)(cnt/ | ||
+ | }else { | ||
+ | if(cnt> | ||
+ | return (string)(cnt/ | ||
+ | } else { | ||
+ | return (string)cnt+" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | //I'm pretty sure there' | ||
+ | //North and the target so I can work out which direction it is in. | ||
+ | float getAngle(vector me, vector target) { | ||
+ | float hyp = llVecDist(me, | ||
+ | float yDiff = target.y-me.y; | ||
+ | float xDiff = target.x-me.x; | ||
+ | float angle = llSin(yDiff/ | ||
+ | if(xDiff> | ||
+ | return angle*RAD_TO_DEG; | ||
+ | } | ||
+ | if(xDiff> | ||
+ | return 90-angle*RAD_TO_DEG; | ||
+ | } | ||
+ | if(xDiff< | ||
+ | return angle*RAD_TO_DEG+270; | ||
+ | } | ||
+ | if(xDiff< | ||
+ | return angle*RAD_TO_DEG + 270; | ||
+ | } | ||
+ | return angle*RAD_TO_DEG; | ||
+ | } | ||
+ | |||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSensorRepeat("", | ||
+ | llSetTimerEvent(6); | ||
+ | } | ||
+ | |||
+ | sensor(integer num_detected) { | ||
+ | people=[]; | ||
+ | string result; | ||
+ | integer n=-1; | ||
+ | integer distance=0; | ||
+ | integer detDist; | ||
+ | string name; | ||
+ | |||
+ | vector pos = llGetPos(); | ||
+ | //get the dist, name and direction of everyone we just scanned. | ||
+ | for(n=0; | ||
+ | vector detPos = llDetectedPos(n); | ||
+ | detDist = (integer)llVecDist(pos, | ||
+ | float angle = getAngle(llGetPos(), | ||
+ | name = llKey2Name(llDetectedKey(n)); | ||
+ | if(detDist< | ||
+ | people+=detDist; | ||
+ | people+=name; | ||
+ | people+=angle; | ||
+ | } | ||
+ | } | ||
+ | //sort the strided list | ||
+ | people = llListSort(people, | ||
+ | //construct settext | ||
+ | num_detected = llGetListLength(people)/ | ||
+ | for(n=0; | ||
+ | detDist=llList2Integer(people, | ||
+ | name = llList2String(people, | ||
+ | float dir = llList2Float(people, | ||
+ | if(detDist> | ||
+ | result+="< | ||
+ | } | ||
+ | result+=name; | ||
+ | if(detDist< | ||
+ | integer cnt = count(name); | ||
+ | result+=" | ||
+ | } | ||
+ | result+=" | ||
+ | |||
+ | if(dir < 0 || dir > 360) { | ||
+ | llOwnerSay(" | ||
+ | } | ||
+ | //determine which compass direction they are in. | ||
+ | if(dir <= 22.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 22.5 && dir <= 67.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 67.5 && dir <= 112.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 112.5 && dir <= 157.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 157.5 && dir <= 202.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 202.5 && dir <= 247.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 247.5 && dir <= 292.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 292.5 && dir <= 337.5) { | ||
+ | result+=" | ||
+ | } else { | ||
+ | if(dir > 337.5 && dir < 360) { | ||
+ | result+=" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | }}}}}} | ||
+ | |||
+ | distance=detDist; | ||
+ | } | ||
+ | |||
+ | |||
+ | //If we detected more (or the same number of) people as maxPeople then shrink down the scan distance to just | ||
+ | //the distance to the furthest one. Otherwise increment it a bit in case there are people further out. | ||
+ | if(num_detected> | ||
+ | maxScanDistance=distance+10; | ||
+ | } else { | ||
+ | maxScanDistance+=10; | ||
+ | } | ||
+ | |||
+ | result+=" | ||
+ | //adjust max people based on the length of result | ||
+ | if(llStringLength(result)> | ||
+ | maxPeople--; | ||
+ | llOwnerSay(" | ||
+ | " Decrementing maxPeople to " | ||
+ | } else { | ||
+ | if(llStringLength(result)< | ||
+ | maxPeople++; | ||
+ | llOwnerSay(" | ||
+ | " Incrementing maxPeople to " | ||
+ | } | ||
+ | } | ||
+ | llSetText(result, | ||
+ | } | ||
+ | |||
+ | no_sensor() { | ||
+ | llSetText(" | ||
+ | maxScanDistance+=10; | ||
+ | llSensorRepeat("", | ||
+ | } | ||
+ | |||
+ | //all we do here is check the sims fps and dilation and tone down our scanning if necessary. | ||
+ | timer() { | ||
+ | float fps = llGetRegionFPS(); | ||
+ | float timeDilation = llGetRegionTimeDilation(); | ||
+ | |||
+ | integer scanDistance; | ||
+ | if(fps< | ||
+ | if(maxScanDistance> | ||
+ | scanDistance=30; | ||
+ | } | ||
+ | scanFreq=240; | ||
+ | status = " | ||
+ | llSetTimerEvent(240); | ||
+ | color=< | ||
+ | } else | ||
+ | { | ||
+ | if(fps< | ||
+ | if(maxScanDistance> | ||
+ | scanDistance=64; | ||
+ | } else { | ||
+ | scanDistance=maxScanDistance; | ||
+ | } | ||
+ | scanFreq=30; | ||
+ | status = " | ||
+ | llSetTimerEvent(120); | ||
+ | color=< | ||
+ | } else | ||
+ | { | ||
+ | if(maxScanDistance> | ||
+ | scanDistance=96; | ||
+ | } else { | ||
+ | scanDistance=maxScanDistance; | ||
+ | } | ||
+ | scanFreq=1; | ||
+ | llSetTimerEvent(60); | ||
+ | status = " | ||
+ | color=< | ||
+ | }} | ||
+ | llSensorRepeat("", | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||