AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to show sprites (https://forums.alliedmods.net/showthread.php?t=184609)

Randomize 05-06-2012 20:13

How to show sprites
 
Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>
#include <cstrike>
#include <fakemeta>
#include <fakemeta_stocks>

#define PLUGIN    "CSPB Helmet Protection, Cheap_Suit, tmen13"
#define AUTHOR    "Cheap_Suit"
#define VERSION    "1.0"

#define HelmetKB    50.0

#define OFFSET_ARMORTYPE 112
#define fm_get_user_armor_type(%1) get_pdata_int(%1, OFFSET_ARMORTYPE)

new HELMET_SOUND[] = "debris/metal6.wav"
new bool:g_has_helmet[33]

new MAX_PLAYERS;

new const SOUND[] = "misc/helmet.wav";

public plugin_cfg()
{
    MAX_PLAYERS = get_maxplayers();
}
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    RegisterHam(Ham_TakeDamage, "player", "playerTakeDamage");   
   
    register_plugin("Ultimate Helmet", "1.1", "Carbine/Cheap_Suit")
    register_cvar("amx_ultimate_helmet", "1")
    register_cvar("amx_ultimate_helmet_cost", "0")
   
    register_clcmd("say /buyhelmet", "HelmetBuy")
    register_clcmd("say /drophelmet", "HelmetDrop")
   
    register_concmd("buyhelmet", "HelmetBuy")
    register_concmd("drophelmet", "HelmetDrop")
   
    register_forward(FM_TraceLine, "fw_traceline", 1)
    register_event("ResetHUD", "newRound", "b")
}

public plugin_modules() {
    require_module("FakeMeta")
    require_module("cstrike")
    require_module("engine")
}
   
public plugin_precache() {
    precache_sound(HELMET_SOUND)
    precache_sound(SOUND)   
    precache_model("models/cspb/headgear.mdl")
}

public client_putinserver(id) {
    g_has_helmet[id] = false
}

public client_disconnect(id) {
    g_has_helmet[id] = false
}

public newRound()
{
    new helmet = find_ent_by_class(-1, "helmet")
    while(helmet) {
        remove_entity(helmet)
        helmet = find_ent_by_class(helmet, "helmet")
    }
}
 
public HelmetBuy(id)
{
    if(client_buy(id, get_cvar_num("amx_ultimate_helmet_cost"), "Helmet") == true)  {
        client_cmd(id, "spk items/gunpickup2.wav")
        g_has_helmet[id] = true
    }
    return PLUGIN_HANDLED
}

public HelmetDrop(id)
{
    if(g_has_helmet[id] == true) {
        g_has_helmet[id] = false
        DropHelmet(id)
    }
    else {
        client_print(id, print_chat, "[CSPB] You aren't wear a headgear")
    }
    return PLUGIN_HANDLED
}

public fw_traceline(Float:TemporarySlot1[3], Float:TemporarySlot2[3], TemporarySlot3, 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
       
    if(get_user_team(id) == get_user_team(victim))
        return FMRES_IGNORED

    new clip, ammo
    get_user_weapon(id, clip, ammo)
    if(clip > 0)
    {
        if(get_user_button(id) & IN_ATTACK)
        {
            if(g_has_helmet[victim] == true)
            {
                new hitplace = get_tr(TR_iHitgroup)
                if(hitplace == HIT_HEAD)
                {   
                    set_tr(TR_iHitgroup, random_num(HIT_LEFTLEG, HIT_RIGHTLEG))
                    emit_sound(victim, CHAN_BODY, HELMET_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
                    entity_set_vector(victim, EV_VEC_punchangle, Float:{-HelmetKB, 0.0, HelmetKB})
                    g_has_helmet[id] = false
                    DropHelmet(victim)
                }
            }
        }
    }
    return FMRES_IGNORED
}

public player_die()
{
    new victim = read_data(2)
    if(g_has_helmet[victim] == true) {
        g_has_helmet[victim] = false
        DropHelmet(victim)
    }
}

public pfn_touch(ptr, ptd)
{
    if(!is_valid_ent(ptd) || !is_valid_ent(ptr))
        return PLUGIN_CONTINUE
       
    if(!is_user_connected(ptd) || !is_user_alive(ptd))
        return PLUGIN_CONTINUE

    new classname[32]
    entity_get_string(ptr, EV_SZ_classname, classname, 31)
    if(equal(classname, "helmet"))
    {
        if(g_has_helmet[ptd] == false)
        {
            client_cmd(ptd, "spk items/gunpickup2.wav")
            g_has_helmet[ptd] = true
            remove_entity(ptr)
        }
    }
    return PLUGIN_CONTINUE
}

stock DropHelmet(id)
{
    if(g_has_helmet[id] == true)
        g_has_helmet[id] = false

    new Float:vAim[3], Float:vOrigin[3]
    entity_get_vector(id, EV_VEC_origin, vOrigin)
    VelocityByAim(id, random_num(100, 200), vAim)

    vOrigin[0] += vAim[0]
    vOrigin[1] += vAim[1]
    vOrigin[2] += 30.0

    new helmet = create_entity("info_target")
    if(helmet > 0)
    {
        entity_set_string(helmet, EV_SZ_classname, "helmet")
        entity_set_model(helmet, "models/cspb/helmet.mdl")   
        entity_set_size(helmet, Float:{-2.5, -2.5, -1.5}, Float:{2.5, 2.5, 1.5})
        entity_set_int(helmet, EV_INT_solid, 2)
        entity_set_int(helmet, EV_INT_movetype, 6)
        entity_set_vector(helmet, EV_VEC_origin, vOrigin)
    }
}

stock bool:client_buy(id, cost, item[])
{
    if(get_cvar_num("amx_ultimate_helmet") >= 1)
    {
        new money = cs_get_user_money(id)
        if(money < cost)
        {
            client_print(id, print_chat, "[CSPB Non NST] You need $%d to buy a %s", cost, item)
            return false
        }
        else if(!is_user_alive(id))
        {
            client_print(id, print_chat, "[CSPB Non NST] You must be alive to buy a %s", item)
            return false
        }
        else if(g_has_helmet[id] == true)
        {
            client_print(id, print_chat, "[CSPB Non NST] You are already has a %s", item)
            return false
        }
        else
        {
            cs_set_user_money(id, money - cost)   
            client_print(id, print_chat, "[CSPB Non NST] You bought a %s", item)
            return true
        }
        return false
    }
    else
    {
        client_print(id, print_chat, "[CSPB Non NST] Sorry, the helmet shop is not on")
        return false
    }
    return false
}
public playerTakeDamage(victim, inflictor, attacker, Float:fDamage, bitDamage)
{
    if( (1 <= victim <= MAX_PLAYERS) && (1 <= attacker <= MAX_PLAYERS) && is_user_connected(victim))
    {
        new gun,hitZone
        get_user_attacker(victim,gun,hitZone)
               
        if( (fm_get_user_armor_type(victim) & 2) && (hitZone == HIT_HEAD))
        {
            new Float:origin[3];
            pev(victim,pev_origin,origin);
           
            EF_EmitAmbientSound(0,origin,SOUND, 1.0, ATTN_NORM, 0 , PITCH_NORM);
        }
    }
}

How to show sprites when hit the helmet?

<VeCo> 05-07-2012 09:40

Re: How to show sprites
 
Make a tempentity message TE_SPRITE.

Randomize 05-07-2012 10:07

Re: How to show sprites
 
public test(id){
new
origin[3]
get_user_origin(id, origin)
message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
write_byte(TE_SPRITETRAIL)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2]-10)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2])
write_short(g_sprite)
write_byte(3)
write_byte(20)
write_byte(1)
write_byte(7)
write_byte(0)
message_end()
}


This code? :)

<VeCo> 05-07-2012 10:12

Re: How to show sprites
 
PHP Code:

#define TE_SPRITE                   17       // Additive sprite, plays 1 cycle
// write_byte(TE_SPRITE)
// write_coord(position.x)
// write_coord(position.y)
// write_coord(position.z)
// write_short(sprite index) 
// write_byte(scale in 0.1's) 
// write_byte(brightness) 


Randomize 05-07-2012 10:27

Re: How to show sprites
 
Code:

/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <engine>
new sprite;

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"
#define TE_SPRITE                  17     
public plugin_init() {
 register_plugin(PLUGIN, VERSION, AUTHOR)
 register_clcmd("say /sprite","cmdtest")
 
}
public plugin_precache()
{
sprite = precache_model("sprites/flame.spr")
}
public cmdtest(id)
{
new origin[3];
origin[0] = get_user_origin(id,origin,0)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
write_byte(TE_SPRITE);
write_coord(origin[0]);
write_coord(origin[1]);
write_coord(origin[2]);
write_short(sprite);
write_byte(1);
write_byte(127);
message_end();
}

This code is correct?

<VeCo> 05-07-2012 10:34

Re: How to show sprites
 
PHP Code:

new origin[3];
get_user_origin(id,origin,0)
message_begin(MSG_BROADCASTSVC_TEMPENTITY);
write_byte(TE_SPRITE);
write_coord(origin[0]);
write_coord(origin[1]);
write_coord(origin[2]);
write_short(sprite);
write_byte(1);
write_byte(127);
message_end(); 

You could test it yourself...

Randomize 05-07-2012 10:48

Re: How to show sprites
 
Well it is work.. But it is flashing.. how to fix that?

<VeCo> 05-07-2012 10:49

Re: How to show sprites
 
What do you mean by 'flashing'?

Randomize 05-07-2012 10:55

Re: How to show sprites
 
when i type /sprite in game, the sprite just showed only 0.1 seconds..

<VeCo> 05-07-2012 10:56

Re: How to show sprites
 
Yes, TE_SPRITE plays only 1 frame. What exactly do you want to do?


All times are GMT -4. The time now is 00:29.

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