FOnline Development > General Discussion

Auto-aim

(1/3) > >>

Plech:
Hello everyone. Can anyone please help me with making of auto-aim? im lil lost :/

wladimiiir:
You have to set aim variable to desired hit location in client_main.fos:

--- Code: ---void hit_aim( uint8& aim )
{
if(GetAutoAim() == HIT_LOCATION_UNCALLED || GetAutoAim() == HIT_LOCATION_NONE)
return;

CritterCl@ chosen = GetChosen();
if(!valid(chosen))
return;

uint8 mode = 0;
ProtoItem@ proto = chosen.GetSlotProto(SLOT_HAND1, mode);
if(mode == 0 && proto.Weapon_Aim_0 && chosen.Trait[TRAIT_FAST_SHOT] == 0)
aim = GetAutoAim();
}
--- End code ---

GetAutoAim() should return value you have set up via shortkeys or via GUI actions (one of the HIT_LOCATION_* values).

The following solution will change autoaim with clicking on bottom-right corner of weapon slot (where "target" icon appears).

File: auto_aim.fos (don't forget to add "@ client module auto_aim" to scripts.cfg)

--- Code: ---#include "_client_defines.fos"
#include "client_gui_h.fos"
#include "_colors.fos"
#include "_macros.fos"

uint8 autoAim = HIT_LOCATION_UNCALLED;
IGUIElementTextOpt@ AutoAimText;

//import void InitAutoAim() from "auto_aim";
void InitAutoAim()
{
@AutoAimText = GUI_AddText(CLIENT_MAIN_SCREEN_GAME, "", 575, 95)
.TextOptions(FONT_FAT, COLOR_SAND, FT_CENTERR)
.TextBoxSize(30, 20)
;
GUI_AddButton(CLIENT_MAIN_SCREEN_GAME, 585, 95)
.ClickableZone(20, 20)
.CallbackMouseClick(ChangeAutoAimAction())
.CallbackDraw(AutoAimDrawer())
;
}

//import uint8 GetAutoAim() from "auto_aim";
uint8 GetAutoAim()
{
return autoAim;
}

class ChangeAutoAimAction : IGUIElementCallbackMouseClick
{
void OnMouseClick(int id, int click) override
{
if(click == MOUSE_CLICK_LEFT)
autoAim = (autoAim + 1) % (HIT_LOCATION_GROIN + 1);
else if(click == MOUSE_CLICK_RIGHT)
if(autoAim == 0)
autoAim = HIT_LOCATION_GROIN;
else
autoAim--;
}

}

class AutoAimDrawer : IGUIElementCallbackDraw
{
void OnDraw(int) override
{
if(!valid(AutoAimText))
InitAutoAim();

RefreshAutoAimText();
}

void RefreshAutoAimText()
{
CritterCl@ chosen = GetChosen();
if(!valid(chosen))
return;

ItemCl@ item = chosen.GetItem(0, SLOT_HAND1);
if(valid(item))
{
int use = _WeaponModeUse(item.Mode);
int aim = _WeaponModeAim(item.Mode);
if(use != 0 || (aim != HIT_LOCATION_NONE && aim != HIT_LOCATION_UNCALLED))
{
AutoAimText.setText("");
return;
}
}


string text = "";
switch(autoAim)
{
case HIT_LOCATION_EYES:
text = "E";
break;
case HIT_LOCATION_HEAD:
text = "H";
break;
case HIT_LOCATION_TORSO:
text = "T";
break;
case HIT_LOCATION_LEFT_ARM:
text = "LA";
break;
case HIT_LOCATION_RIGHT_ARM:
text = "RA";
break;
case HIT_LOCATION_LEFT_LEG:
text = "LL";
break;
case HIT_LOCATION_RIGHT_LEG:
text = "RL";
break;
case HIT_LOCATION_GROIN:
text = "G";
break;
}

AutoAimText.setText(text);
}
}

--- End code ---

In client_main.fos add imports from auto_aim.fos and add InitAutoAim(); to start() method.

Hope it helps. ;)

Plech:
a few errors scared me :D

--- Code: ---[01:19:165] Script message: auto_aim : Error : Identifier 'IGUIElementTextOpt' is not a data type : 91, 1.
[01:19:165] Script message: auto_aim : Error : Missing implementation of 'void IGUIElementCallbackMouseClick::OnMouseClick(int)' : 111, 7.
[01:19:165] Script message: auto_aim : Error : Method 'void ChangeAutoAimAction::OnMouseClick(int, int)' marked as override but does not replace any base class or interface method : 111, 7.
[01:19:165] Script message: auto_aim : Error : Missing implementation of 'void IGUIElementCallbackDraw::OnDraw()' : 126, 7.
[01:19:165] Script message: auto_aim : Error : Method 'void AutoAimDrawer::OnDraw(int)' marked as override but does not replace any base class or interface method : 126, 7.
[01:19:166] Script message: auto_aim : Info : Compiling void AutoAimDrawer::OnDraw(int) : 128, 2.
[01:19:166] Script message: auto_aim : Error : Object handle is not supported for this type : 130, 8.
[01:19:166] Script message: auto_aim : Error : Expression must be of boolean type : 130, 6.
[01:19:167] Script message: auto_aim : Info : Compiling void AutoAimDrawer::RefreshAutoAimText() : 136, 2.
[01:19:167] Script message: auto_aim : Error : Illegal operation on 'int&' : 149, 16.
[01:19:167] Script message: auto_aim : Error : Illegal operation on 'int&' : 183, 14.
[01:19:168] Script message: auto_aim : Info : Compiling void InitAutoAim() : 93, 1.
[01:19:168] Script message: auto_aim : Error : No matching signatures to 'GUI_AddText(const uint, string@&, const uint, const uint)' : 95, 15.
[01:19:168] Script message: auto_aim : Error : Illegal operation on 'const int' : 96, 2.
[01:19:168] Script message: auto_aim : Error : Object handle is not supported for this type : 95, 2.
[01:19:168] Script message: auto_aim : Error : No matching signatures to 'GUI_AddButton(const uint, const uint, const uint)' : 99, 2.
[01:19:168] Script message: auto_aim : Error : Illegal operation on 'const int' : 100, 2.
[01:19:169] Script::LoadScript - Unable to Build module<auto_aim>, result<-1>.
[01:19:169] FOServer::ReloadClientScripts - Unable to load client script<auto_aim>.
[01:19:170] Script::BindImportedFunctions - Fail to bind imported functions, module<client_main>, error<-19>.

--- End code ---

Plech:
now its without errors but still dont works.

--- Code: ---#include "_client_defines.fos"
#include "client_gui_h.fos"
#include "_colors.fos"
#include "_macros.fos"

uint8 autoAim = HIT_LOCATION_UNCALLED;
IGUIElementOpt@ AutoAimText;

//import void InitAutoAim() from "auto_aim";
void InitAutoAim()
{
@AutoAimText = GUI_AddScreenElement(CLIENT_MAIN_SCREEN_GAME, "", 575, 95)
.Text("N",FONT_FALLOUT, COLOR_SAND, COLOR_RED, FT_CENTERR)
//.TextBoxSize(30, 20)
;
GUI_AddScreenElement(CLIENT_MAIN_SCREEN_GAME, "", 585, 95)
//.ClickableZone(20, 20)
.CallbackMouseClick(ChangeAutoAimAction())
.CallbackDraw(AutoAimDrawer())
;
}

//import uint8 GetAutoAim() from "auto_aim";
uint8 GetAutoAim()
{
return autoAim;
}

class ChangeAutoAimAction : IGUIElementCallbackMouseClick
{
void OnMouseClick(int click) //override
{
if(click == MOUSE_CLICK_LEFT)
autoAim = (autoAim + 1) % (HIT_LOCATION_GROIN + 1);
else if(click == MOUSE_CLICK_RIGHT)
if(autoAim == 0)
autoAim = HIT_LOCATION_GROIN;
else
autoAim--;
}

}

class AutoAimDrawer : IGUIElementCallbackDraw
{
void OnDraw() //override
{
if(!valid(AutoAimText))
InitAutoAim();

RefreshAutoAimText();
}

void RefreshAutoAimText()
{
CritterCl@ chosen = GetChosen();
if(!valid(chosen))
return;

ItemCl@ item = chosen.GetItem(0, SLOT_HAND1);
if(valid(item))
{
int use = _WeaponModeUse(item.Mode);
int aim = _WeaponModeAim(item.Mode);
if(use != 0 || (aim != HIT_LOCATION_NONE && aim != HIT_LOCATION_UNCALLED))
{
AutoAimText.Text("N",FONT_FALLOUT, COLOR_SAND, COLOR_RED, FT_CENTERR);
return;
}
}


string text = "N";
switch(autoAim)
{
case HIT_LOCATION_EYES:
text = "E";
break;
case HIT_LOCATION_HEAD:
text = "H";
break;
case HIT_LOCATION_TORSO:
text = "T";
break;
case HIT_LOCATION_LEFT_ARM:
text = "LA";
break;
case HIT_LOCATION_RIGHT_ARM:
text = "RA";
break;
case HIT_LOCATION_LEFT_LEG:
text = "LL";
break;
case HIT_LOCATION_RIGHT_LEG:
text = "RL";
break;
case HIT_LOCATION_GROIN:
text = "G";
break;
}

AutoAimText.Text(text,FONT_FALLOUT, COLOR_SAND, COLOR_RED, FT_CENTERR);
}
}
--- End code ---

any ideas?

wladimiiir:

--- Quote from: Plech on February 26, 2013, 07:43:39 pm ---now its without errors but still dont works.

--- End quote ---
It depends on how you have solved it. :)

Navigation

[0] Message Index

[#] Next page

Go to full version