CS Peeking

A Config Script for Counter-Strike 1.6

Yo, buddy. We are one of the oldest mod sites on the Interwebs. Sign up and maximize your browsing experience.

  • Subscribe: Get notified of new submissions like this.
  • Say Thanks: Show your appreciation by sending rj. points.
  • Post: Give rj. your thoughts on this Script.
  • Vote: Help rj. win the Monthly Awards.
  • Rate: Give this Script a rating out of 10.
  • Flag: Alert moderators and warn members of a problem with this Script.
  • Watch: Get notified when this Script is updated.
Mascot

Resistance is futile...

Sign up

Already a Bananite? Login

453 lines | 10 kb | Raw Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#include 
#include 
#include 
#include 
#include 

#define PLUGIN            "Peeking"
#define AUTHOR            "OT"
#define VERSION            "1.5"

#define MAX_PLAYERS     32

#define MAX_ANGLE        60.0

#define angle_sin(%0,%1) xs_sin(%0 * float(%1) / 100.0, degrees)
#define angle_cos(%0,%1) xs_cos(%0 * float(%1) / 100.0, degrees)

new gBS_alive
new gBS_canpeek
new gI_peekPercent[MAX_PLAYERS + 1]
new gE_peekEnt[MAX_PLAYERS + 1]
new gB_BlockWallhack
new gI_MaxPlayers
new gI_peekDir[MAX_PLAYERS + 1] = {0, ...}

#define IN_PEEKLEFT                            (1<<0)
#define IN_PEEKRIGHT                        (1<<1)

#define add_alive(%1)                        gBS_alive |= (1<<(%1 - 1))
#define add_dead(%1)                        gBS_alive &= ~(1<<(%1 - 1))
#define is_alive(%1)                        (gBS_alive & (1<<(%1 - 1)))

#define add_peek(%1)                        gBS_canpeek |= (1<<(%1 - 1))
#define del_peek(%1)                        gBS_canpeek &= ~(1<<(%1 - 1))
#define can_peek(%1)                        (gBS_canpeek & (1<<(%1 - 1)))

const gBS_CanAttackWeapons =                 ((1<<2) | (1<
public plugin_precache()
{
    precache_model("models/rpgrocket.mdl")
}

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_forward(FM_CmdStart, "fw_CmdStart")
    register_forward(FM_AddToFullPack, "pfw_AddToFullPack", 1)
    register_forward(FM_AddToFullPack, "fw_AddToFullPack")
    register_forward(FM_UpdateClientData, "pfw_UpdateClientData", 1)
    
    register_think("func_peek", "think_func_peek")

    RegisterHam(Ham_Spawn, "player", "pfw_PlayerHandleAD", 1)
    RegisterHam(Ham_Killed, "player", "pfw_PlayerHandleAD", 1)
    
    register_clcmd("+canpeek", "cmd_willpeek")
    register_clcmd("-canpeek", "cmd_stoppeek")
    
    register_clcmd("+peekleft", "cmd_peekleft")
    register_clcmd("-peekleft", "cmd_stopleft")
    register_clcmd("+peekright", "cmd_peekright")
    register_clcmd("-peekright", "cmd_stopright")
    
    gI_MaxPlayers = get_maxplayers()
    
    // A delayed init
    set_task(2.0, "plugin_dinit")
}

public plugin_dinit()
{
    // Here we check if we run my wallblocker, if yes then the plugin will send data to my plugin about attaching entities
    gB_BlockWallhack = cvar_exists("wallblocker_version")
    if (cvar_exists("trwb_version"))
        gB_BlockWallhack = 10000
}

public cmd_peekleft(id)
{
    gI_peekDir[id] |= IN_PEEKLEFT
    
    return PLUGIN_HANDLED
}

public cmd_stopleft(id)
{
    gI_peekDir[id] &= ~IN_PEEKLEFT
    
    return PLUGIN_HANDLED
}

public cmd_peekright(id)
{
    gI_peekDir[id] |= IN_PEEKRIGHT
    
    return PLUGIN_HANDLED
}

public cmd_stopright(id)
{
    gI_peekDir[id] &= ~IN_PEEKRIGHT
    
    return PLUGIN_HANDLED
}

public cmd_willpeek(id)
{
    add_peek(id)
    
    return PLUGIN_HANDLED
}

public cmd_stoppeek(id)
{
    del_peek(id)
    
    return PLUGIN_HANDLED
}

public client_disconnect(id)
{
    if (gE_peekEnt[id])
        remove_entity(gE_peekEnt[id])
    
    gI_peekDir[id] = 0
    del_peek(id)
}

// Block client animation if we are peeking, also stop player from moving (if he uses the peek with one key)
public pfw_UpdateClientData(id, weapons, cd)
{
    if (gE_peekEnt[id])
    {
        set_cd(cd, CD_flNextAttack, 1.0)
        
        if (can_peek(id) && !(entity_get_int(id, EV_INT_button) & (IN_FORWARD | IN_BACK)))
            set_cd(cd, CD_MaxSpeed, 1.0)
    }
    
    return FMRES_IGNORED
}

// Alive/Dead handle
public pfw_PlayerHandleAD(id)
{
    if (is_user_alive(id))
    {
        add_alive(id)
    }
    else
    {
        add_dead(id)
        
        if (gE_peekEnt[id] != 0)
        {
            remove_entity(gE_peekEnt[id])
            AttachView(id, id)
            gE_peekEnt[id] = 0
            gI_peekPercent[id] = 0
        }
    }
    
    return HAM_IGNORED
}

// Count all the comands
public fw_CmdStart(id, uc, seed)
{
    if (!is_alive(id))
        return FMRES_IGNORED
    
    new iButtons = get_uc(uc, UC_Buttons)
    
    if (can_peek(id))
    {
        switch (iButtons & (IN_MOVERIGHT | IN_MOVELEFT | IN_FORWARD | IN_BACK))
        {
            case (IN_MOVERIGHT):
            {
                if (!gE_peekEnt[id])
                    create_peek(id)
                
                if (gI_peekPercent[id] < 100)
                    gI_peekPercent[id] += 4
            }
            
            case (IN_MOVELEFT):
            {
                if (!gE_peekEnt[id])
                    create_peek(id)
                
                if (gI_peekPercent[id] > -100)
                    gI_peekPercent[id] -= 4
            }
            
            default:
            {
                if (gI_peekPercent[id] == 0)
                {
                    if (gE_peekEnt[id])
                    {
                        remove_entity(gE_peekEnt[id])
                        AttachView(id, id)
                        gE_peekEnt[id] = 0
                    }
                    
                    return FMRES_IGNORED
                }
                
                if (0 < gI_peekPercent[id])
                    gI_peekPercent[id] -= 4
                if (gI_peekPercent[id] < 0)
                    gI_peekPercent[id] += 4
            }
        }
    }
    else
    {
        switch (gI_peekDir[id])
        {
            case IN_PEEKRIGHT:
            {
                if (!gE_peekEnt[id])
                    create_peek(id)
                
                if (gI_peekPercent[id] < 100)
                    gI_peekPercent[id] += 4
            }
            
            case IN_PEEKLEFT:
            {
                if (!gE_peekEnt[id])
                    create_peek(id)
                
                if (gI_peekPercent[id] > -100)
                    gI_peekPercent[id] -= 4
            }
            
            default:
            {
                if (gI_peekPercent[id] == 0)
                {
                    if (gE_peekEnt[id])
                    {
                        remove_entity(gE_peekEnt[id])
                        AttachView(id, id)
                        gE_peekEnt[id] = 0
                    }
                    
                    return FMRES_IGNORED
                }
                
                if (0 < gI_peekPercent[id])
                    gI_peekPercent[id] -= 4
                if (gI_peekPercent[id] < 0)
                    gI_peekPercent[id] += 4
            }
        }
    }
    
    if (gE_peekEnt[id])
    {
        new weapon = get_user_weapon(id)
        
        if (weapon == CSW_KNIFE)
            iButtons &= ~IN_ATTACK2
        
        if ((1<            set_uc(uc, UC_Buttons, iButtons & ~(IN_ATTACK))
    }
    
    return FMRES_HANDLED
}

// Make the player invisible so that we will not get blocked by the model
public pfw_AddToFullPack(es, e, ent, host, flags, player, set)
{
    if (!player)
        return FMRES_IGNORED
    
    if (host != ent)
        return FMRES_IGNORED
    
    if (gE_peekEnt[host])
    {
        set_es(es, ES_RenderMode, kRenderTransAlpha)
        set_es(es, ES_RenderAmt, 0.0)
    }
    
    return FMRES_IGNORED
}

// Do not transmit other player peek cameras (less bandwidth usage)
// We also block the transmition of the players if the peek is in the wall
public fw_AddToFullPack(es, e, ent, host, flags, player, set)
{
    if (!player)
        return FMRES_IGNORED
    
    for (new i=1; i <= gI_MaxPlayers; i++)
    {
        if (i == host)
            continue
        
        if (!gE_peekEnt[i])
            continue
        
        return FMRES_SUPERCEDE
    }
    
    return FMRES_IGNORED
}

// Func peek Think, here we do all the calculations
public think_func_peek(eEnt)
{
    new eOwner = entity_get_edict(eEnt, EV_ENT_owner)
    
    new Float:vAngles[3], Float:vOffs[3], Float:fZoff, Float:vStart[3], Float:vAngles2[3], Float:vOffs2[3]
    
    entity_get_vector(eOwner, EV_VEC_v_angle, vAngles)
    entity_get_vector(eOwner, EV_VEC_view_ofs, vOffs)
    
    xs_vec_copy(vOffs, vStart)
    xs_vec_copy(vOffs, vOffs2)
    
    fZoff = vOffs[2]
    
    angle_vector(vAngles, ANGLEVECTOR_RIGHT, vAngles)
    
    xs_vec_copy(vAngles, vAngles2)
    
    xs_vec_mul_scalar(vAngles, angle_sin(MAX_ANGLE, gI_peekPercent[eOwner]) * fZoff * 2, vOffs)
    
    fZoff *=  angle_cos(MAX_ANGLE, gI_peekPercent[eOwner])
    
    vOffs[2] = fZoff
    
    entity_get_vector(eOwner, EV_VEC_origin, vAngles)
    
    xs_vec_add(vStart, vAngles, vStart)
    
    xs_vec_add(vAngles, vOffs, vOffs)
    
    new Float:fraction = traceCamHull(eEnt, vStart, vOffs);
    
    if (fraction > 0.99)
        entity_set_origin(eEnt, vOffs)
    else
    {
        new peekPercent = floatround((gI_peekPercent[eOwner] * fraction))
        
        fZoff = vOffs2[2]
        
        xs_vec_mul_scalar(vAngles2, angle_sin(MAX_ANGLE, peekPercent) * fZoff * 2, vOffs2)
        
        fZoff *=  angle_cos(MAX_ANGLE, peekPercent)
        
        vOffs2[2] = fZoff
        
        entity_get_vector(eOwner, EV_VEC_origin, vAngles2)
        
        xs_vec_add(vAngles2, vOffs2, vOffs2)
        
        entity_set_origin(eEnt, vOffs2)
    }
    
    entity_get_vector(eOwner, EV_VEC_velocity, vOffs)
    entity_set_vector(eEnt, EV_VEC_velocity, vOffs)
    
    entity_get_vector(eOwner, EV_VEC_v_angle, vOffs)
    entity_set_vector(eEnt, EV_VEC_angles, vOffs)
    
    entity_set_float(eEnt, EV_FL_nextthink, get_gametime() + 0.008)
    
    return PLUGIN_CONTINUE
}

stock create_peek(id)
{
    if (gE_peekEnt[id] != 0)
        return gE_peekEnt[id]
    
    new ent, Float:vOrigin[3], Float:vOffs[3]
    
    ent = create_entity("info_target")
    
    if(!ent)
        return 0
    
    entity_set_string(ent, EV_SZ_classname, "func_peek")
    
    gE_peekEnt[id] = ent
    
    entity_set_model(ent, "models/rpgrocket.mdl")
    
    entity_set_size(ent, Float:{-6.0,-6.0,-6.0}, Float:{6.0,6.0,6.0})
    
    entity_set_byte(ent, EV_INT_solid, SOLID_TRIGGER)
    entity_set_int(ent, EV_INT_movetype, MOVETYPE_FLYMISSILE)
    
    entity_set_edict(ent, EV_ENT_owner, id)
    
    entity_set_int(ent,EV_INT_rendermode, kRenderTransTexture)
    entity_set_float(ent, EV_FL_renderamt, 0.0)
    
    entity_get_vector(id, EV_VEC_origin, vOrigin)
    entity_get_vector(id, EV_VEC_view_ofs, vOffs)
    
    xs_vec_add(vOrigin, vOffs, vOrigin)
    
    entity_set_origin(ent, vOrigin)
    
    entity_get_vector(id, EV_VEC_v_angle, vOffs)
    entity_set_vector(ent, EV_VEC_angles, vOffs)
    
    AttachView(id,ent)
    
    entity_set_float(ent, EV_FL_nextthink, get_gametime() + 0.02)
    
    return ent
}

stock AttachView(id, eAttachEnt) 

    attach_view(id, eAttachEnt)
    
    if (gB_BlockWallhack)
    {
        callfunc_begin("fw_setview", (gB_BlockWallhack == 10000) ? "trblock.amxx" : "block_wallhack.amxx") 
        callfunc_push_int(id) 
        callfunc_push_int(eAttachEnt) 
        callfunc_end() 
    }
    
    return 1 
}

stock Float:traceCamHull(ent, Float:start[3], Float:end[3])
{
    new ptr = create_tr2()
    
    engfunc(EngFunc_TraceHull, start, end,  IGNORE_MONSTERS | IGNORE_MISSILE, HULL_HEAD, ent, ptr)
    
    new Float:fraction
    get_tr2(ptr, TR_flFraction, fraction)
    
    free_tr2(ptr)
    
    return fraction
}
Description:
This plugin allows players to peek over the corner.

Usage:
The plugin offers 2 modes of control:
1. Hold the CAN PEEK key and press LEFT or RIGHT and the player will try to peek.
You cannot move/shoot while peeking. But you can look around.
Advantage is that you only need one key bind.
2. Press PEEK RIGHT or PEEK LEFT and hold them for peeking.
Here you can move while peeking.
The disadvantage is that you need 2 key binds.

Commands:
+canpeek - If a user holds this key he will be able to peek around the corners.
+peekleft - If a user holds this key he will peek on the left.
+peekright - If a user holds this key he will peek on the right.
Example how to bind it: bind v +canpeek

Porting the plugin to other mods:
If you want this mod to be ported to other mods (ex DOD) you need to post this: 
- The weapons that behave like grenades
- The weapons that behave like knives
Changelog:
PHP Code:
- 1.5  - added support for my block wallhack plugin! 
- 1.4  - added wall detection via TRACE_HULL, the plugin is closer to reality, all bugs fixed! 
- 1.3  - +peekleft;+peekright commands for players that do want to use 2 keys! [You can move arround when using these two] 
- 1.2  - changed the method of blocking so that the plugin can be easily adapted with other mods 
- 1.1  - fixed client animation, added +canpeek command 
- 1.0  - initial release  

Posts

None found

Share

Shareable Image:
Share banner
HTML embed code:
BB embed code:
Markdown embed code:

More embeddable images

Bookmark and Share

Credits

Original Authors
ot
Creator

Submitter

rj. avatar
rj. PAUSE
Member Joined 1y
307 points Ranked 12924th
38 medals 4 legendary 10 rare
  • Submitted 15 Tools Medal icon
  • Submitted 50 Gamefiles Medal icon
  • 15+ Entries! GameBanana’s Christmas Giveaway 2016 Medal icon
  • Thanked 500 submitters Medal icon
  • 2nd Place - Game Poetry Contest Medal icon
  • Submitted 5 Tools Medal icon

rj.
Redistributor
Are you the owner? Request Ownership
Sign up to access this!
Sign up to access this!
Sign up to access this!
Sign up to access this!

Category

Attributes

Language
Pawn

Stats

Posts
0
Views
748
Date Added
6mo
bcp.crwdcntrl.net tracking pixel