Jump to content

[LE] What is wrong with my script ? :)


Recommended Posts

Hello i'm Tobi !...

 

Now im trying to add new arena like in Braverock Island

 

but Braverock Island was pretty fu*ke* cause of memory leaks and crashes

well Braverock Island script was only 5 lines long xD

 

how about this script?

 

What can i fix, do better?

 

 

Scriptname QLG_Script_DeleteDead extends ObjectReference
;===- Base Info. -===;
 ;Created: 2019-03-09
 ;Author: TobiPL
 ;Unit: M.PC<3>
;===- Reward Var. setup -============================================
	
	GlobalVariable property QFameStore auto
		{Global, Fame that player have}
	
	int property QFameReward auto
		{Fame that player earn for killing this enemy}
	
	GlobalVariable property QArenaPayout auto
		{Global, Gold that player should get after win}
	
	int property QGoldReward auto
	{Gold that player earn for killing this enemy}
	
	int property QGold auto
	{ Chance to drop gold from enemy:
		value :0: -> 0%
		value :1: -> 100%
	  Any other up to 99 mean % to drop
	}
	
	bool property QIsBoss auto
	{ If this Unit is Boss Unit set it to True }
	
	string property QKillMSG auto
	{ Text to show when player have killed this unit 
	  Text will show only when :QIsBoss: is set to True }

;===- Script -Main- -================================================
Event OnDeath(Actor QKiller)

	If QKiller == Game.GetPlayer()
		If QIsBoss
			
			Debug.Notification(QKillMsg)
			;Text show when player have killed this unit
			
		EndIf
		
		Utility.Wait(35.0)		;wait for other mods to finish
		self.disable()			;disable and wait
		Utility.Wait(5.0)		;wait for some more time
		
		If QGold > 0
			If QGold == 1
				
				QArenaPayout.SetValue(QArenaPayout.GetValue() + QGoldReward)
				;for 100% chance just give player payout
				
			Else
				
				If QGold > Utility.RandomInt(0,100)
					
					QArenaPayout.SetValue(QArenaPayout.GetValue() + QGoldReward)
					;test and give player gold if test = ture
					
				EndIf
			EndIf
		EndIf
		
		QFameStore.SetValue(QFameReward+QFameStore.GetValue())
		
		Utility.Wait(60.0)		;waint for other scripts to finish
		self.delete()			;final delete
		
	EndIf
endEvent






 

 

//Edit: { just spoiler }

Edited by TobiaszPL
Link to comment
Share on other sites

You posted a single script. It's not really clear what is your aim.

The waitings are definitely too long! And the script should be extended to Actor, not ObjectReference imho.

 

QLG_DeadActorScript

 

Scriptname QLG_DeadActorScript extends Actor
; https://forums.nexusmods.com/index.php?/topic/7464626-what-is-wrong-with-my-script/

;===- Base Info. -===; original name "QLG_Script_DeleteDead"
; Created: 2019-03-09
; Author: TobiPL
; Unit: M.PC<3>

; TobiaszPL  wrote: "I am trying to add new arena like in Braverock Island.. What can i fix, do make it better?"
     
  GlobalVariable PROPERTY QFameStore   auto      ; Global, Fame that player have
  GlobalVariable PROPERTY QArenaPayout auto      ; Global, Gold that player should get after win

  MiscObject PROPERTY Gold001 auto               ; use Auto-fill

  Float PROPERTY QFameReward auto                ; Fame that player earn for killing this enemy
  Int   PROPERTY QGoldReward auto                ; Gold that player earn for killing this enemy
  Int   PROPERTY iGoldChance auto                ; Chance to drop gold from enemy: value :0: -> 0%, value :1: -> 100%, Any other up to 99 mean % to drop

 ;Bool   PROPERTY QIsBoss  auto                  ; UnUSED by now (If this Unit is Boss Unit set it to True)
  String PROPERTY QKillMSG auto                  ; if this unit is a Boss, set this to show a message when player or allied has killed them


; -- EVENTs -- 2

EVENT OnDeath(Actor akKiller)
    IF myF_IsOK(akKiller)
        myF_Action()
        Utility.Wait(5.0)    ; wait for other mods to finish
    ENDIF

    self.Delete()            ; mark as deleted, regardeless of killing actor
ENDEVENT


EVENT OnCellDetach()
    Debug.Trace(" OnCellDetach() - player has left the actors cell.. " +self)
    self.Delete()            ; just in case (have to be verified)
ENDEVENT


; -- FUNCTIONs -- 2

;-------------------------------------
Bool FUNCTION myF_IsOK(Actor akKiller)
;-------------------------------------
    actor player = Game.GetPlayer()

IF (akKiller == player)
    Return TRUE                ; killed by the player
ENDIF
;---------
;;;IF !akKiller.IsCommandedActor()
;;;    Return False    ; not commanded
;;;ENDIF
;--------- https://www.creationkit.com/index.php?title=IsHostileToActor-_Actor
IF !akKiller.IsHostileToActor(player)
    Return TRUE                ; killed by player friendly actor
ENDIF
;---------
    Return False    ; someone else
ENDFUNCTION


;--------------------
FUNCTION myF_Action()  ; player (or commanded actor) has killed the actor, which this script has been attached
;--------------------
    IF ( QKillMsg )
        Debug.Notification(QKillMsg)    ; text will be shown when player has killed the boss, if this is a boss
;;;    ELSE
;;;        Debug.Notification("Congratulation.. you win this fight!")
    ENDIF
; ---
    Utility.Wait(3.0)        ; wait some time
    self.Disable(TRUE)                                                ; disable with fading out
    Utility.Wait(1.0)        ; wait a bit
; ---
    int i = QArenaPayout.GetValueInt()                               ; minimum amount of gold
    IF (iGoldChance < 1)
        ; no gold to give to the player
    ELSEIF (iGoldChance == 1) || (iGoldChance > Utility.RandomInt(0, 100))        ; 100% chance /or/ random chance to give player more
        i = i + QGoldReward
    ENDIF

;;;    Game.GetPlayer().AddItem(Gold001 as Form, i)                    ; pay out the whole money
    QArenaPayout.SetValue(i as Float)
; ---
    float f = QFameStore.GetValue() + QFameReward
    QFameStore.SetValue(f)                                          ; adjust the global fame
ENDFUNCTION

 

 

edited later this day

Edited by ReDragon2013
Link to comment
Share on other sites

 

 

Game.GetPlayer().AddItem(Gold001 as Form, i) ; pay out the whole money

 

hehe xD no way !...

first you have to finish wave :smile:

 

My arena allow you to exit only when u finish wave and all rounds and you got your payout from NPC in Arena "Barracks"

 

thats why Arena payout is stored in Global value

1) cause many NPC may pay you

2) cause taxes lol and they change over time

3) Every arena have thier own "taxes" so not all gold is your

 

and if payout is small you can take all your gold from Arena Master

if your payout is little bigger you have to go to Arena Bank

and if your payout is REALLY REALLY BIG you have to ask in Big Fuma Bank

 

and if you WON all 120 waves ( wtf idk even how and i dont want to xD ) you have to travel to Fuma God City and take your reward from Golden Gate Bank

 

lol

 

xD

 

all i need in this script is add payout to selected Global and add Fame to selected Global

and only delete enemy body

 

 

but... why should i use Actor instead of ObjectReference ?

i was almost always using ObjectReference xD and this script is... well can't test is now but with ObjectReference is compiling fine :x...

 

no errors while compile !

 

 

 

and one more

why like this?

float f = QFameStore.GetValue() + QFameReward
QFameStore.SetValue(f) ; adjust the global fame

 

we waste one line :x

 

 

 

ok so:

1) why Actor not ObjectReference ( i want to know why !! no "JUST DO IT" xD lel )

2) why use var to store value instead of giving it to function ?

float f = QFameStore.GetValue() + QFameReward
QFameStore.SetValue(f) ; adjust the global fame

 

sry potato english :tongue:

 

 

//Edit:

Many unworth to read text :P

just added it to spoiler but keep if any1 need / rly want to read xD

Edited by TobiaszPL
Link to comment
Share on other sites

You wrote: "why Actor not ObjectReference ( i want to know why !! no "JUST DO IT")"

 

Only actors may die. Objects can be disabled and removed, but never die!
Have a look into vanilla Skyrim scripts "Actor.psc" and "ObjectReference.psc"!

 

All things that objectReferences can do, actors can also do. But some things are actor specific, like dead, equip and etc.

What do you think the native event OnDeath() is located?

 

---

 

your code

QFameStore.SetValue(QFameReward+QFameStore.GetValue())

my code

float f = QFameStore.GetValue() + QFameReward
QFameStore.SetValue(f)

It's a matter of reading and maintaining.

Edited by ReDragon2013
Link to comment
Share on other sites

Hmm :x objects can't die xD

ok ill change it from ObjectReference to Actor but it was working... not bad :D

 

Anything left to fix ? :tongue:

 

 

Scriptname QLG_Script_DeleteDead extends Actor
;===- Base Info. -===;
 ;Created: 2019-03-09
 ;Update: 2019-03-12 ( TobiPL )
 ;Author: TobiPL
 ;Unit: M.PC<3>
;===- Reward Var. setup -============================================
	
	GlobalVariable property QFameStore auto
		{Global, Fame that player have}
	
	int property QFameReward auto
		{Fame that player earn for killing this enemy}
	
	GlobalVariable property QArenaPayout auto
		{Global, Gold that player should get after win}
	
	int property QGoldReward auto
	{Gold that player earn for killing this enemy}
	
	int property QGold auto
	{ Chance to drop gold from enemy:
		value :0: -> 0%
		value :1: -> 100%
	  Any other up to 99 mean % to drop
	}
	
	bool property QIsBoss auto
	{ Only if Unit is Boss or Special }
	
	string property QKillMSG auto
	{ Text to show when player have killed this unit 
	  Text will show only if :QIsBoss: is set to True }

;===- Script -Main- -================================================
Event OnDeath(Actor QKiller)

	If QKiller == Game.GetPlayer()
		If QIsBoss
			
			Debug.Notification(QKillMsg)
			;Text show when player have killed this unit
			
		EndIf
		
		Utility.Wait(35.0)		;wait for other mods/scripts
		self.disable()			;disable and wait
		
		If QGold > Utility.RandomInt(1, 100)
		
			float QPay = QArenaPayout.GetValue() + QGoldReward
			QArenaPayout.SetValue(QPay)
			
		EndIf
		
		QFameStore.SetValue(QFameReward+QFameStore.GetValue())
		
		Utility.Wait(60.0)		;waint for other scripts to finish
		self.delete()			;final delete
		
	EndIf
EndEvent


;===- Script -===-===- ;ReDragon2013 ( NexusForum )
Event OnCellDetach()
	
	self.Delete()            ; just in case (have to be verified)
	
EndEvent







 

 

 

like for me its perfect now xD lel

 

//Edit1:

But one more question... why u use float ?

gold can't be with second number part xD sry 4 my epic english :tongue:

//Edit4:

{

ohh xD ok sorry can't compile script if its Int :D

}

 

int is bad or something ?

 

//Edit2:

and one more :D

how i can make spoilers ? i dont have button on tab abowe text field :c...

<spoiler> he ? </spoiler>

 

just testing xD

//Edit3:

<spoiler=""> meow? </spoiler>

 

//Edit5:

if its Open World OnCellDetach will work fine?

 

//Edit6:

{ just added spoiler }

Edited by TobiaszPL
Link to comment
Share on other sites

Hmm :x objects can't die xD

ok ill change it from ObjectReference to Actor but it was working... not bad :D

 

Technically, Actor extends ObjectReference and thus if the only functions / events needed were ObjectReference only then a script extending ObjectReference would work. However, because it is an actor and the chances that one day an update you make might require using Actor functions / events, extending Actor now gets you access to both Actor and ObjectReference functions / events without introducing problems down the road. Once established in a save game, the script being extended cannot change. Thus this is a change that is better to do now while building the mod than later when wanting to tweak a couple things.

 

The float in use with Qpay is because the calculated result is then used within SetValue which requires a float.

 

See my signature for instructions on how to do spoilers.

 

As far as OnCellDetach, it should work in the open world. As to whether what you want to do will work correctly or no, you'll need to test that out. Just remember that in the open world cells are loaded in a grid and the player may never actually enter some of those loaded cells.

Link to comment
Share on other sites

 

 

Yey, but why Nexus [] instead of < > xD

 

 

 

ok ty u all 4 help :D !

 

for 4 years i was using mostly russian websites and i was uploading only in russia but when i ask 4 help almost no1 were to help me :c

looks like Nexus is much better place than russia if looking 4 help :tongue:

 

well this gonna be my first Mod uploaded ( and not deleted ) on Nexus ^_^

 

 

if any admin want to, you can close this topic and mark it as solved :tongue:

 

//Edit:

Final version if any1 need :x...

 

 

 

Scriptname QLG_Script_DeleteDead extends Actor
;===- Base Info. -===;
 ;Created: 2019-03-09
 ;Update: 2019-03-12 ( TobiPL )
 ;Author: TobiPL
 ;Unit: M.PC<3>
;===- Var. setup -============================================


;===- Fame -===
	GlobalVariable property QFameStore auto
	{ Global, Fame that player have }
	
	int property QFameReward auto
	{ Fame that player earn for killing this enemy }
	
	
;===- Gold -===
	GlobalVariable property QArenaPayout auto
	{ Global, Gold that player should get after win }
	
	int property QGold auto
	{ Chance to drop gold }
	
	int property QGoldReward auto
	{ Gold that player earn for killing this enemy }
	
	int property QGoldOff auto
	{ Gold offset for killing Monsters
		example:
		  Set =20= mean +/- 10 Gold
		  Set =60= mean +/- 30 Gold
		This value shouldn't be bigger than QGoldReward
	}
	

;===- Messages -===	
	bool property QIsBoss auto
	{ Only if Unit is Boss or Special }
	
	string property QKillMsg auto
	{ Text to show when player have killed this unit 
	  Text will show only if :QIsBoss: is set to True }





;===- Script -Main- -================================================
Event OnDeath(Actor QKiller)

	If QKiller == Game.GetPlayer()
		If QIsBoss
			
			Debug.Notification(QKillMsg)
			
		EndIf
		
		Utility.Wait(35.0)		;wait for other mods/scripts
		self.disable()			;disable and wait
		
		If QGold > Utility.RandomInt(0, 100)
		
			float QOff = Utility.RandomInt( -QGoldOff / 2, QGoldOff / 2 )
			float QPay = QArenaPayout.GetValue() + QGoldReward
			
			If QPay > 0
			
				QArenaPayout.SetValue( QPay + QOff )
			
			EndIf
		EndIf
		
		int Fame = QFameStore.GetValue() + QFameReward
		QFameStore.SetValue( Fame )
		
		Utility.Wait(60.0)		;wait for other mods/scripts to finish
		self.delete()			;final delete
		
	EndIf
EndEvent


;===- Script -===-===- ;ReDragon2013 ( NexusForum )
Event OnCellDetach()
	
	self.Delete()            ;just in case (have to be verified)
	
EndEvent







 

 

//Edit2:

i hope there is no more errors :D

Edited by TobiaszPL
Link to comment
Share on other sites

Can you remember what Rasikko posted: "Change SetValue to Mod."

 

Tutorial you'll find here: https://www.creationkit.com/index.php?title=Mod_-_GlobalVariable

Make sure your browser has cookies enabled to bypass the start page.

 

instead of

 int Fame = QFameStore.GetValue() + QFameReward
 QFameStore.SetValue( Fame )

use that for thread safe scripting:

  Float property QFameReward auto
 { Fame that player earn for killing this enemy }


QFameStore.Mod(QFameReward)

The problem with long waitings keeps alive. Use a controller quest script to count dying of NPCs. Its much more useful than long time wait.

 

my version as follow

 

Scriptname QLG_Script_DeleteDead extends Actor
;===- Base Info. -===;
;Created: 2019-03-09
;Update: 2019-03-12 ( TobiPL )
;Author: TobiPL
;Unit: M.PC<3>

;===- Fame -===
    GlobalVariable PROPERTY QFameStore auto
    { Global, Fame that player have }
    
    Float PROPERTY QFameReward auto
    { Fame that player earn for killing this enemy }
    
;===- Gold -===
    GlobalVariable PROPERTY QArenaPayout auto
    { Global, Gold that player should get after win }
    
    Int PROPERTY iGoldChance auto
    { Chance to drop gold }
    
    Int PROPERTY iGoldReward auto                     ; [default=0], make sure this is positive
    { Gold that player earn for killing this enemy }
    
    Int PROPERTY iGoldVariance auto
    { Gold offset for killing Monsters
        example:
         Set =20= mean +/- 10 Gold
         Set =60= mean +/- 30 Gold
        This value should not be bigger than iGoldReward  }
    
;===- Messages -===    
    ;Bool property QIsBoss auto          ; UnUSED by now
    { Only if Unit is Boss or Special }
    
    String PROPERTY QKillMsg auto
    { Text to show when player has killed this unit, Text will be shown only if this is a Boss }


;===- Script -Main- -================================================
EVENT OnDeath(Actor akKiller)
    IF (akKiller == Game.GetPlayer())
        IF ( QKillMsg )
            Debug.Notification(QKillMsg)
        ENDIF

        IF (iGoldChance > Utility.RandomInt(0, 100))
            int i = iGoldVariance / 2
            i = Utility.RandomInt( -i, i)
  
            int r = QArenaPayout.GetValueInt() + iGoldReward     
            IF (r > i)
                QArenaPayout.SetValue( (r + i) as Float )
            ENDIF
        ENDIF

        Utility.Wait(35.0)     ; wait for other mods/scripts
        self.Disable()         ; disable, not fading out
      
        QFameStore.Mod( QFameReward )
        
        Utility.Wait(60.0)     ;wait for other mods/scripts to finish
        self.Delete()          ;final delete
    ENDIF
ENDEVENT


;===- Script -===-===- ;ReDragon2013 ( NexusForum )
EVENT OnCellDetach()
    self.Delete()    ; just in case (have to be verified)  
ENDEVENT

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...