What's new

Discussion [CODE] HEX-F Coding: Distance Text Function

K

Antic

Enthusiast
Messages
331
Reaction score
81
Hey its Antic from HEx-F Coding

Thanks to
pcfreak30
george777
zy0n

This function allows you create very easy distance functions
E.X.: When you get near a gun it says "Press X to pick up Gun"
Well thats what this function is
Code:
createDistanceText(ref, dest, dist, msg, callfunc, button, func)
-----------------------------------------------------------------------------------------
ref - STRING - So basically you can do alot of thigs with this. The "ref" var is particularly useful. Say you create a health house. you want them to be able to get health increase only one time. Simply make the ref something like, "healthboost". Then when the function for the heath boost is called, have it run this:

Code:
self notify("dist_heathboost");

That will end the whole distance function and they will no longer be able to get a health boost until that it is re-ran/re-created.
-----------------------------------------------------------------------------------------
dest - INTEGER - destination - the area you will around to make the message pop up
-----------------------------------------------------------------------------------------
dist - INTEGER - distance - How far you need to be from dest for the message to pop up
-----------------------------------------------------------------------------------------
msg - STRING - the message that will show up when u get near dest
-----------------------------------------------------------------------------------------
callfunc - BOOLEAN - if true, you put in a function that you will want to run when you press X - if false leave func blank
-----------------------------------------------------------------------------------------
button - STRING - the button you want to press when you get near dest
-----------------------------------------------------------------------------------------
func - STRING - the function name you want to run when u hit the button, E.X.: ::teleport
-----------------------------------------------------------------------------------------
put this in onPlayerSpawn():
Code:
self thread initButtons();
self thread monitor_PlayerButtons();
//createDistanceText(Ur code here);
EXAMPLE:
Code:
createDistanceText("carepkg", (14069, 1649.49, 40.1254), 60, "Press [{+reload}] to Teleport", true, "X", ::doTeleport);
CODE:
Code:
initButtons(){
level.buttonName = strToArray("X;Y;A;B;Up;Down;Left;Right;RT;LT;RB;LB;RS;LS", ";");
level.buttonAction = [];
actions = strToArray("+usereload;weapnext;+gostand;+melee;+actionslot 1;+actionslot 2;+actionslot 3;+actionslot4;+attack;+speed_throw;+frag;+smoke;+stance;+breathe_sprint", ";");
foreach(button in level.buttonName ) level.buttonAction[button] = actions[level.buttonAction.size];
}

monitor_PlayerButtons()
{
self.buttonPressed = [];
self.buttonPressedCombo = [];
self.comboPressed = [];
foreach ( Button in level.buttonName )self thread monitorButtons( Button );
}

monitorButtons( Button )
{
self endon ( "disconnect" );
self endon ( "death" );
self notifyOnPlayerCommand( button, level.buttonAction[button] );
self.buttonPressed[button] = false;
self.buttonPressedCombo[button] = false;
for ( ;; ) {
self waittill( Button );
self.buttonPressed[ Button ] = true;
self.buttonPressedCombo[ Button ] = true;
self notify( "buttonPressed" );
wait .05;
self.buttonPressed[ Button ] = false;
self.buttonPressedCombo[ Button ] = false;
}
}

isButtonPressed( buttonID )
{
if (self.buttonPressed[ buttonID ]) {
self.buttonPressed[ buttonID ] = false;
return true;
} else return false;
}

strToArray(string, del)
{
array = [];
values = strTok( string, del);
foreach (value in values) array[array.size] = value;
return array;
}

createDistanceText(ref, dest, dist, msg, callfunc, button, func)
{
if(self.sessionstate == "playing")
{
disp = 0;
show = 0;
self endon("death");
self endon("dist_" + ref);
for(;;)
{
if(distance(self gettagorigin("j_head"), dest) < dist)
{
if(isButtonPressed(button) && callfunc == true)
{
self thread [[func]]();
}
if(show == 0)
{
disp= self createFontString( "hudbig", 1 );
disp setPoint("CENTER","BOTTOM", 0, -100);
disp setText(msg);
self thread destroyOnDeath(disp);
show = 1;
}
}
else
{
if(show == 1)
{
disp destroy();
show = 0;
}
}
wait 0.05;

}
}	
}

destroyOnDeath( elm )
{
self waittill("death");
elm destroy();
}
VID:
 
A

Android

Just Imagine
Messages
2,585
Reaction score
662
cool this is really in depth coding ( more in depth than Most of the stuff posted) Good job
 
K

kiwimoosical

Getting There
Messages
1,123
Reaction score
474
Not as advanced as pcfreak made it out to be :tongue:

But noice nonetheless :tongue:
 
I

Isucklotsofdick

Enthusiast
Messages
610
Reaction score
281
Mk so thanks for the thread antic. FYI, I wrote this in about 45 mins. Antic originally came to me to debug his messy version.

So basically you can do alot of thigs with this. The "ref" var is particularly useful. Say you create a health house. you want them to be able to get health increase only one time. Simply make the ref something like, "healthboost". Then when the function for the heath boost is called, have it run this:

Code:
self notify("dist_heathboost");

That will end the whole distance function and they will no longer be able to get a health boost until that it is re-ran/re-created.

Any questions feel free to ask us.

OH and kiwimoosical, uh I actually mode it with modifications by antic. Your making yourself look like a moron. Antic is a really good coder, yet can be a lazy as you as times, (no offense to both of you). So stop trying to kiss peoples arses. Seriously...
 
P

P-A-T

Enthusiast
Messages
164
Reaction score
2
this is sweet. nice explanation too
 
Z

ZaCk iS BaD

Enthusiast
Messages
112
Reaction score
23
Cool Atleast You Tried Man :lol: Don't Stop
 
I

Injection

Enthusiast
Messages
657
Reaction score
82
man whats ur aim i need summ help
 
L

Lost4468

Contributor
Messages
2,202
Reaction score
1,760
Why not just use setLowerMessage instead of creating a hud element and just create a trigger.
 
Top Bottom