Page 1 of 1
Various suggestions for IPlayer
Posted: Thu Feb 20, 2020 2:14 pm
by Mr Argon
I have noticed that we can check if the player is a burned corpse but we can't actually check if it's a normal corpse. I mean, this is causing me a lot of trouble, PlayerDeathCallback executes when player dies and executes again if player's corpse got gibbed or fall down the map bottom. We should have something to distinguish that, or maybe just something that allows scripters to detect what killed the player: a melee attack, a gunshot, fall damage, fire or explotion.
Also, I don't remember very well what functions do we have right now, but I think there isn't something to check what weapon the player gor selected, or something to get if the player is firing, we got IsHipFiring and IsManualAiming only.
It would be great if we could get at least one of these, preferably the first one about PlayerDeathCallback
Re: Various suggestions for IPlayer
Posted: Thu Feb 20, 2020 8:53 pm
by Odex64
there's a script which tells you how a player died (fall damage, projectiles, melee etc..) by checking what kind of damage he received and some workarounds
UPDATE: here's the script
http://sfdmaps.at.ua/load/scripts/compl ... 0-1-0-4188
Re: Various suggestions for IPlayer
Posted: Thu Feb 20, 2020 9:57 pm
by Mr Argon
I'll check it out, but I think we still need some scriptAPI getters to make better scripts
Re: Various suggestions for IPlayer
Posted: Fri Feb 21, 2020 8:43 pm
by JakSparro98
Mr Argon wrote: ↑Thu Feb 20, 2020 2:14 pm
[..] PlayerDeathCallback executes when player dies and executes again if player's corpse got gibbed or fall down the map bottom. We should have something to distinguish that [..]
It is actually possible to "filter" died players and removed ones, according to
this thread.
Mr Argon wrote: ↑Thu Feb 20, 2020 2:14 pm
[..] I think there isn't something to check what weapon the player gor selected[..]
IPlayer.CurrentWeaponDrawn is the property for that.
Mr Argon wrote: ↑Thu Feb 20, 2020 2:14 pm
[..] or something to get if the player is firing, we got IsHipFiring and IsManualAiming only. [..]
You could get a pretty decent result by using the TotalShotsFired property from IPlayerStatistics inside the update callback, you store the last value into a variable and check for updates next:
Code: Select all
int LastTotalShotsFired = 0;
public void OnStartup()
{
Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float elapsed)
{
IPlayer plr = Game.GetPlayers()[0];
int CurrentTotalShotFired = plr.Statistics.TotalShotsFired;
if (CurrentTotalShotFired != LastTotalShotsFired)
{
Game.WriteToConsole("player " + plr.Name + " fired");
LastTotalShotsFired = CurrentTotalShotFired;
}
}
Re: Various suggestions for IPlayer
Posted: Fri Feb 21, 2020 9:14 pm
by Mr Argon
Thanks, that helped me. I'll open another thread later because I need some help with a custom script. Or maybe someone could answer this here. I'm having some trouble with custom commands. I can't manage to store a variable through games.
Example
private bool IsActivated = false;
public void OnStartup()
{
Events.UserMessageCallback.Start(OnCommand);
}
public void OnCommand(IPlayer player, UserMessageArgs args)
{
if (args.IsCommand && args.Command == "setenabled")
{
IsActivated = false;
}
}
IsActivated will be reset to true after map restart...
Also, is there any other way to execute a method after certain time rather than using UpdateCallback? Because update callback doesn't support method arguments, and I need to disable player input and then reactivate it after a few seconds.
Re: Various suggestions for IPlayer
Posted: Fri Feb 21, 2020 10:39 pm
by JakSparro98
For storing values between rounds/games/maps you need to use IGame.SessionStorage.SetItem (key,value) and IGame.SessionStorage.GetItem (key)
Here there is a snippet that uses LocalStorage instead, but the concept behind is the same with the exception that LocalStorage is for storing persistent data on disk.
Re: Various suggestions for IPlayer
Posted: Sat Feb 22, 2020 1:36 am
by Mr Argon
Thank you very much!
Also, is there any other way to execute a method after certain time rather than using UpdateCallback? Because update callback doesn't support method arguments, and I need to disable player input and then reactivate it after a few seconds.
About that... if you know the answer I'd be very happy if you could tell me, i'm getting really stuck with that...
Again, thanks for answering
Re: Various suggestions for IPlayer
Posted: Sat Feb 22, 2020 12:01 pm
by JakSparro98
For executing delayed functions you can create a timer and assign it a method in the script method field but will not allow for additional parameters, for that you need to measure how much time has passed and if it is enough call a custom function, you will still need to use an update loop (UpdateCallback or set the OnUpdateTrigger to call a loop function at your choice).
I personally use this approach:
Code: Select all
float CurrentTime;
bool IsButtonPressed=false;
static bool IsElapsed(float TimeStarted, float TimeToElapse)
{
if ((float)(Game.TotalElapsedGameTime - TimeStarted) >= TimeToElapse)
return true;
else
return false;
}
public void OnStartup()
{
Events.UpdateCallback.Start(OnUpdate, 0);
}
public void OnUpdate(float elapsed)
{
if(IsButtonPressed)
if(IsElapsed(CurrentTime,2000))
{
Game.ShowPopupMessage("elapsed");
IsButtonPressed=false;
}
}
public void Button(TriggerArgs arg)
{
CurrentTime=Game.TotalElapsedGameTime;
IsButtonPressed=true;
}
Assigning the Button method to a trigger will wait 2 seconds before showing the text "elapsed".
Re: Various suggestions for IPlayer
Posted: Sat Feb 22, 2020 3:06 pm
by Gurt
You can use anonomous functions for "parameter" usage with the update callback event in a fire-and-forget style coding approach:
Code: Select all
public void Button(TriggerArgs arg)
{
IObject sender = args.Sender;
Events.UpdateCallback.Start((float elapsed) => {
//This code is executed after 2 seconds.
ButtonThingy(sender);
}, 2000, 1); // execute update event after 2000 ms, 1 time.
}
public void ButtonThingy(IObject sender)
{
if (sender != null && sender is IPlayer) {
IPlayer plr = ((IPlayer)sender);
if (!plr.IsRemoved && !plr.IsDead) {
// DoStuff
}
}
}
Re: Various suggestions for IPlayer
Posted: Sat Feb 22, 2020 4:44 pm
by Mr Argon
Well, I'll try with this on my script. By the way, i have to say that I'm making a custom script so I can't actually access to the editor itself, and I think that you can't actually instantiate IObjects via code. Anyways I'm trying this.
I need this because I disabled player input and then I call a method for enabling it, but if I can't use method parameters, I'm unable to tell the method what IPlayer to reactivate.
EDIT: I tried it and it seems to work fine. Thank you very much for the help!