AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Longest Jump (https://forums.alliedmods.net/showthread.php?t=220630)

ironskillz1 07-12-2013 16:05

Longest Jump
 
How can i check who did the longest jump?


Exemple:

If i jumped 240 units

And my freind jumped 235 units

How can i find out that i jumped farest?



I already got the code that shows units, i only need to find out who jumped farest


Here is the code if someone want to use it anyways
Code:

public gocheck(id) {
 gInAir[id] = false
}
public fwdPlayerPreThink(id) {
 if( is_user_alive(id) ) {
  static flags, buttons, oldbuttons
  flags = pev(id, pev_flags)
  buttons = pev(id, pev_button)
  oldbuttons = pev(id, pev_oldbuttons)
  static Float:fGravity
  pev(id, pev_gravity, fGravity)
  pev(id, pev_angles, angle)
  old_angle1[id] = angle[1]
  if( gInAir[id] == true && !(flags&FL_ONGROUND) ) {
  static i
  for( i = INFO_ZERO; i < 2; i++ ) {
    if( (vFramePos[id][i][0] == 0
    && vFramePos[id][i][1] == 0
    && vFramePos[id][i][2] == 0
    && vFrameSpeed[id][i][0] == 0
    && vFrameSpeed[id][i][1] == 0
    && vFrameSpeed[id][i][2] == 0)
    || (i == 1) ) {
    pev(id, pev_origin, vOrigin)
    vFramePos[id][i][0] = vOrigin[0]
    vFramePos[id][i][1] = vOrigin[1]
    vFramePos[id][i][2] = vOrigin[2]
    pev(id, pev_velocity, vVelocity)
    vFrameSpeed[id][i][0] = vVelocity[0]
    vFrameSpeed[id][i][1] = vVelocity[1]
    vFrameSpeed[id][i][2] = vVelocity[2]
    i=2
    }
  }
  }
  pev(id, pev_velocity, vVelocity)
  if( flags&FL_ONGROUND && flags&FL_INWATER )
  vVelocity[2] = 0.0
  pev(id, pev_origin, vOrigin)
  fDistance = get_distance_f(vOldOrigin[id], vOrigin)
  pev(id, pev_origin, vOldOrigin[id])
  pev(id, pev_velocity, vVelocity)
  if( vVelocity[2] != 0 )
  vVelocity[2]-=vVelocity[2]
  if( pev(id, pev_movetype) != MOVETYPE_WALK
  || fGravity != 1.0
  || pev(id, pev_waterlevel) >= 2
  || fDistance > 20 ) {
  gocheck(id)
  return FMRES_IGNORED
  }
  if( !(flags&FL_ONGROUND) )
  lasttime[id] = get_gametime()
  if( buttons&IN_JUMP
  && !(oldbuttons&IN_JUMP)
  && flags&FL_ONGROUND
  && gInAir[id] == false ) {
  set_task(0.8,"gocheck", id)
  weaponspeed = pev(id, pev_maxspeed)
  jumptime[id] = get_gametime()
  gInAir[id] = true
  pev(id, pev_origin, vOrigin)
  vJumpedAt[id][0] = vOrigin[0]
  vJumpedAt[id][1] = vOrigin[1]
  vJumpedAt[id][2] = vOrigin[2]
  strafes[id] = INFO_ZERO
  turning_right[id] = false
  turning_left[id] = false
  strafing_aw[id] = false
  strafing_sd[id] = false
  static i
  for( i = INFO_ZERO; i < 2; i++ ) {
    vFramePos[id][i][0] = 0.0
    vFramePos[id][i][1] = 0.0
    vFramePos[id][i][2] = 0.0
    vFrameSpeed[id][i][0] = 0.0
    vFrameSpeed[id][i][1] = 0.0
    vFrameSpeed[id][i][2] = 0.0
  }
  }
  else if( flags&FL_ONGROUND
  && gInAir[id] == true ) {
  set_task(0.5,"gocheck", id)
  gInAir[id] = false
  pev(id, pev_origin, vOrigin)
  fDistance1 = get_distance_f(vJumpedAt[id], vOrigin)+32.0625
  if( !(vFramePos[id][0][2] > vOrigin[2]) )
    return FMRES_IGNORED
  rLandPos[2] = vFrameSpeed[id][0][2] * vFrameSpeed[id][0][2] + (1600 * (vFramePos[id][0][2] - vOrigin[2]))
  rDistance[0] = (floatsqroot(rLandPos[2]) * -1) - vFrameSpeed[id][1][2]
  rDistance[1] = 800.000000*-1
  frame2time = floatdiv(rDistance[0], rDistance[1])
  if( vFrameSpeed[id][1][0] < 0 )
    vFrameSpeed[id][1][0] = vFrameSpeed[id][1][0]*-1
  rDistance[0] = frame2time*vFrameSpeed[id][1][0]
  if( vFrameSpeed[id][1][1] < 0 )
    vFrameSpeed[id][1][1] = vFrameSpeed[id][1][1]*-1
  rDistance[1] = frame2time*vFrameSpeed[id][1][1]
  if( vFramePos[id][1][0] < vOrigin[0] )
    rLandPos[0] = vFramePos[id][1][0] + rDistance[0]
  else
    rLandPos[0] = vFramePos[id][1][0] - rDistance[0]
  if( vFramePos[id][1][1] < vOrigin[1] )
    rLandPos[1] = vFramePos[id][1][1] + rDistance[1]
  else
    rLandPos[1] = vFramePos[id][1][1] - rDistance[1]
  if( is_in_duck(id) )
    vOrigin[2]+=18.0
  rLandPos[2] = vOrigin[2]
  frame2time += (lasttime[id]-jumptime[id])
  if( vOrigin[2] == vJumpedAt[id][2] ) {
    if( is_in_duck(id) && !(frame2time > 0.71 && frame2time < 0.77) )
    vOrigin[2] = vOrigin[2]*-1
    else if( !(is_in_duck(id)) && !(frame2time > 0.65 && frame2time < 0.70) )
    vOrigin[2] = vOrigin[2]*-1
  }
  fDistance2 = get_distance_f(vJumpedAt[id], rLandPos)+32.0625
  if( fDistance1 > fDistance2 ) {
    fDistance = fDistance2
    vOrigin[0] = rLandPos[0]
    vOrigin[1] = rLandPos[1]
  }
  else
    fDistance = fDistance1
  if( vJumpedAt[id][2] == vOrigin[2]
  && fDistance > 200
  && !(fDistance > 280) ) {
    static i, name[33], strdist[128]
    get_user_name(id, name, 31)
    num_to_word(floatround(fDistance, floatround_floor), strdist, 127)
    for( i = INFO_ONE; i < 33; i++ ) {
    if( i == id && gHasLjStats[i] ) {
      set_hudmessage(255, 255, 255, 0.05, 0.5, 0, 0.0, 2.0, 0.1, 0.1, 2)
      if(weaponspeed != 250.0) {
      ColorChat( 0, GREY, "%s ^4 %s ^3jumped ^4 %.3f ^3units with^4 %i ^3strafes!", prefix, name, fDistance, strafes[id] )
      }
      else if(225 < fDistance < 280)
      {
      show_hudmessage(id, "Distance: %.3f units^nStrafes: %i", fDistance, strafes[id] )
      if(fDistance > 210)
      {
        ColorChat( 0, GREY, "%s ^4 %s ^3jumped ^4 %.3f ^3units with^4 %i ^3strafes!", prefix, name, fDistance, strafes[id] )
      }
      }
    }
    }
  }
  gInAir[id] = false
  }
  else if( flags&FL_ONGROUND
  && gInAir[id] == false ) {
  pev(id, pev_velocity, vVelocity)
  vVelocity[2]-=vVelocity[2]
  if( vector_length(vVelocity) >= 312 )
    set_task(0.5,"gocheck", id)
  gInAir[id] = false
  }
  if( flags&FL_ONGROUND ) {
  static ClassName[32]
  pev(pev(id, pev_groundentity), pev_classname, ClassName, 32)
  if( equal(ClassName, "func_train") || equal(ClassName, "func_door") || equal(ClassName, "func_door_rotating") || equal(ClassName, "func_conveyor") ) {
    gocheck(id)
    set_task(0.4,"gocheck", id)
  }
  if( OnGround[id] == false ) {
    pev(id, pev_origin, vOrigin)
    if( buttons&IN_JUMP
    && !(oldbuttons&IN_JUMP) )
    set_task(0.4,"gocheck", id)
    OnGround[id] = true
  }
  }
  if( !(flags&FL_ONGROUND) )
  OnGround[id] = false
 }
 return FMRES_IGNORED
}
public fwdPlayerPostThink(id) {
 if( is_user_alive(id) ) {
  static buttons, flags
  buttons = pev(id, pev_button)
  flags = pev(id, pev_flags)
  if( flags&FL_ONGROUND
  && (gInAir[id] == true
  || OnGround[id] == false) )
  fwdPlayerPreThink(id)
  pev(id, pev_angles, angle)
  if( old_angle1[id] > angle[1] ) {
  turning_left[id] = false
  turning_right[id] = true
  }
  else if( old_angle1[id] < angle[1] ) {
  turning_left[id] = true
  turning_right[id] = false
  }
  else {
  turning_left[id] = false
  turning_right[id] = false
  }
  if( strafing_aw[id] == false
  && (buttons&IN_MOVELEFT
  || buttons&IN_FORWARD)
  && (turning_left[id] == true
  || turning_right[id] == true )
  && !(buttons&IN_MOVERIGHT
  || buttons&IN_BACK) ) {
  strafing_aw[id] = true
  strafing_sd[id] = false
  strafes[id] += INFO_ONE
  }
  else if( strafing_sd[id] == false
  && (buttons&IN_MOVERIGHT
  || buttons&IN_BACK)
  && (turning_left[id] == true
  || turning_right[id] == true )
  && !(buttons&IN_MOVELEFT
  || buttons&IN_FORWARD) ) {
  strafing_aw[id] = false
  strafing_sd[id] = true
  strafes[id] += INFO_ONE
  }
  pev(id, pev_velocity, vVelocity)
  vVelocity[2] = 0.0
 }
}
public fwdTouch(ent, id) {
 static ClassName[32]
 if( pev_valid(ent) ) {
  pev(ent, pev_classname, ClassName, 31)
 }
 static ClassName2[32]
 if( pev_valid(id) ) {
  pev(id, pev_classname, ClassName2, 31)
 }
 if( equal(ClassName2, "player") ) {
  if( pev(id, pev_groundentity) == ent && (gInAir[id] || !OnGround[id]) ) {
  if( pev(id, pev_flags)&FL_ONGROUND ) {
    if( get_gametime() > (jumptime[id]+0.1) )
    fwdPlayerPreThink(id)
  }
  }
  if( equal(ClassName, "func_train") || equal(ClassName, "func_door") || equal(ClassName, "func_door_rotating") || equal(ClassName, "func_conveyor") ) {
  gocheck(id)
  set_task(0.4,"gocheck", id)
  }
 }
}
stock is_in_duck(player) {
 if( !pev_valid(player)  )
  return 0
 static Float:absmin[3], Float:absmax[3]
 pev(player, pev_absmin, absmin)
 pev(player, pev_absmax, absmax)
 absmin[2]+=64.0
 if( absmin[2] < absmax[2] )
  return 0
 return 1
}


Backstabnoob 07-12-2013 16:08

Re: Longest Jump
 
Compare the results?

ironskillz1 07-12-2013 16:30

Re: Longest Jump
 
Quote:

Originally Posted by Backstabnoob (Post 1989562)
Compare the results?

Yeah but how can i do that?


i want the highest number to "win"

mottzi 07-12-2013 23:40

Re: Longest Jump
 
how do you store the the jumplenghts? In a global array?

ironskillz1 07-14-2013 13:31

Re: Longest Jump
 
Quote:

Originally Posted by mottzi (Post 1989753)
how do you store the the jumplenghts? In a global array?

new Float:fDistance

mottzi 07-14-2013 15:44

Re: Longest Jump
 
You have to save every record (means the record of EVERY player in an array). then you can get the "longes" jump with something like this:

PHP Code:

new max get_maxplayers()
new 
Float:longest g_record[1]

for(new 
i=2i<=max;i++){
    if(
g_record[i] > longestlongest g_record[i]


now in "longest" the longest jump is stored

ironskillz1 07-25-2013 13:35

Re: Longest Jump
 
Quote:

Originally Posted by mottzi (Post 1990874)
You have to save every record (means the record of EVERY player in an array). then you can get the "longes" jump with something like this:

PHP Code:

new max get_maxplayers()
new 
Float:longest g_record[1]
 
for(new 
i=2i<=max;i++){
    if(
g_record[i] > longestlongest g_record[i]


now in "longest" the longest jump is stored

Can you explain more i dont get it :s

UchihaSkills 07-25-2013 16:12

Re: Longest Jump
 
You didnt saved it on all in an array


All times are GMT -4. The time now is 06:26.

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