AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_PreThink Crashing Server... (https://forums.alliedmods.net/showthread.php?t=12814)

BioHazardousWaste 04-25-2005 17:03

client_PreThink Crashing Server...
 
Hey all :)

I'm just trying to make someone invulnerable for a single shot (telling them they dodged it)... here's my code, not sure how it works. (I tried calling godmode from damageevent, but problem is they already do damage, then damageevent is not called again cuz they are god)

Code:
public client_PreThink(id) {     if(entity_get_int(id, EV_INT_button) & ~IN_ATTACK)    {         new Enemy = id, Victim         new Float:Distance = get_user_aiming(id, Victim)         new EnemyName[34], VictimName[34]                 get_user_name(Enemy, EnemyName, 33)         get_user_name(Victim, VictimName, 33)                 //evade         new DodgeChance = random_num(0, 100)         new DodgeMod = (PlayerSkill[Victim][SKILL_DODGE] - PlayerSkill[Enemy][SKILL_TRUESHOT])                         if(DodgeMod >= DodgeChance)         {             client_print(Victim, print_chat, "You dodged a shot by %s!", EnemyName)             client_print(0, print_console, "DodgeMod(%i)/DodgeChance(%i) = SUCCESS!", DodgeMod, DodgeChance)             client_print(Enemy, print_chat, "%s dodged your shot!", VictimName)                         set_user_godmode (Victim, 1)             return PLUGIN_HANDLED         }         else         {             client_print(0, print_console, "Skill(%i)/DodgeChance(%i) = FAILURE!", PlayerSkill[Victim][SKILL_DODGE], DodgeChance)             set_user_godmode(Victim)                        return PLUGIN_HANDLED         }     } }

Any idea whats wrong/how i can fix it/ a better way to do this?

xeroblood 04-25-2005 17:13

Use the damage event, check how much damage they did, and then add that health back to the victim!! It is easier, but it will not work for HS and stuff that does more than 100 damage.. an easy work-around is to set the users HP to something like 356, then the HUD will only show 100 HP but the user will have 356, so HS are taken care of.. then, when a users HP is below 256 just kill them!!

BioHazardousWaste 04-25-2005 17:19

I tried that xero.. cuz that's what wc3 code did, and it did not work properly (hs = kill) on top of that you are still gushing blood everywhere, and your armour gets hurt :( :(

v3x 04-25-2005 17:20

I helped him out a bit on MSN.. :)

BioHazardousWaste 04-25-2005 17:21

OK.. getting spammed with this error:

Quote:

L 04/25/2005 - 17:33:33: [AMXX] Run time error 4 (index out of bounds) on line 20 (file "ma_damageevents.inc").
added stuff for player0 to stop this eror:
Quote:


L 04/25/2005 - 17:33:16: [FUN] Player out of range (17)
L 04/25/2005 - 17:33:16: [AMXX] Native error in "set_user_godmode" on line

but i think it's checking everytime i move.. because it's checking when noone is shooting.... new code below:

Code:
public client_PreThink(id) {     if(entity_get_int(id, EV_INT_button) & ~IN_ATTACK)    {         new Victim = read_data(2)         new Enemy = id, BodyPart         new Float: distance = get_user_aiming(id, Enemy, BodyPart)         new EnemyName[34], VictimName[34]                 get_user_name(Enemy, EnemyName, 33)         get_user_name(Victim, VictimName, 33)                 if (Victim == 0 || Enemy == 0)         {             return PLUGIN_HANDLED         }                 //evade         new DodgeChance = random_num(0, 100)         new DodgeMod = (PlayerSkill[Victim][SKILL_DODGE] - PlayerSkill[Enemy][SKILL_TRUESHOT])                         if(DodgeMod >= DodgeChance)         {             client_print(Victim, print_chat, "You dodged a shot by %s!", EnemyName)             client_print(0, print_console, "DodgeMod(%i)/DodgeChance(%i) = SUCCESS!", DodgeMod, DodgeChance)             client_print(Enemy, print_chat, "%s dodged your shot!", VictimName)                         set_user_godmode (Victim, 1)             return PLUGIN_HANDLED         }         else         {             client_print(0, print_console, "Skill(%i)/DodgeChance(%i) = FAILURE!", PlayerSkill[Victim][SKILL_DODGE], DodgeChance)             set_user_godmode(Victim)                        return PLUGIN_HANDLED         }     }     return PLUGIN_HANDLED }

BioHazardousWaste 04-25-2005 18:27

Update....
 
Changed code to this:

Code:
public client_PreThink(id) {     new button = get_user_button(id)     if(button & IN_ATTACK)     {         new Victim = read_data(2)         new Enemy = id, BodyPart         new Float: distance = get_user_aiming(id, Victim, BodyPart)         new EnemyName[34], VictimName[34]                 get_user_name(Enemy, EnemyName, 33)         get_user_name(Victim, VictimName, 33)                 if (Victim == 0 || Enemy == 0 || is_user_alive(Enemy)==0 || is_user_alive(Victim)==0)         {             return PLUGIN_HANDLED         }                 //evade         new DodgeChance = random_num(0, 100)         new DodgeMod = (PlayerSkill[Victim][SKILL_DODGE] - PlayerSkill[Enemy][SKILL_TRUESHOT])                         if(DodgeMod >= DodgeChance)         {             client_print(Victim, print_chat, "You dodged a shot by %s!", EnemyName)             client_print(0, print_console, "DodgeMod(%i)/DodgeChance(%i) = SUCCESS!", DodgeMod, DodgeChance)             client_print(Enemy, print_chat, "%s dodged your shot!", VictimName)                         if(is_user_alive(Victim))             {                 set_user_godmode (Victim, 1)                 return PLUGIN_HANDLED             }         }         else         {             if(is_user_alive(Victim))             {                 client_print(0, print_console, "Skill(%i)/DodgeChance(%i) = FAILURE!", PlayerSkill[Victim][SKILL_DODGE], DodgeChance)                 set_user_godmode(Victim)                            return PLUGIN_HANDLED             }         }     }     return PLUGIN_HANDLED }

and it works fine, except for the fact that it runs around 6 - 8 times per shot (tested with usp) is there any way to stop this? I only want it ran once per shot.

EDIT:

Found this off a post and added it to help, but didn't work :cry:
Code:
public curweapon(id) {    new wpnid = read_data(2)    new clip = read_data(3)    if (lastweap[id] != wpnid){       //Changed weapons    }    else if ( lastclip[id] > clip ) {       if (wpnid != CSW_C4 && wpnid != CSW_HEGRENADE && wpnid != CSW_FLASHBANG && wpnid != CSW_SMOKEGRENADE && wpnid != CSW_KNIFE) {         //Fired a Bullet         UserFired[id] = 1       }       else         UserFired[id] = 0    }    lastclip[id] = clip    lastweap[id] = wpnid }

xeroblood 04-25-2005 23:01

Quote:

Originally Posted by BioHazardousWaste
I tried that xero.. cuz that's what wc3 code did, and it did not work properly (hs = kill) on top of that you are still gushing blood everywhere, and your armour gets hurt :( :(

Well, 356 was an example (a poor one) but it demonstrated the basics of the idea rather well.. you see, if you give a player 255 HP it will show up as 255 on the HUD, but that is the max value of the HUD display, so if you give the player 256 HP it will show up as 1 HP on the HUD (it just recycles through).. Using this idea you could set the users HP to 1356 (or something) that way a HS with an AWP + WC3 Powers won't kill the player unless your code determines that they should die; then kill them!
The only down-side is that you have to manage HP yourself, and spectators/dead people will see the users true HP as 1000+ even though they will die after 100 HP damage.. (Some people see this in-game and don't understand that, so they think people really have 1000+ hP :P)
Seems simpler then what you are attempting with PreThink, and also would be less laggy, since PreThink is always called (and usually more than once before any action is done), whereas HP management is only done when needed, as in the Damage/Death events, and any other special effects you add..

Just my 0.5 cents! :D

BioHazardousWaste 04-25-2005 23:46

ok.. i guess I could do that, but it just seems stupid to have blood gushing out of somones head and be like you dodged the bullet! also, how would you handle the loss in armour?

EDIT:
Sweet I gained another rank! on my second week here :D

KyleD 04-26-2005 02:10

Cause you post same damn much! But, you must work on a lot of plugins to have so many questions.

BioHazardousWaste 04-26-2005 21:20

lol, most of my days have been spent working on my new matrix mod... technically one plugins, with (currently) about 6 .inc files ... about 1000 lines in total so far. I'd love to help more, but I can't really without knowing how stuff works myself :(


All times are GMT -4. The time now is 16:41.

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