Raised This Month: $ Target: $400
 0% 

ADV. script, need some help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 14:37   ADV. script, need some help
Reply With Quote #1

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!
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
IceMouse[WrG]
Senior Member
Join Date: Mar 2004
Old 04-23-2004 , 16:38  
Reply With Quote #2

Be more specific... Which way is it firing? If its going down then change the movetype to 5(Fly) instead of 6(Toss)
IceMouse[WrG] is offline
Send a message via AIM to IceMouse[WrG] Send a message via MSN to IceMouse[WrG] Send a message via Yahoo to IceMouse[WrG]
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 17:14   lol
Reply With Quote #3

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.
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 17:19   o yea
Reply With Quote #4

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 :\
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
IceMouse[WrG]
Senior Member
Join Date: Mar 2004
Old 04-23-2004 , 18:34  
Reply With Quote #5

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))
IceMouse[WrG] is offline
Send a message via AIM to IceMouse[WrG] Send a message via MSN to IceMouse[WrG] Send a message via Yahoo to IceMouse[WrG]
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 19:10   ic
Reply With Quote #6

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?
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
IceMouse[WrG]
Senior Member
Join Date: Mar 2004
Old 04-23-2004 , 19:24  
Reply With Quote #7

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
IceMouse[WrG] is offline
Send a message via AIM to IceMouse[WrG] Send a message via MSN to IceMouse[WrG] Send a message via Yahoo to IceMouse[WrG]
QwertyAccess
Veteran Member
Join Date: Feb 2004
Location: Enjiru Layer
Old 04-23-2004 , 19:33  
Reply With Quote #8

looks good O_o
__________________
QwertyAccess is offline
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 20:29   thx
Reply With Quote #9

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 }
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 04-23-2004 , 20:32   damn
Reply With Quote #10

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

Code:
Got a NaN velocity on RPG Rocket
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
Reply


Thread Tools
Display Modes

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 14:57.


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