|
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
|
05-01-2007 02:34
This is a script for a HUD that displays score and what-not in a combat system I'm working on. Right now I'm having major issues with the kill/death registration part. deaths register fine 100% of the time. kills have about a 50% chance of registering, event though the listener for that particular channel fires off. Observed Behaviour: Player makes a kill- The listen is being processed from the appropriate data channel. the proper data is being sent (both keys are valid, seperator symbols are properly set). Sometimes it will go through the if-statement that a kill was made. sometimes it won't. there does not seem to be any obvious reason for this behaviour. out of 75 test kills, only 38 registered. environmental conditions were as close to duplicate as possible for each test kill. integer health; integer ammocount; string ammotype; integer kills; integer deaths; default { on_rez(integer num) { kills=0; deaths=0; } state_entry() { llListen(-650978,"",NULL_KEY,""); llListen(-24897,"",NULL_KEY,""); }
listen(integer channel, string name, key id, string message) { if(channel==-650978 && llGetOwnerKey(id)==llGetOwner()) { list data = llParseString2List(message,["//"],[]); health= (integer)llList2String(data,0); ammotype=llList2String(data,1); ammocount=(integer)llList2String(data,2); llMessageLinked(LINK_SET,health,"health",NULL_KEY); llMessageLinked(LINK_SET,-132,ammotype,NULL_KEY); llMessageLinked(LINK_SET,ammocount,"ammocount",NULL_KEY); } if(channel==-24897)//Channel for kill/death info. info is parsed as victim'skey//killer'skey { llSay(0,"Recieved a death/kill");//Debugging info. this is fired everytime a death or kill happens list keys = llParseString2List(message,["//"],[]);//parsing my data into usable chunks key killer=llList2String(keys,1);//setting the killer's key key victim=llList2String(keys,0);//setting the victim's key if(victim==llGetOwner() && victim != killer)//This particular part is working just fine. the victim!=killer part is to filter out suicide cases { llOwnerSay(llKey2Name(llGetOwnerKey(killer)) + " Killed you.");//announce to the player who killed them deaths +=1;//increase the death counter } if(killer==llGetOwner() && victim != killer)//This part is what's not working 100% of the time. sometimes it fires off when conditions are met, sometimes it doesn't. I can't seem to figure out why. { llOwnerSay("You Killed " + llKey2Name(llGetOwnerKey(victim)));//announce to the player who they killed. kills +=1;//increase the kill counter } if(victim==killer)//incase the player killed themselves { llOwnerSay("You sucided");//let them know they screwed up :) kills -=1; } llMessageLinked(LINK_SET,deaths,"deaths",NULL_KEY);//Transmit the appropriate data to the HUD display llMessageLinked(LINK_SET,kills,"kills",NULL_KEY); } } }
I'm at a loss here and really banging my head as to what's wrong. PS. it's late tons of typos in the comments, I'll try and edit it later when I'm not crosseyed.
_____________________
My SLExchange shopTypos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not. The function is working perfectly fine. It's just not working the way you wanted it to work.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-01-2007 03:28
Only thing I can think to suggest are extra parenthesis around the tests and also reducing the number of calls to llGetOwner. integer health; integer ammocount; string ammotype; integer kills; integer deaths; default { on_rez(integer num) { kills=0; deaths=0; } state_entry() { llListen(-650978,"",NULL_KEY,""); llListen(-24897,"",NULL_KEY,""); }
listen(integer channel, string name, key id, string message) { key kOwner = llGetOwner(); if( (-650978 == channel) && (llGetOwnerKey(id) == kOwner) ) { list data = llParseString2List(message,["//"],[]); health= (integer)llList2String(data,0); ammotype=llList2String(data,1); ammocount=(integer)llList2String(data,2); llMessageLinked(LINK_SET,health,"health",NULL_KEY); llMessageLinked(LINK_SET,-132,ammotype,NULL_KEY); llMessageLinked(LINK_SET,ammocount,"ammocount",NULL_KEY); } if( -24897 == channel)//Channel for kill/death info. info is parsed as victim'skey//killer'skey { llSay(0,"Received a death/kill");//Debugging info. this is fired everytime a death or kill happens list keys = llParseString2List(message,["//"],[]);//parsing my data into usable chunks key killer=llList2String(keys,1);//setting the killer's key key victim=llList2String(keys,0);//setting the victim's key if(victim == kOwner)//This particular part is working just fine. the victim!=killer part is to filter out suicide cases { if(victim == killer) { llOwnerSay("You sucided");//let them know they screwed up :) kills -=1; } else { llOwnerSay(llKey2Name(llGetOwnerKey(killer)) + " Killed you.");//announce to the player who killed them deaths +=1;//increase the death counter } } else if(killer == kOwner) //This part is what's not working 100% of the time. sometimes it fires off when conditions are met, sometimes it doesn't. I can't seem to figure out why. { if(victim != killer) { llOwnerSay("You Killed " + llKey2Name(llGetOwnerKey(victim)));//announce to the player who they killed. kills +=1;//increase the kill counter } } llMessageLinked(LINK_SET,deaths,"deaths",NULL_KEY);//Transmit the appropriate data to the HUD display llMessageLinked(LINK_SET,kills,"kills",NULL_KEY); } } }
You may also find using llGetSubString faster than parsing to a list to get the encoded keys. (Nothing to do with your OP I know)
|