Page 1 of 1
[ACTION MAKER][WEAPON][SCRIPT][SOLVED] Yield
Posted: 27 Feb 2019, 23:52
by weerwolf
Code: Select all
#RequireContext CSmAction
#Include "TextLib" as TextLib
#Setting C_Cooldown 300
#Setting C_EnergyCost 1600
#Setting C_EnergyMax 6400
#Setting C_EnergyReload True
#Const C_LaserName1 "Beam 1"
#Const C_ProjectileName1 "Projectile 1"
#Const C_AnimName "Anim1"
Cooldown = C_Cooldown;
EnergyMax = C_EnergyMax;
EnergyCost = C_EnergyCost;
EnergyReload = C_EnergyReload;
declare AnimId0 = Anim_GetModelId(C_AnimName);
// MP3 - declare AnimId0 = GetAnimModelId(C_AnimName);
declare LaserId1 = Projectile_GetModelId(C_LaserName1);
declare ProjectileId1 = Projectile_GetModelId(C_ProjectileName1);
// MP3 - declare LaserId1 = GetProjectileModelId(C_LaserName1);
// MP3 - declare ProjectileId1 = GetProjectileModelId(C_ProjectileName1);
while (True) {
foreach (Event in PendingEvents) {
switch (Event.Type) {
case CSmActionEvent::EType::OnHitPlayer : {
// MP3 - SendRulesEvent("damage", [TextLib::ToText(Event.Damage)], Owner, Event.Player);
SendRulesEvent("damage", [TextLib::ToText(Event.Damage)], Owner, Event.Victim);
}
}
}
if (Owner != Null && Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned && IsActive && (Energy >= EnergyCost) && Cooldown_IsReady() && !Owner.IsOnTechNoWeapon && !Owner.IsInWater ) {
Cooldown_Start();
// MP3 if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned && IsActive && (Energy >= EnergyCost) && Cooldown_IsReady(Now) && !Owner.IsOnTechNoWeapon && !Owner.IsInWater ) {
Cooldown_Start();
Energy -= EnergyCost;
declare Anim0 = Anim_PlayOnPlayer(AnimId0, Owner);
// MP 3-PlayAnimOnPlayer(AnimId0, Owner);
declare Laser1 = Projectile_CreateOnPlayer(LaserId1, Owner);
// MP3 -CreateShoot(Owner, LaserId1);
declare Proj1 = Projectile_CreateOnPlayer(ProjectileId1, Owner);
// MP3 -CreateShoot(Owner, ProjectileId1);
SendRulesEvent("fire", [], Owner, Null);
}
yield;
}
Error [48,8] 'yield' is not allowed in this script. Script compilation failed
After removing yield:
This script is using too many resources. This script should call yield more often

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield
Posted: 28 Feb 2019, 09:39
by chco
Lol
Re: [ACTION MAKER][WEAPON][SCRIPT] Yield
Posted: 28 Feb 2019, 10:50
by Miss
According to
the documentation, actions are one-shot actions, not continuing actions. So, making it a yieldable function wouldn't really work (as it's not called/resumed each frame).
Perhaps you want to write this code elsewhere, like in a gamemode?
Re: [ACTION MAKER][WEAPON][SCRIPT] Yield
Posted: 28 Feb 2019, 14:16
by Eole
The script of your action should be in a
main() function. This function will be called at each yield by the engine, so you do not need to yield yourself.
Code: Select all
#RequireContext CSmAction
// The function is executed at each yield
main() {
declare Integer SomeVariable; // Will be back to 0 each time
declare Integer AnotherVariable for This; // Will keep its previous value
foreach (Event in PendingEvents) {
// Do things with the events generated for this yield
}
}
Re: [ACTION MAKER][WEAPON][SCRIPT] Yield
Posted: 28 Feb 2019, 22:34
by weerwolf
Ty Eole,
I have written it this way
Code: Select all
// BeamMiniNuclear
// Fires a beam and creates mini mushroom explosion at hitpoint
// Version 28-02-2019
// Changes MP3 > MP4 :
// GetAnimModelId replaced by Anim_GetModelId
// GetProjectileModelId replaced by Projectile_GetModelId
// Event.Player replaced by Event.Victim
// PlayAnimOnPlayer replaced by Anim_PlayOnPlayer
#RequireContext CSmAction
#Include "TextLib" as TextLib
#Setting C_Cooldown 300
#Setting C_EnergyCost 1600
#Setting C_EnergyMax 6400
#Setting C_EnergyReload True
#Const C_LaserName1 "Beam 1"
#Const C_ProjectileName1 "Projectile 1"
#Const C_AnimName "Anim1"
// MP4 - Main fuction . This function will be called at each yield by the engine
main() {
declare Integer SomeVariable;
Cooldown = C_Cooldown;
EnergyMax = C_EnergyMax;
EnergyCost = C_EnergyCost;
EnergyReload = C_EnergyReload;
declare AnimId0 = Anim_GetModelId(C_AnimName);
declare LaserId1 = Projectile_GetModelId(C_LaserName1);
declare ProjectileId1 = Projectile_GetModelId(C_ProjectileName1);
foreach (Event in PendingEvents) {
switch (Event.Type) {
case CSmActionEvent::EType::OnHitPlayer : {
SendRulesEvent("damage", [TextLib::ToText(Event.Damage)], Owner, Event.Victim);
}
}
}
if (Owner != Null && Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned && IsActive && (Energy >= EnergyCost) && Cooldown_IsReady() && !Owner.IsOnTechNoWeapon && !Owner.IsInWater ) {
Cooldown_Start();
Energy -= EnergyCost;
declare Anim0 = Anim_PlayOnPlayer(AnimId0, Owner);
declare Laser1 = Projectile_CreateOnPlayer(LaserId1, Owner);
declare Proj1 = Projectile_CreateOnPlayer(ProjectileId1, Owner);
SendRulesEvent("fire", [], Owner, Null);
}
}
And it compiles without errors, and can be tested.
Still can't fire weapons as mention here
viewtopic.php?f=520&t=45567
Re: [ACTION MAKER][WEAPON][SCRIPT] Yield
Posted: 01 Mar 2019, 15:20
by Eole
Indeed, it seems there is a problem with the
EnergyReload property. What you can do in the meantime is to replace the line
EnergyReload = C_EnergyReload; by this:
Code: Select all
// EnergyReload = C_EnergyReload;
if (Energy < EnergyMax) {
Energy += 10;
if (Energy > EnergyMax) {
Energy = EnergyMax;
}
}