[ACTION MAKER][WEAPON][SCRIPT][SOLVED] Yield

Moderator: NADEO

Post Reply
User avatar
weerwolf
Posts: 630
Joined: 15 Jun 2010, 21:21
Location: Wijchen, Netherlands
Contact:

[ACTION MAKER][WEAPON][SCRIPT][SOLVED] Yield

Post by weerwolf » 27 Feb 2019, 23:52

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
:roflol:
Last edited by weerwolf on 02 Mar 2019, 20:03, edited 1 time in total.

User avatar
chco
Posts: 301
Joined: 24 Dec 2012, 09:11

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield

Post by chco » 28 Feb 2019, 09:39

:pop:
Lol
Image

User avatar
Miss
Posts: 2112
Joined: 05 Jan 2016, 11:34
Location: The Netherlands
Contact:

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield

Post by Miss » 28 Feb 2019, 10:50

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?
1070 GTX, Ryzen 3700X, 16GB RAM, Windows 10
Forum moderator, opinions are my own. :thx:
Check out Image openplanet, the alternative ManiaPlanet & Turbo scripting platform! (Openplanet subforum)
I also stream on Twitch and tweet on Twitter.

User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield

Post by Eole » 28 Feb 2019, 14:16

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
  }
}
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!

User avatar
weerwolf
Posts: 630
Joined: 15 Jun 2010, 21:21
Location: Wijchen, Netherlands
Contact:

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield

Post by weerwolf » 28 Feb 2019, 22:34

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

User avatar
Eole
Nadeo
Nadeo
Posts: 1265
Joined: 26 Apr 2011, 21:08

Re: [ACTION MAKER][WEAPON][SCRIPT] Yield

Post by Eole » 01 Mar 2019, 15:20

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;
	}
}
Contribute to the ManiaPlanet documentation on GitHub
A question about ManiaScript? Ask it here!

Post Reply

Return to “ActionMaker and Item editor”

Who is online

Users browsing this forum: No registered users and 1 guest