AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ADV. script, need some help (https://forums.alliedmods.net/showthread.php?t=1331)

knekter 04-23-2004 14:37

ADV. script, need some help
 
Im making a Rocket Launcher script, and everything is going fine like the speed of the rocket and such, except one thing, the rocket doesnt fire straight. I got help from PM with his mathamatics, but we cant seen to get it to go straight. Heres the code:

Code:
//////////////////// #include <amxmodx> #include <engine> #include <fun> //////////////////// #define SPEED 10.0 //////////////////// new Float:PlayerOrigin[3] new Float:flEyeOrigin[3] new Float:flVelocity[3] new EyeOrigin[3] new OwnerID[33] new RpgID[33] new smoke //////////////////// public plugin_init(){     register_plugin("RPG Rocket","0.1","knekter")     register_concmd("rocket","rocket_init") } public plugin_precache(){     precache_model("models/rpgrocket.mdl")     smoke = precache_model("sprites/smoke.spr")     return PLUGIN_CONTINUE } public rocket_init(id){         // creates the entity     RpgID[id] = create_entity("info_target")     if(RpgID[id] == 0) return PLUGIN_HANDLED         // gives the entity some traits and values     entity_set_string(RpgID[id],EV_SZ_classname,"RPG Rocket")     entity_set_model(RpgID[id],"models/rpgrocket.mdl")     entity_get_vector(id,EV_VEC_origin,PlayerOrigin)     entity_set_origin(RpgID[id],PlayerOrigin)     entity_set_int(RpgID[id],EV_INT_solid,1)     entity_set_int(RpgID[id],EV_INT_movetype,6)         // sets the rockets owner     OwnerID[id] = entity_set_edict(RpgID[id],EV_ENT_owner,id)     get_user_origin(id,EyeOrigin,3)     flEyeOrigin[0] = float(EyeOrigin[0])     flEyeOrigin[1] = float(EyeOrigin[1])     flEyeOrigin[2] = float(EyeOrigin[2])     // creates the velocity and aiming for the rocket     flVelocity[0] = flEyeOrigin[0] - PlayerOrigin[0]     flVelocity[1] = flEyeOrigin[1] - PlayerOrigin[1]     flVelocity[2] = flEyeOrigin[2] - PlayerOrigin[2]     new Float:invLen = floatsqroot(flVelocity[0]*flVelocity[0] + flVelocity[1]*flVelocity[1] +      flVelocity[2]*flVelocity[2])     flVelocity[0]*=invLen*SPEED     flVelocity[1]*=invLen*SPEED     flVelocity[2]*=invLen*SPEED     message_begin(MSG_BROADCAST,SVC_TEMPENTITY)     write_byte(22) // TE_BEAMFOLLOW     write_short(RpgID[id]) // the entity to follow     write_short(smoke) // the sprite     write_byte(2) // life     write_byte(10) // width     write_byte(255) // red     write_byte(0) // green     write_byte(0) // blue     write_byte(255) // brightness     message_end()     entity_set_vector(RpgID[id],EV_VEC_velocity,flVelocity)     return PLUGIN_CONTINUE }

Plz help!

IceMouse[WrG] 04-23-2004 16:38

Be more specific... Which way is it firing? If its going down then change the movetype to 5(Fly) instead of 6(Toss)

knekter 04-23-2004 17:14

lol
 
No I mean if I look left, it fires my rocket up in the air way way left, if I look to the right, it fires the rocket way way right. I can see it fly hit, then bounce back also. :(

knekter 04-23-2004 17:19

o yea
 
Also as you can see I'm trying to get the rocket to fire straigh ahead of me, so its no use when it doesnt fly straight :\

IceMouse[WrG] 04-23-2004 18:34

Normally people would update the position/velocity of the entity frame-by-frame(Since entites will probably end up loosing velocity)
EDIT: So you would get the vector of Playerview - PlayerOrigin, store it to a variable, and then on every frame update the origin/velocity of it as something like Rocketorigin + (rocketvel*(length/SPEED))

knekter 04-23-2004 19:10

ic
 
I c what you mean, so I would need to user forward server_frame() if so could you give me an example using my code plz?

IceMouse[WrG] 04-23-2004 19:24

Code:
new rocketvel[33][3] new framemod = 10; new framecount = 0; public rocket_init(id) { ... new Float:length=get_vector_distance(look,origin); for(new i=0; i<3; i++)    rocketvel[id][i] = (view[i]-origin[i])*length/SPEED; ... } public server_frame() { framecount++; ... if(!(framecount%framemod)) {     for(new i=0; i<33;i++)     {         if(!rocketid[i]) continue         entity_set_vector(rocketid[i], EV_VEC_velocity, rocketvel[i])     } } .... }
Given it isn't perfect, it gives the idea

QwertyAccess 04-23-2004 19:33

looks good O_o

knekter 04-23-2004 20:29

thx
 
Thx im really getting close, now im getting 3 warnings. I know that warnings normally dont mean much, but this is a tag_mismatch on lines 50,50,51 . I dont know why, I checked everything and it doesnt want to work. Heres my new code:

EDIT** fixed tag mismatch on line 50

Code:
//////////////////// #include <amxmodx> #include <engine> #include <fun> //////////////////// #define SPEED 10.0 //////////////////// new Float:PlayerOrigin[3] new Float:flEyeOrigin[3] new Float:flVelocity[33][3] new EyeOrigin[3] new OwnerID[33] new RpgID[33] new framemod = 10 new framecount = 0 new smoke //////////////////// public plugin_init(){     register_plugin("RPG Rocket","0.1","knekter")     register_concmd("rocket","rocket_init") } public plugin_precache(){     precache_model("models/rpgrocket.mdl")     smoke = precache_model("sprites/smoke.spr")     return PLUGIN_CONTINUE } public rocket_init(id){         // creates the entity     RpgID[id] = create_entity("info_target")     if(RpgID[id] == 0) return PLUGIN_HANDLED     // gives the entity some traits and values     entity_set_string(RpgID[id],EV_SZ_classname,"RPG Rocket")     entity_set_model(RpgID[id],"models/rpgrocket.mdl")     entity_get_vector(id,EV_VEC_origin,PlayerOrigin)     entity_set_origin(RpgID[id],PlayerOrigin)     entity_set_int(RpgID[id],EV_INT_solid,1)     entity_set_int(RpgID[id],EV_INT_movetype,6)         // sets the rockets owner     OwnerID[id] = entity_set_edict(RpgID[id],EV_ENT_owner,id)     get_user_origin(id,EyeOrigin,3)         new pOrigin[3]     pOrigin[0] = floatround(PlayerOrigin[0])     pOrigin[1] = floatround(PlayerOrigin[1])     pOrigin[2] = floatround(PlayerOrigin[2])     new Float:length = get_distance(EyeOrigin,pOrigin)         for(new b = 0; b < 3; b++){         flEyeOrigin[b] = float(EyeOrigin[b])     }         for(new i = 0; i < 3; i++){         flVelocity[id][i] = (flEyeOrigin[i] - PlayerOrigin[i]) * length / SPEED     }     message_begin(MSG_BROADCAST,SVC_TEMPENTITY)     write_byte(22) // TE_BEAMFOLLOW     write_short(RpgID[id]) // the entity to follow     write_short(smoke) // the sprite     write_byte(2) // life     write_byte(10) // width     write_byte(255) // red     write_byte(0) // green     write_byte(0) // blue     write_byte(255) // brightness     message_end()     return PLUGIN_CONTINUE } public server_frame(){     framecount++     if(!(framecount%framemod)){         for(new c = 0; c < 33; c++){             if(!RpgID[c]) continue             entity_set_vector(RpgID[c],EV_VEC_velocity,flVelocity[c])         }     }     return PLUGIN_CONTINUE }

knekter 04-23-2004 20:32

damn
 
I tested it with the warnings and every server frame it says this:

Code:

Got a NaN velocity on RPG Rocket

T(+)rget 04-23-2004 23:08

Why don't you just use VelocityByAim (VexdUM) not sure if the native name has changed in AMXX, don't need serverframe or half those calculations then :D

AssKicR 04-23-2004 23:09

Quote:

Originally Posted by T(+)rget
Why don't you just use VelocityByAim (VexdUM) not sure if the native name has changed in AMXX, don't need serverframe of half those calculations then :D

it hasn't

IceMouse[WrG] 04-24-2004 01:00

Quote:

Originally Posted by T(+)rget
Why don't you just use VelocityByAim (VexdUM) not sure if the native name has changed in AMXX, don't need serverframe or half those calculations then :D

Thats basically what VelocityByAim does... Just simplified... Gets where they look and subtract from thier position and then multiply it


All times are GMT -4. The time now is 14:57.

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