AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Crossbow Help meh! (https://forums.alliedmods.net/showthread.php?t=45558)

10Stars 10-05-2006 20:21

Crossbow Help meh!
 
Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <cstrike>
 
new PLUGIN_NAME[] =    "Crossbow"
new PLUGIN_VERSION[] =  "2.9"
new PLUGIN_AUTHOR[] =  "10 $74|2$"
 
new g_cvarEnabled
new g_msgCrosshair
new bool:g_crossbow[33]
new crosshair [33]
public plugin_init()
{
        register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
        register_cvar("amx_cost","800")
        register_cvar("mp_noscoutrecoil", "1");
        register_event("ResetHUD","event_resethud","b")
        register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
        register_event("DeathMsg", "Event_Death", "a")
        register_clcmd("say /buycrossbow", "cmdBuy")
        register_forward(FM_TraceLine,"fw_traceline",1)
 
        g_cvarEnabled = register_cvar("sc_enabled","1",FCVAR_SERVER)
        g_msgCrosshair = get_user_msgid("Crosshair")
}
 
public plugin_precache()
{
        precache_model("models/v_crossbow.mdl")
}
 
public client_connect(id) g_crossbow[id] = false
public Event_Death() g_crossbow[read_data(2)] = false
 
public cmdBuy(id)
{
        new Cost = get_cvar_num("amx_cost");
        new Money = cs_get_user_money(id);
        if(!is_user_alive(id))
                client_print(id, print_chat, "Sorry, You need to be alive")
        else if(Money < Cost)
                client_print(id, print_chat, "Sorry, You need %d to buy", Cost)
        else if(g_crossbow[id])
                client_print(id, print_chat, "Gordon already sold you a crossbow")
        else
        {
                g_crossbow[id] = true
                cs_set_user_money(id, Money - Cost)
                client_print(id, print_chat, "Gordon sold you a Crossbow")
        }
        return PLUGIN_HANDLED
}
 
public Event_CurWeapon(id)
{
        if(!is_user_alive(id) || !is_user_connected(id))
                return PLUGIN_CONTINUE
               
        new temp[2], weapon = get_user_weapon(id, temp[0], temp[1])
        if(weapon == CSW_SCOUT)
        {
                if(g_crossbow[id])
                {
                        entity_set_string(id, EV_SZ_viewmodel, "models/v_crossbow.mdl")
                }
        }
        return PLUGIN_CONTINUE
}
 
public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id)
{
        if(!is_user_connected(id) || !is_user_alive(id))
        {
                return FMRES_IGNORED;
        }
 
        new victim = get_tr(TR_pHit);
 
        if(!is_user_connected(victim) || !is_user_alive(victim))
        {
                return FMRES_IGNORED;
        }
 
        new clip, ammo, weapon = get_user_weapon(id,clip,ammo);
 
        if(weapon != CSW_SCOUT || clip <= 0)
        {
                return FMRES_IGNORED;
        }
 
        new hitplace = get_tr(TR_iHitgroup);
 
        if(hitplace == HIT_LEFTARM)
        {
                set_tr(TR_iHitgroup,random_num(HIT_STOMACH,HIT_CHEST));
        }
        else if(hitplace == HIT_RIGHTARM)
        {
                set_tr(TR_iHitgroup,random_num(HIT_STOMACH,HIT_CHEST));
        }
        else if(hitplace == HIT_RIGHTLEG)
        {
                set_tr(TR_iHitgroup,random_num(HIT_STOMACH,HIT_CHEST));
        }
        else if(hitplace == HIT_STOMACH)
        {
                set_tr(TR_iHitgroup,random_num(HIT_CHEST,HIT_CHEST));
        }
        else if(hitplace == HIT_LEFTLEG)
        {
                set_tr(TR_iHitgroup,random_num(HIT_STOMACH,HIT_CHEST));
        }
       
        return FMRES_IGNORED; 
}
 
public event_resethud(id)
{
        if(is_user_alive(id)) set_crosshair(id,0);
}
 
public event_curweapon(id)
{
        if(read_data(2) != CSW_SCOUT)
        {
                set_crosshair(id,0);
        }
 
        else if(crosshair[id])
        {
                set_crosshair(id,1);
        }
}
 
public event_deathmsg()
{
        set_crosshair(read_data(2),0);
}
 
public client_PreThink(id)
{
        if(!get_pcvar_num(g_cvarEnabled)) return PLUGIN_CONTINUE;
 
        new clip, ammo, weapon = get_user_weapon(id,clip,ammo);
 
        if(weapon != CSW_SCOUT) return PLUGIN_CONTINUE;
 
        new button = entity_get_int(id,EV_INT_button);
 
        if(button & IN_ATTACK2)
        {
                // did he just press it?
                if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))
                {
                        // toggle effect
                        set_crosshair(id,!crosshair[id]);
                }
 
                entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);
        }
        if(weapon == CSW_SCOUT)
        if(!get_cvar_num("mp_noscoutrecoil"))
 
        if(get_user_button(id) & IN_ATTACK)
                entity_set_vector(id, EV_VEC_punchangle, Float:{0.0, 0.0, 0.0});
 
        return PLUGIN_CONTINUE;
}
 
public set_crosshair(id,enabled)
{
        crosshair[id] = enabled;
 
        message_begin(MSG_ONE_UNRELIABLE,g_msgCrosshair,_,id);
        write_byte(enabled);
        message_end();
}
 
public forward_traceline(Float:v1[3], Float:v2[3], noMonsters, id)
{
        if(!get_cvar_num("mp_noscoutrecoil") || !is_user_connected(id) || !is_user_alive(id))
                return FMRES_IGNORED;
 
        new hit[3], Float:fHit[3];
        get_user_origin(id, hit, 4);
        IVecFVec(hit, fHit);
 
        set_tr(TR_vecEndPos, fHit);
 
        return FMRES_IGNORED;
}

OK, now, im having a problem with the following things:::

1. With this plugin enabled it is suppossed to redirect the hits from leg/stomache/arms to chest hits for higher damage, but it does the extra damage wether you have the crossbow or not, a fix plzzz?

2. Also, the crosshair too (Thanks avalanche for making the crosshair) It unfortunately works wether you have the crossbow or not.

3. The No recoil thing, when you have the crossbow only your suppossed to have no recoil (So you can be running withthe crosshair up and shoot and hit someone) But this doesnt seem to work at all -.-

4. This isnt in the plugin at all, but i want it so that when you have the crossbow you move faster (Kinda like a speed up to about 330 or even set it to a cvar).

5. When someone says /buycrossbow i want it so that it actually gives them a scout, instead of just the upgrade so they dont have to buy the scout seperately.

Im relatively new to coding, and still pretty bad at it, can anyone help?

Current credits for help on the plugin::

Cheap_Suit-->Set up the buying of the crossbow
Avalanche--->Is the crosshair pimp

XxAvalanchexX 10-05-2006 23:16

Re: Crossbow Help meh!
 
You had a couple functions that were supposed to be called but weren't because you added your own event hooks and didn't merge them with the old ones.

For your no recoil (or no cone of fire)... I put the code into the fw_traceline function (merging the old with the new), and modified it a bit. It sets your end position at straight ahead (like before), but also checks if you are aiming at someone straight ahead, and sets those values for the traceline as well.

I cleaned up the hitgroup changing code a bit, and changed the punchangle prethink code so that it should work (maybe it did before).

Code:
#include <amxmodx> #include <fakemeta> #include <engine> #include <cstrike>   new PLUGIN_NAME[] =     "Crossbow" new PLUGIN_VERSION[] =  "2.9" new PLUGIN_AUTHOR[] =   "10 $74|2$"   new g_cvarEnabled new g_msgCrosshair new bool:g_crossbow[33] new crosshair [33] public plugin_init() {         register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)         register_cvar("amx_cost","800")         register_cvar("mp_noscoutrecoil", "1");         register_event("ResetHUD","Event_ResetHUD","b")         register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")         register_event("DeathMsg", "Event_Death", "a")         register_clcmd("say /buycrossbow", "cmdBuy")         register_forward(FM_TraceLine,"fw_traceline",1)           g_cvarEnabled = register_cvar("sc_enabled","1",FCVAR_SERVER)         g_msgCrosshair = get_user_msgid("Crosshair") }   public plugin_precache() {         precache_model("models/v_crossbow.mdl") } // merged? public client_connect(id) {         g_crossbow[id] = false         set_crosshair(id,0); } // merged public Event_Death() {         new victim = read_data(2)         g_crossbow[victim] = false         set_crosshair(victim,0); }   public cmdBuy(id) {         new Cost = get_cvar_num("amx_cost");         new Money = cs_get_user_money(id);         if(!is_user_alive(id))                 client_print(id, print_chat, "Sorry, You need to be alive")         else if(Money < Cost)                 client_print(id, print_chat, "Sorry, You need %d to buy", Cost)         else if(g_crossbow[id])                 client_print(id, print_chat, "Gordon already sold you a crossbow")         else         {                 g_crossbow[id] = true                 cs_set_user_money(id, Money - Cost)                 client_print(id, print_chat, "Gordon sold you a Crossbow")         }         return PLUGIN_HANDLED } // renamed and repositioned to fit your coding style public Event_ResetHUD(id) {         if(is_user_alive(id)) set_crosshair(id,0); } // merged public Event_CurWeapon(id) {         if(!is_user_alive(id) || !is_user_connected(id))                 return PLUGIN_CONTINUE         if(read_data(2) != CSW_SCOUT)         {                 set_crosshair(id,0);         }         else if(g_crossbow[id] && crosshair[id])         {                 set_crosshair(id,1);                 entity_set_string(id, EV_SZ_viewmodel, "models/v_crossbow.mdl")         }         return PLUGIN_CONTINUE } // merged public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id) {         if(!is_user_connected(id) || !is_user_alive(id))         {                 return FMRES_IGNORED;         }         new clip, ammo, weapon = get_user_weapon(id,clip,ammo);           if(weapon != CSW_SCOUT || clip <= 0)         {                 return FMRES_IGNORED;         }         new victim = get_tr(TR_pHit);         new hitplace = get_tr(TR_iHitgroup);         // merged/redone         if(get_cvar_num("mp_noscoutrecoil"))         {                 // set aim to straight ahead                 new hit[3], Float:fHit[3];                 get_user_origin(id,hit,4);                 IVecFVec(hit, fHit);                 set_tr(TR_vecEndPos,fHit);                 // test if we hit someone                 new target, body;                 get_user_aiming(id,target,body);                 set_tr(TR_pHit,target);                 set_tr(TR_iHitgroup,body);                 // override values for calculations below                 victim = target;                 hitplace = body;         }           if(!is_user_connected(victim) || !is_user_alive(victim))         {                 return FMRES_IGNORED;         }         // cleaned up         if(hitplace == HIT_LEFTARM || hitplace == HIT_RIGHTARM         || hitplace == HIT_RIGHTLEG || hitplace == HIT_LEFTLEG         || hitplace == HIT_STOMACH)         {                 set_tr(TR_iHitgroup,HIT_CHEST);         }                 return FMRES_IGNORED;   } public client_PreThink(id) {         if(!get_pcvar_num(g_cvarEnabled)) return PLUGIN_CONTINUE;           new clip, ammo, weapon = get_user_weapon(id,clip,ammo);           if(weapon != CSW_SCOUT) return PLUGIN_CONTINUE;           new button = entity_get_int(id,EV_INT_button);           if(button & IN_ATTACK2)         {                 // did he just press it?                 if(!(entity_get_int(id,EV_INT_oldbuttons) & IN_ATTACK2))                 {                         // toggle effect                         set_crosshair(id,!crosshair[id]);                 }                   entity_set_int(id,EV_INT_button,button & ~IN_ATTACK2);         }         // cleaned up... we couldn't be here if weapon wasn't CSW_SCOUT         if(get_cvar_num("mp_noscoutrecoil"))         {                 if(button & IN_ATTACK)                         entity_set_vector(id, EV_VEC_punchangle, Float:{0.0, 0.0, 0.0});         }           return PLUGIN_CONTINUE; }   public set_crosshair(id,enabled) {         crosshair[id] = enabled;           message_begin(MSG_ONE_UNRELIABLE,g_msgCrosshair,_,id);         write_byte(enabled);         message_end(); }

Cheers!

SweatyBanana 10-06-2006 00:49

Re: Crossbow Help meh!
 
I have a question...Is there any other crosshair available other than the spec one?

10Stars 10-06-2006 01:25

Re: Crossbow Help meh!
 
Yeah, even if it was a download, maybe a sprite download? it would be incredibly small for a download so it wouldnt be a big deal.

10Stars 10-06-2006 01:45

Re: Crossbow Help meh!
 
Hmm, random crashes with the code you gave back Avalanche.

Also the crosshair still appears with a regular scout

It crashed everytime i tried to get someone else to connect to check out the damage, so im not sure about that.

SweatyBanana 10-06-2006 09:04

Re: Crossbow Help meh!
 
Check your logs 10stars.

XxAvalanchexX 10-06-2006 12:32

Re: Crossbow Help meh!
 
Quote:

Originally Posted by SweatyBanana (Post 388101)
I have a question...Is there any other crosshair available other than the spec one?

No. The client dll doesn't draw a regular crosshair when the scout is out, that's how it's coded. You can't modify the client dll, so there isn't any way to change this.

Half-Life has a message named Crosshair, which you can use to turn the spectating crosshair on and off. That is it's intended functionality. All you do is send it: 1 (turn it on), 0 (turn it off), you can't specify what sprite to draw, as it's set in the client dll.

So, what I do is send the user the Crosshair message with a value of 1, which turns on their spectating crosshair. You couldn't add any custom sprite displays unless you could modify the client dll.

As for crashing when someone connects, maybe it's because it's trying to send them a message on client_connect. Comment out set_user_crosshair(id,0) in the client_connect code and see if it still crashes.

And I forgot that you wanted the effects to work only with the "crossbow". So, on all the checks that sees if they are using CSW_SCOUT, add "&& g_crossbow[id]" or something, which means all the checks to see if they DON'T have a scout should add "|| !g_crossbow[id]".


All times are GMT -4. The time now is 04:52.

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