- Quick Links - |
Visitor No.72282 |
- Random Picture - | ||||||
|
Making a Flashing Grenade
Let's make a flash grenade shall we? First of all, the way it works is that the grenade will check around it when it explodes and finds anyone unlucky to be blinded. This is a bit complicated, but I'll try to explain it easily.
Now you will create a cog and attach this to the explosion template. If you want to make thing lights take effect for a few seconds after the explosion make sure you set the timer for the explosion longer than that, and that explosion can be just a ghost template, nothing has to happen with the template, the cog will handle all. Open up a new cog. In there add "created" message and "timer" message. In the created message you will make the explosion find anything around it, if it has LOS. This is plain complicated here, so let me paste it for now. You do this part several times for the explosion to search around because somehow 360 deg for FirstThingInView doesn't work(even with no ThingViewDot)! Place this in a custom message like "find_them:" potential = FirstThingInView(original, 180, 9, 0x404); while(potential != -1) { if( HasLOS(potential, original) && (ThingViewDot(potential, original) > 0) && !(GetThingFlags(potential) & 0x200) && !(GetActorFlags(potential) & 0x100) ) { Spotted = 0; for(i = 0; i <= m; i = i + 1) { if(victim0[i] == potential) Spotted = 1; } if(!Spotted) { victim0[m] = potential; m = m + 1; } } potential = NextThingInView(); } return; This will check if there is anything in front of the explosion that has LOS to it, in front of it, not a dying thing and not a droid. If found, it will store the victim in a variable till it checks all victim in that direction. And it makes sure none of the victim will be double spotted. if(!Spotted) add the victim.
Since 360 deg for firstthinginview doesn't work, you need to turn the explosion 180 deg and do the same checking, otherwise people only that is faced by the explosion will be blinded and not behind the explosion. In order to change the direction the explosion is facing and repeat the same procedure, use this. And there are better method for multiplayer since the grenade is being thrown locally, you only have to care about the GetLocalPlayerThing() and not other players. original = GetSenderRef(); victim0 = -1; m = 0; if(!IsMulti()) //for single player only, better method for multiplayer { LookVec = GetThingLVec(original); SetThingLook(original, VectorSet(VectorX(LookVec), VectorY(LookVec), 0)); call find_them; SetThingLook(original, VectorSet(-VectorX(LookVec), -VectorY(LookVec), 0)); call find_them; SetThingLook(original, VectorSet(VectorX(LookVec), VectorY(LookVec), 0.5)); call find_them; SetThingLook(original, VectorSet(-VectorX(LookVec), -VectorY(LookVec), 0.5)); call find_them; SetThingLook(original, VectorSet(VectorX(LookVec), VectorY(LookVec), 1)); call find_them; SetThingLook(original, VectorSet(-VectorX(LookVec), -VectorY(LookVec), 1)); call find_them; SetThingLook(original, VectorSet(VectorX(LookVec), VectorY(LookVec), -0.5)); call find_them; SetThingLook(original, VectorSet(-VectorX(LookVec), -VectorY(LookVec), -0.5)); call find_them; for(i = 0; i <= m - 1; i= i + 1) { blinded = victim0[i]; SetActorFlags(blinded, 0x800); //blind flags KillTimerEx(blinded); //new timer for the individuals SetTimerEx(3, 0, GetThingSignature(blinded), blinded); //3sec should do } } //multiplayer can only care about the player himself, since the grenade is only appearing locally on every computer. blinded = GetLocalPlayerThing(); //local player if( HasLOS(blinded, original) && (GetThingHealth(blinded) != 0) ) { SetActorFlags(blinded, 0x800); KillTimerEx(0); SetTimerEx(3, 0, GetThingSignature(blinded), blinded); DistFromFlash = VectorDist(GetThingPos(original), GetThingPos(blinded)); //distance from flash Flash_Intensity = (6 - DistFromFlash) * 100; //how flashy from the distance if(Flash_Intensity < 10) Flash_Intensity = 10; //if too low, give some DistFromFlash = (10 - DistFromFlash) * 0.2; //used for how long the flash stays on player SendMessageEx(GetThingClassCog(blinded), user1, Flash_Intensity, DistFromFlash, 0, 0); //send info to kyle.cog, user1 } SetThingLight(original, 2, 0.2); //visual lights SetTimerEx(1, 1, original, 0); //for little time return; At least this will check most of the directions, don't know how much fov it covered. But somehow when the victim and the explosions are in the different sectors even next to each other it won't affect him. Maybe firstthinginview has something to do with it and not me. But that is being fixed for the multiplayer, it checks if the player has LOS to the grenade or not, and just force them to be blinded. You might want to simplify the above message with "for" but if you do, jk WILL freeze, so don't.
In kyle.cog user1 message, add this so it blinds them physically (hurts eyes...ouch) user1: Flash_Intensity = GetParam(0); Flash_Wait = GetParam(1) / 100; //make it multiple compatible, in case this guy gets blinded multiple times quickly. flashBlind0[flashes] = NewColorEffect(0, 0, 0, 0, 0, 0, Flash_Intensity, Flash_Intensity, Flash_Intensity, 1); SetTimerEx(Flash_Wait, flashes, Flash_Intensity, Flash_Wait); // at least take his white flash off in a time...or it's too vicious flashes = flashes + 1; //make the next flash get in different variable flashBlind0 - flashBlind1 etc... if(flashes == 16) flashes = 0; //after a cycle get the variable back to flashBlind0 return; Add this in the timer message to take the effect off. Btw it reserves timerID 0 to 15, so make sure it won't conflict with other timer ID in the timer message. And place this below all the other timers, because of "else" //other timers above... else { TimerID = GetSenderID(); if(flashBlind0[TimerID] != -1) //reset every flash and give new flash with less flashy effect { freeColorEffect(flashBlind0[TimerID]); flashBlind0[TimerID] = -1; } Flash_Intensity = GetParam(0) - 3; //lower flashing by bit if( (Flash_Intensity < 0) || (GetThingHealth(player) == 0) ) return; //if negative or dead, stop and quit //otherwise, keep on giving blindness. flashBlind0[TimerID] = NewColorEffect(0, 0, 0, 0, 0, 0, Flash_Intensity, Flash_Intensity, Flash_Intensity, 1); SetTimerEx(GetParam(1), TimerID, Flash_Intensity, GetParam(1)); //with timer return; }
Now this is the timer for the explosion cog to take the thing light effect off. timer: if(GetSenderID() == 0) { if(GetThingSignature(GetParam(1)) == GetParam(0)) ClearActorFlags(GetParam(1), 0x800); //AI blind off } else if(GetSenderID() == 1) { SetThingLight(GetParam(0), 0, 2); //Thing light off in 2 sec } return;
That was a lot of coding...well I hope you can figure out what the lines are doing. You can add a line that plays the explosion sound in the created message, if you need. And don't forget all symbols section setup as well. Change the grenade template in the weap_thermdet.cog when you test.
|
This site is developed using PHP under Apache server Certain parts of this site require Cookie support. This site is best viewed with
Internet Explorer 5.5, Netscape 6.0, Opera 6.0 or Mozilla 1.0 and above |