Raised This Month: $51 Target: $400
 12% 

Send Ent to Origin with Gravity


Post New Thread Reply   
 
Thread Tools Display Modes
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 07-22-2009 , 16:33   Re: Send Ent to Origin with Gravity
Reply With Quote #11

I've finded a site where this problem is discussed and have all answers you need. Only thing is that those calculations are to find the EndPositon, and you must extract the Gravity from there -> http://objectmix.com/java-games/7433...e-gravity.html
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-22-2009 , 16:43   Re: Send Ent to Origin with Gravity
Reply With Quote #12

Can you give full code, so i can try and test

EDIT: Here is something i made. It's showing the general prupose of velocity and gravity, if you want to set a custom angle, you must modify the code and add to calculations the angle thing that you can find in Alka's post from above.

EDIT2: Alka stop cheating xD he edited my post and added this code

EDIT3: Stop talking with yourself, you really posted this, i mean I xD

EDIT4: Fu. xD Last edited by Alka; Today at 01:07..

EDIT5: Lies! Last edited by xPaw; Today at 01:08 AM.. i have print ;o

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <xs>

#define VELOCITY 350

public plugin_init( ) {
    
register_plugin"Random Grenade Crap""I think 1.0""xPaw" );
    
    
register_clcmd"say /gren""CmdGrenade" );
}

public 
plugin_precache( )
    
precache_model"models/grenade.mdl" );

public 
CmdGrenadeid ) {
    if( !
is_user_aliveid ) )
        return 
PLUGIN_CONTINUE;
    
    new 
iEntity create_entity"info_target" );
    
    if( !
pev_validid ) )
        return 
PLUGIN_CONTINUE;
    
    
client_printidprint_chat"Creating grenade..." );
    
    
set_peviEntitypev_classname"my_super_grenade" );
    
set_peviEntitypev_solidSOLID_BBOX );
    
set_peviEntitypev_movetypeMOVETYPE_FLY );
    
set_peviEntitypev_ownerid );
    
    
set_peviEntitypev_gravity0.5 ); // hlsdk
    
set_peviEntitypev_friction0.8 ); // hlsdk
    
    
entity_set_modeliEntity"models/grenade.mdl" );
    
    
// Angles
    
new Float:vAngles];
    
pevidpev_v_anglevAngles );
    
set_peviEntitypev_anglesvAngles );
    
    
// Target Origin
    
new Float:vTargetOrigin], Float:vOrigin];
    
pevidpev_originvOrigin );
    
set_peviEntitypev_originvOrigin );
    
fm_get_aim_originidvTargetOrigin );
    
    
// Random calculations
    
new Float:vDifference], Float:vVelocity];
    
vDifference] = vTargetOrigin] - vOrigin];
    
vDifference] = vTargetOrigin] - vOrigin];
    
vDifference] = vTargetOrigin] - vOrigin];
    
    new 
Float:flLength floatsqrootfloatpowervDifference], 2.0 ) + floatpowervDifference], 2.0 ) + floatpowervDifference], 2.0 ) );
    
    
vVelocity] = vDifference] * ( VELOCITY flLength );
    
vVelocity] = vDifference] * ( VELOCITY flLength );
    
vVelocity] = vDifference] * ( VELOCITY flLength );
    
    
set_peviEntitypev_velocityvVelocity );
    
    
// Random #2
    
new Float:flTravelTime vector_lengthvDifference ) / VELOCITY;
    
set_taskflTravelTime"Land"iEntity );
    
client_printidprint_chat"Your 'grenade' should reach target origin in %.1f seconds"flTravelTime );
    
    return 
PLUGIN_CONTINUE;
}

public 
LandiEntity )
    
client_printpeviEntitypev_owner ), print_chat"Grenade #%i reached target origin."iEntity );

stock fm_get_aim_origin(indexFloat:origin[3]) {
    new 
Float:start[3], Float:view_ofs[3]
    
pev(indexpev_originstart)
    
pev(indexpev_view_ofsview_ofs)
    
xs_vec_add(startview_ofsstart)
    
    new 
Float:dest[3]
    
pev(indexpev_v_angledest)
    
engfunc(EngFunc_MakeVectorsdest)
    
global_get(glb_v_forwarddest)
    
xs_vec_mul_scalar(dest9999.0dest)
    
xs_vec_add(startdestdest)
    
    
engfunc(EngFunc_TraceLinestartdest0index0)
    
get_tr2(0TR_vecEndPosorigin)
    
    return 
1

__________________

Last edited by Alka; 07-22-2009 at 18:10.
xPaw is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-22-2009 , 18:11   Re: Send Ent to Origin with Gravity
Reply With Quote #13

Quote:
Last edited by xPaw; Today at 01:10..
LIES! All see that, oh i think forums are broked, in quote show by Me, so i LIE? *Cryes*
__________________

Last edited by Alka; 07-22-2009 at 18:14. Reason: by xPaw
xPaw is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 07-22-2009 , 21:22   Re: Send Ent to Origin with Gravity
Reply With Quote #14

Ok, i've done some tests and i got something close to results expected, but the problem is from some wrong code (rofl, life sucks) and while distance increased the accuracy decreased. I'd like to see a code for this, all you have to do is to calculate the angle of trajectory based on velocity and gravity and set the velocity in the direction of angles, but i don't get those trajectory formulas -.-' http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
madeitout
Member
Join Date: Jun 2008
Old 07-22-2009 , 22:26   Re: Send Ent to Origin with Gravity
Reply With Quote #15

yea i was never good at physics and am not getting very far with those formulas, im sure everything we need is in there but im not sure how to convert it all to cs velocitys and gravitys

thanks for the help xpaw and alka, im sure its a matter of time until someone gets it

for anyone that wants to try, here is my starting point.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <csx>
#include <fun>

#define TARGETOFFSET1    500.0
#define TARGETOFFSET2    50.0

new target_id;

public 
plugin_init()
{
    
register_forward(FM_CmdStart"fw_start"1);

    
set_task(3.0"give_nade"___"b");

    
target_id engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
set_pev(target_idpev_movetype5);
    
engfunc(EngFunc_SetModeltarget_id"models/grenade.mdl");    
}

public 
fw_start(id)
{
    if (
is_user_alive(id))
    {
        static 
Float:temp[3];
        
pev(idpev_origintemp);
        
temp[1] += TARGETOFFSET1;
        
temp[2] += TARGETOFFSET2;
        
set_pev(target_idpev_origintemp);
    }
    return 
FMRES_IGNORED;
}

public 
give_nade()
    for (new 
id 1id <= get_maxplayers(); id++)
        if (
is_user_alive(id) && !get_pdata_int(id3885))
            
give_item(id"weapon_hegrenade");

public 
grenade_throw(ident)
{
    new 
Float:temp[3];
    
pev(idpev_origintemp);
    
temp[1] += TARGETOFFSET1;
    
temp[2] += TARGETOFFSET2;

    
send_to_origin(enttemp750.0)
}

stock send_to_origin(entFloat:target_origin[3], Float:speed)
{
    if (!
pev_valid(ent))
        return 
0;

    new 
Float:entity_origin[3];
    
pev(entpev_originentity_origin);

    new 
Float:diff[3];
    
diff[0] = target_origin[0] - entity_origin[0];
    
diff[1] = target_origin[1] - entity_origin[1];
    
diff[2] = target_origin[2] - entity_origin[2];

    new 
Float:length floatsqroot(floatpower(diff[0], 2.0) + floatpower(diff[1], 2.0) + floatpower(diff[2], 2.0));

    new 
Float:velocity[3];
    
velocity[0] = diff[0] * (speed length);
    
velocity[1] = diff[1] * (speed length);
    
velocity[2] = diff[2] * (speed length);
    
set_pev(entpev_velocityvelocity);

    return 
1;

for the desired result, the nades should intersect when you throw it no matter what you set the TARGETOFFSET defines to.

Last edited by madeitout; 07-22-2009 at 22:29.
madeitout is offline
SchlumPF*
Veteran Member
Join Date: Mar 2007
Old 07-22-2009 , 22:56   Re: Send Ent to Origin with Gravity
Reply With Quote #16

this may help

PHP Code:
#include <amxmodx>
#include <engine>

#define PLUGIN_NAME "jumpit"
#define PLUGIN_VERSION "v.1.2"
#define PLUGIN_AUTHOR "dajrokan"

new Float:XY 250.0
new Float:270.0
new Float:tposs
new Float:jorig[3]
new 
Float:corig[3]
new 
Float:stack
new Float:counter
new lj false

public plugin_init() {

    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
    
register_cvar(PLUGIN_NAMEPLUGIN_VERSIONFCVAR_SERVER)

    
register_menucmd(register_menuid("\rJump It!"), 1023"action_jump")
    
register_clcmd("say /jumpit""display_jump"0" - velocity jump menu")

    return 
PLUGIN_CONTINUE
}

public 
client_PreThink(id) {

    new 
Float:vec[3]
    new 
jmp[10], dck[10], fwd[10], bck[10], lft[10], rgh[10], 1

    entity_get_vector
(idEV_VEC_velocityvec)
    
vec[2] = 0.0
    vec
[0] = vector_length(vec)
    if (
lj) {
        if (
vec[0] < 180.0) {
            
lj false
            
if (tposs 1.0)
                
client_print(0print_chat"Last tracking: %.1f units"tposs)
        } else {
            
stack += vec[0]
            
counter += 1.0
            tposs 
= (((stack counter) - 202) * 0.75) + 180
            entity_get_vector
(idEV_VEC_origincorig)
            
set_hudmessage(255255255, -1.00.000.00.10.00.01)
            
show_hudmessage(id"Speed [xy]: %.1f px/s | AV: %.1f px/sec^nTracking possibility: %.1f u."vec[0], stack countertposs)
        }
    } else {
        
set_hudmessage(25500, -1.00.000.00.10.00.01)
        
show_hudmessage(id"Speed [xy]: %.1f px/s^nJump statistic: N/A"vec[0])
    }

    if(
get_user_button(id) & IN_MOVELEFT)
        
lft "<= LEFT"
    
else {
        
lft " "
        
0
    
}

    if(
get_user_button(id) & IN_MOVERIGHT)
        
rgh "RIGHT =>"
    
else {
        
rgh " "
        
0
    
}

    if (
b)
        
set_hudmessage(25500, -1.00.1500.00.10.00.02)
    else
        
set_hudmessage(02550, -1.00.1500.00.10.00.02)

    
show_hudmessage(id"%s                            %s"lftrgh)

    if(
get_user_button(id) & IN_JUMP) {
        
jmp "^^JUMP^^"
        
if (!lj && !(get_user_oldbutton(id) & IN_JUMP)) {
            
counter 0.0
            stack 
0.0
            tposs 
0.0
            entity_get_vector
(idEV_VEC_originjorig)
            
lj true
        
}
    } else
        
jmp ""

    
if(get_user_button(id) & IN_DUCK)
        
dck "_duck_"
    
else
        
dck ""

    
set_hudmessage(2550255, -1.00.1000.00.10.00.03)
    
show_hudmessage(id"^n%s^n%s"jmpdck)

    if(
get_user_button(id) & IN_FORWARD)
        
fwd "/FORWARD\ "
    
else
        
fwd ""

    
if(get_user_button(id) & IN_BACK)
        
bck "\BACK/"
    
else
        
bck ""
    
    
set_hudmessage(255255255, -1.00.1000.00.10.00.04)
    
show_hudmessage(id"%s^n^n^n%s"fwdbck)
}

public 
action_jump(idkey) {
    switch (
key) {
        case 
0+= 1.0
        
case 1-= 1.0
        
case 2XY += 1.0
        
case 3XY -= 1.0
        
case 4jump(id)
        default: return 
PLUGIN_HANDLED
    
}
    
display_jump(id)
    return 
PLUGIN_HANDLED
}

public 
display_jump(id) {    

    new 
menuBody[512]
    new 
keys = (1<<9)
    new 
key 0

    
new len format(menuBody,511"\rJump It!\w^n^n")    

    
keys |= (1<<key)
    
key++
    
len += format(menuBody[len],511-len,"%d. + Z velocity^n"key)

    
keys |= (1<<key)
    
key++
    
len += format(menuBody[len],511-len,"%d. - Z velocity^n"key)

    
keys |= (1<<key)
    
key++
    
len += format(menuBody[len],511-len,"%d. + XY velocity^n"key)

    
keys |= (1<<key)
    
key++
    
len += format(menuBody[len],511-len,"%d. - XY velocity^n   \dZ (normal 270.0, bhop 230.0): %.1f px/sec | XY: %.0f px/sec\w^n^n"keyZXY)

    
keys |= (1<<key)
    
key++
    
len += format(menuBody[len],511-len,"%d. Jump!^n^n0. Exit"key)

    
show_menu(idkeysmenuBody)
    return 
PLUGIN_HANDLED
}

public 
jump(id) {

    new 
Float:vec[3], Float:norm[3]

    
entity_get_vector(idEV_VEC_v_anglevec)

    
norm[2] = Z
    norm
[1] = floatsin(vec[1], degrees) * XY
    norm
[0] = floatcos(vec[1], degrees) * XY

    entity_set_vector
(idEV_VEC_velocitynorm)

    return 
PLUGIN_CONTINUE

__________________

Last edited by ConnorMcLeod; 03-16-2011 at 02:28.
SchlumPF* is offline
Send a message via ICQ to SchlumPF*
madeitout
Member
Join Date: Jun 2008
Old 07-24-2009 , 07:15   Re: Send Ent to Origin with Gravity
Reply With Quote #17

hmm there doesnt seem to be anything that I can use in there schlumpf, thanks anyhow
madeitout is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:08.


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