Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.
New to the forum? Say hello in this topic! Also make sure to read the rules.
New to the forum? Say hello in this topic! Also make sure to read the rules.
Various suggestions for IPlayer
Forum rules
By using the forum you agree to the following rules.
By using the forum you agree to the following rules.
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
Various suggestions for IPlayer
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
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
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
- Odex64
- Superfighter
- Posts: 172
- Joined: Sat Jul 29, 2017 12:39 pm
- Title: Content Creator
- SFD Account: Odex64
- Started SFD: PreAlpha
- Location: Italy
- Gender:
- Age: 22
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
UPDATE: here's the script http://sfdmaps.at.ua/load/scripts/compl ... 0-1-0-4188
0 x
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
I'll check it out, but I think we still need some scriptAPI getters to make better scripts
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
- JakSparro98
- Superfighter
- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 25
It is actually possible to "filter" died players and removed ones, according to this thread.
IPlayer.CurrentWeaponDrawn is the property for that.
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;
}
}
0 x
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
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.
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.
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
- JakSparro98
- Superfighter
- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 25
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.
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.
0 x
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
Thank you very much!
Again, thanks for answering
About that... if you know the answer I'd be very happy if you could tell me, i'm getting really stuck with that...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.
Again, thanks for answering
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.
- JakSparro98
- Superfighter
- Posts: 530
- Joined: Fri Jul 15, 2016 7:56 pm
- Started SFD: PreAlpha 1.0.5
- Location: Rome, Italy
- Gender:
- Age: 25
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:
Assigning the Button method to a trigger will wait 2 seconds before showing the text "elapsed".
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;
}
0 x
- Gurt
- Lead Programmer
- Posts: 1884
- Joined: Sun Feb 28, 2016 3:22 pm
- Title: Lead programmer
- Started SFD: Made it!
- Location: Sweden
- Gender:
- Age: 34
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
}
}
}
0 x
Gurt
- Mr Argon
- Fighter
- Posts: 56
- Joined: Sat Mar 09, 2019 2:22 am
- SFD Account: Argón (steam)
- SFD Alias: Mr. Argon
- Started SFD: Pre-Alpha 1.8.2c
- Location: Argentina
- Gender:
- Age: 20
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!
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!
0 x
I'м д Liттlэ оdd... sтill саи livе шiтн тнат.