| @@ -0,0 +1,78 @@ | |||
| 1 | + | float targetPos[MAXPLAYERS+1][3]; | |
| 2 | + | int targetEnt[MAXPLAYERS+1]; | |
| 3 | + | ||
| 4 | + | static char STORE_KEY[] = "SEND_TO_HEAVEN"; | |
| 5 | + | ||
| 6 | + | void SendToHeaven_OnActivate(int apologizer, int target, const char[] eventId) { | |
| 7 | + | Handle h = CreateTimer(1.0, Timer_Levitate, GetClientUserId(apologizer), TIMER_REPEAT); | |
| 8 | + | SorryStore[apologizer].SetBool(STORE_KEY, true); | |
| 9 | + | } | |
| 10 | + | ||
| 11 | + | Action Timer_Levitate(Handle h, int userid) { | |
| 12 | + | int client = GetClientOfUserId(userid); | |
| 13 | + | if(client > 0) { | |
| 14 | + | int entity = FindNearestEntityInRange(client, "player", 500.0); | |
| 15 | + | if(entity > 0) { | |
| 16 | + | targetEnt[client] = entity; | |
| 17 | + | GetEntPropVector(entity, Prop_Data, "m_vecOrigin", targetPos[client]); | |
| 18 | + | } | |
| 19 | + | } | |
| 20 | + | return Plugin_Handled; | |
| 21 | + | } | |
| 22 | + | ||
| 23 | + | Action SendToHeaven_OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2]) { | |
| 24 | + | if(client > 0 && SorryStore[client].ContainsKey(STORE_KEY)) { | |
| 25 | + | // Make client "look at" the target for the calculation | |
| 26 | + | float result[3], pos[3]; | |
| 27 | + | GetClientAbsOrigin(client, pos); | |
| 28 | + | MakeVectorFromPoints(targetPos[client], pos, result); | |
| 29 | + | GetVectorAngles(result, angles); | |
| 30 | + | if(angles[0] >= 270){ | |
| 31 | + | angles[0] -= 270; | |
| 32 | + | angles[0] = (90-angles[0]); | |
| 33 | + | } else { | |
| 34 | + | if(angles[0] <= 90){ | |
| 35 | + | angles[0] *= -1; | |
| 36 | + | } | |
| 37 | + | } | |
| 38 | + | angles[1] -= 180; | |
| 39 | + | ||
| 40 | + | // PrintToServer("look at -> (%.0f %.0f %.0f) %d", targetPos[client][0], targetPos[client][1], targetPos[client][2], targetEnt[client]); | |
| 41 | + | ||
| 42 | + | if(buttons & IN_FORWARD) { | |
| 43 | + | // GetHorizontalPositionFromOrigin(pos, angles, 1.0, pos); | |
| 44 | + | float theta = DegToRad(angles[1]); | |
| 45 | + | vel[0] = 150.0 * Cosine(theta); | |
| 46 | + | vel[1] = 150.0 * Sine(theta); | |
| 47 | + | SetAbsVelocity(client, vel); | |
| 48 | + | // TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vel); | |
| 49 | + | // SetAbsOrigin(client, pos); | |
| 50 | + | return Plugin_Changed; | |
| 51 | + | } else if(buttons & IN_BACK) { | |
| 52 | + | float theta = DegToRad(angles[1]); | |
| 53 | + | vel[0] = -150.0 * Cosine(theta); | |
| 54 | + | vel[1] = -150.0 * Sine(theta); | |
| 55 | + | SetAbsVelocity(client, vel); | |
| 56 | + | } else if(buttons & IN_MOVELEFT) { | |
| 57 | + | float theta = DegToRad(angles[1] - 90.0); | |
| 58 | + | vel[0] = -150.0 * Cosine(theta); | |
| 59 | + | vel[1] = -150.0 * Sine(theta); | |
| 60 | + | SetAbsVelocity(client, vel); | |
| 61 | + | } else if(buttons & IN_MOVERIGHT) { | |
| 62 | + | float theta = DegToRad(angles[1] - 90.0); | |
| 63 | + | vel[0] = 150.0 * Cosine(theta); | |
| 64 | + | vel[1] = 150.0 * Sine(theta); | |
| 65 | + | SetAbsVelocity(client, vel); | |
| 66 | + | } | |
| 67 | + | return Plugin_Changed; | |
| 68 | + | } | |
| 69 | + | return Plugin_Continue; | |
| 70 | + | } | |
| 71 | + | ||
| 72 | + | void SetHorizontalVelocity(int client, const float heading, const float speed) { | |
| 73 | + | float theta = DegToRad(heading); | |
| 74 | + | float vel[3]; | |
| 75 | + | vel[0] += speed * Cosine(theta); | |
| 76 | + | vel[1] += speed * Sine(theta); | |
| 77 | + | SetAbsVelocity(client, vel); | |
| 78 | + | } | |
jackz / test: move to player
Last active 13 hours ago
makes player redirect movement to the nearest other player