AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weapon toss units (https://forums.alliedmods.net/showthread.php?t=131763)

outsiderlv 07-08-2010 15:24

Weapon toss units
 
How can i get the distance from the player who dropped a deagle between the drop pont of the deagle? I think its simular to lj stats.

drekes 07-08-2010 16:14

Re: Weapon toss units
 
This is how i did it.
PHP Code:

#include <amxmodx>
#include <engine>

#pragma semicolon 1
#define VERSION "1.0"

new Floatthroworigin[3];
new 
Floatdroporigin[3];

public 
plugin_init()
{
    
register_plugin("Drop Distance"VERSION"Drekes");
    
    
register_touch("weaponbox""worldspawn""Fwd_Weapon_Touch");
    
    
register_clcmd("drop""cmd_drop");
}

public 
cmd_drop(id)
    
entity_get_vector(idEV_VEC_originthroworigin);
    
public 
Fwd_Weapon_Touch(weaponworld)
{
    
entity_get_vector(weaponEV_VEC_origindroporigin);
    
    
check_distance();
}

public 
check_distance()
{
    new 
Floatdistance get_distance_f(throworigindroporigin);
    
    
client_print(0print_chat"Drop distance: %.1f"distance);



outsiderlv 07-08-2010 23:47

Re: Weapon toss units
 
And how can i do it with spray? From the ground to the middle of a spray. I tried to do something with impulse and decal, but no results.. <_<

Hunter-Digital 07-09-2010 03:08

Re: Weapon toss units
 
This might help: http://forums.alliedmods.net/showthread.php?p=58076

Basically, you hook the SVC_TEMPENTITY message, check for first param is it's TE_PLAYERDECAL (112), get the origin and calculate, easy.

outsiderlv 07-09-2010 03:55

Re: Weapon toss units
 
Damnn.. 2 hard for me.. Can u make a sample? I think register_event("23", "newspray", "a", "1=112") is the main thing..

Hunter-Digital 07-09-2010 05:09

Re: Weapon toss units
 
Actally it's hooking the SVC_TEMPENTITY (wich is 23) message and first param as TE_PLAYERDECAL... wich is 112.

TE_PLAYERDECAL params from include/message_const.inc
Code:

#define TE_PLAYERDECAL              112
// write_byte(TE_PLAYERDECAL)
// write_byte(playerindex)
// write_coord(position.x)
// write_coord(position.y)
// write_coord(position.z)
// write_short(entity???)
// write_byte(decal number)
// [optional] write_short(model index)

the #define is the define for using it, the rest with // are informations about message parameters, that are between message_begin(msgtype, SVC_TEMPENTITY) and message_end()...

So... after knowing that I would do the following:

PHP Code:

#include <amxmodx>
#include <engine>

public plugin_init()
{
      
/* SVC_TEMPENTITY (event #23) event, trigger if parameter 1 is equal to 112 (TE_PLAYERDECAL) */
      
register_event("23""player_spray""a""1=112")
}

public 
player_spray()
{
      new 
id read_data(2/* as seen in the include, player index is the second parameter */
      
new iOrigin[3]

      
iOrigin[0] = read_data(3/* and of course, the coordinates... */
      
iOrigin[1] = read_data(4)
      
iOrigin[2] = read_data(5)

      
/* you can get the rest of parameters too if you need them */

      /* now, what you needed... distance... */

      
new iPlayerOrigin[3]

      
get_user_origin(idiPlayerOrigin)

      new 
iDistance get_distance(iPlayerOriginiOrigin)

      
client_print(idprint_chat"Distance to your spray: %d"iDistance)


easy :}

Note: not actually tested, but should work.

outsiderlv 07-09-2010 05:38

Re: Weapon toss units
 
It says something about argument type mismatch (argument 1) @ register_event(SVC_TEMPENTITY, "player_spray", "a", "1=112")

Hunter-Digital 07-09-2010 05:54

Re: Weapon toss units
 
Yeah, SVC_TEMPENTITY is an int, not a string xD fixed and tested, works just fine.

outsiderlv 07-09-2010 06:22

Re: Weapon toss units
 
It shows 0.000 units all the time.. Works only if %d ...<_< I need %.3f :D
And yes.. i need to measure the distance not from player, but from ground.

Hunter-Digital 07-09-2010 14:10

Re: Weapon toss units
 
Use get_distance_f then if you want float... the code I wrote works because I tested it... but detects distance from player to spray... you want from ground (walkable ground, not wall ?) to the entity ? I dunno, trace line or something... from the player's origin so that it doesn't collide with something else down the wall.


All times are GMT -4. The time now is 07:05.

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