AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=43)
-   -   Laser Dot.. how? (https://forums.alliedmods.net/showthread.php?t=34896)

craze 10-25-2005 01:09

Laser Dot.. how?
 
How would i make a laser dot that goes on whatever wall your aiming at like the rocket launcher from the original half-life?
I just have to get where the user is aiming and spawn a transperent sprite wherever they aim. I think I'd use aimvec or something but im not sure how. Are there any heroes that have this that I can look at? Is it even possible?
I really need to know how to do this. Thanks for your help all.

Batman/Gorlag 10-25-2005 02:44

Code:
/* Gets origin from player. * Modes: * 0 - current position. * 1 - position from eyes (weapon aiming). * 2 - end position from player position. * 3 - end position from eyes (hit point for weapon). * 4 - position of last bullet hit (only CS). */ native get_user_origin(index, origin[3], mode = 0);

This is the answer you are looking for.

yang 10-25-2005 04:30

laser dot:

precache "sprites/laserdot.spr"


use the additive sprite 17.

get the aim vector.

then:

Code:

#define TE_SPRITE    17    // additive sprite, plays 1 cycle

message_begin(MSG_ ,SVC_TEMPENTITY) //message begin
write_byte(TE_)
write_coord() // start position
write_coord()
write_coord()
write_short() // sprite index
write_byte() // scale in 0.1's
write_byte() // brightness
message_end()


craze 10-25-2005 20:04

Im kind of having a little trouble with the help you guys gave me, but it did help get me on track some more and i really appreciate it. Thanks.

I found 2 codes (on amxmodx forums) for a laser sight and I dont know which one to use or how to modify them to match what i want. Can someone help me figure out how to do this.

Here's the first example i found:
Code:
ls_dot = precache_model("sprites/laserdot.spr")

Code:
new aimvec[3]     get_user_origin(id,aimvec,3)     //Make the Laser Dot     message_begin( MSG_BROADCAST,SVC_TEMPENTITY)     write_byte( 17 )     write_coord(aimvec[0])     write_coord(aimvec[1])     write_coord(aimvec[2])     write_short( ls_dot )     write_byte( 10 )     write_byte( 255 )     message_end()

And here's the 2nd one (using same precache as above):
Code:
public make_dot(vec[]) {     message_begin( MSG_BROADCAST,SVC_TEMPENTITY)       write_byte( 17 )     write_coord(vec[0])     write_coord(vec[1])     write_coord(vec[2])     write_short( ls_dot )     write_byte( 10 )     write_byte( 255 )     message_end() }

So i guess they both do the same thing and they're just a tad bit different.
Here's the code im thinking of using (written by myself):

Code:
public laserAimLoop() {     for( new id = 1; id <= SH_MAXSLOTS; id++ ){         if( !is_user_alive(id) || !shModActive() || !gHasHeroPower[id] ) return         //Get origin of user         new aimvec[3]         get_user_origin(id,aimvec,3)         //Make laser dot         message_begin( MSG_BROADCAST,SVC_TEMPENTITY)         write_byte( 17 )         write_coord(aimvec[0])         write_coord(aimvec[1])         write_coord(aimvec[2])         write_short( ls_dot )         write_byte( 10 )         write_byte( 255 )         message_end()     } }

would that work? would that make a laser sight for all players that have the hero and have it follow there cursor no matter what? Thanks for your help all.

Emp` 10-25-2005 20:55

edit: nvm, that looks like it should work, why dont you test it yourself?

craze 10-25-2005 21:05

i dont have cs on this computer.
my main computer got messed up and i have to repair windows.

I changed the code around a tiny bit and made the error checking better:
Code:
ls_dot = precache_model("sprites/laserdot.spr") public laserAimLoop() {     if(!shModActive()) return     for( new id = 1; id <= SH_MAXSLOTS; id++ ){     if(!gHasHeroPower[id]) return      if(is_user_alive(id))      {          //Get origin of user                 new aimvec[3]                 get_user_origin(id,aimvec,3)                 //Make laser dot                 message_begin( MSG_BROADCAST,SVC_TEMPENTITY)                 write_byte( 17 )                 write_coord(aimvec[0])                 write_coord(aimvec[1])                 write_coord(aimvec[2])                 write_short( ls_dot )                 write_byte( 10 )                 write_byte( 255 )                     message_end()     }       } }

Does my code remove the laser dot when they die or do I have to add that in? I'm not sure how I would do that.
So do you guys see any errors... do you think it will work the way i want it to?
thanks for all your help guys

Batman/Gorlag 10-25-2005 23:04

If the user dies, the whole laser thing doesn't get executed at all because you made the check is_user_alive(id). So it's good so far.

craze 10-25-2005 23:15

Quote:

Originally Posted by Gorlag/Batman
it's good so far.

what do you mean so far? that's it. that's all the code right?

yang 10-26-2005 00:49

if(!shModActive()) return
for( new id = 1; id <= SH_MAXSLOTS; id++ ){
if(!gHasHeroPower[id]) return
if(is_user_alive(id))

you can just do somethign like this and make it look way cleaner:

Code:
    for( new id = 1; id <= SH_MAXSLOTS; id++ ){         if ( !shModActive() || !gHasHeroPower[id] || !is_user_alive(id)         {             // do code           } }

and yes, thats all the code you'll need for laser dot to loop.

Emp` 10-26-2005 08:43

yang, wouldnt that make it so it does the loop if sh is off, they dont have the power, or theyre dead?

shouldnt it be like
Code:

    for( new id = 1; id <= SH_MAXSLOTS; id++ ){
        if ( shModActive() && gHasHeroPower[id] && is_user_alive(id) )
        {
            // do code
        }
}



All times are GMT -4. The time now is 23:11.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.