Sweetgebus Posted yesterday at 03:53 AM Author Posted yesterday at 03:53 AM 2 minutes ago, Josh said: You'd probably want a separate script that you add to each powerup object. Ok, is there something I need to do to include the script within the player script? Quote
Josh Posted yesterday at 04:08 AM Posted yesterday at 04:08 AM No, the engine will load both scripts. Quote Let's build cool stuff and have fun.
Sweetgebus Posted yesterday at 04:12 AM Author Posted yesterday at 04:12 AM 3 minutes ago, Josh said: No, the engine will load both scripts. Thank you, I wasn't sure if I had to manual include it Quote
Sweetgebus Posted 4 hours ago Author Posted 4 hours ago I'm a lost ball in tall weeds. Josh, would I just need to add a collision function to the powerup entity? such as slowedSpeed = {} slowedSpeed.name = "slowedSpeed" function slowedSpeed:Start() --set the trigger properties self:SetCollisionType(COLLISION_TRIGGER) end function slowedSpeed:Collide(entity) if entity:GetCollisionType() == COLLISION_PLAYER then myPlayer.speed = 140 end end I have the myPlayer.speed = 10 at the top of my player script. Obviously this isn't right because its not working. Am I going about this the wrong way? Quote
Sweetgebus Posted 4 hours ago Author Posted 4 hours ago (edited) 39 minutes ago, Sweetgebus said: I'm a lost ball in tall weeds. Josh, would I just need to add a collision function to the powerup entity? such as slowedSpeed = {} slowedSpeed.name = "slowedSpeed" function slowedSpeed:Start() --set the trigger properties self:SetCollisionType(COLLISION_TRIGGER) end function slowedSpeed:Collide(entity) if entity:GetCollisionType() == COLLISION_PLAYER then myPlayer.speed = 140 end end I have the myPlayer.speed = 10 at the top of my player script. Obviously this isn't right because its not working. Am I going about this the wrong way? ignore that, I'm an idiot. This is was an issue within my player script, I did infact have a global variable, myPlayer.speed = 10. The issue was that I was never using it. The above code does infact work. Edited 4 hours ago by Sweetgebus Quote
Sweetgebus Posted 2 hours ago Author Posted 2 hours ago I have the script working the way I was expecting to. I just want to post what I have so others can view it. I welcome any feed back, it helps me learn. Maybe there is a better way? or maybe this way will lead to issues later? Your feed back will help with this, and help me by preventing bad habits. Here is my powerup script. slowedSpeed = {} slowedSpeed.name = "slowedSpeed" function slowedSpeed:Start() self.window = ActiveWindow() --set the trigger properties self:SetCollisionType(COLLISION_TRIGGER) end function slowedSpeed:Collide(entity) if entity:GetCollisionType() == COLLISION_PLAYER then inventory.slot1 = 1 end end function onEffect() slowtimer = CreateTimer(5000) ListenEvent(EVENT_TIMERTICK,slowtimer,effectTimer) myPlayer.speed = 5 end function effectTimer() slowtimer:Stop() myPlayer.speed = 10 inventory.slot1 = inventory.slot1 - 1 end It creates the effect, but stores it for later use, I created a inventory table within my player script that holds the value. inventory = {} iventory.slot1 = 0 Below is how I went about using the powerup in my player script. I first check to make sure if I have a power up available. If so, when the player presses the T key, the powerup script is executed for the set duration. -- player effects if self.window:KeyHit(KEY_T) and inventory.slot1 >= 1 then Print("Buff Active") onEffect() end Ignore the Prints, they are just there for debugging purposes. If there is at least 1 power up stored in inventory.slot 1, the onEffect() function from the powerup script is called. Quote
Sweetgebus Posted 2 hours ago Author Posted 2 hours ago (edited) 2 minutes ago, Sweetgebus said: I have the script working the way I was expecting to. I just want to post what I have so others can view it. I welcome any feed back, it helps me learn. Maybe there is a better way? or maybe this way will lead to issues later? Your feed back will help with this, and help me by preventing bad habits. Here is my powerup script. slowedSpeed = {} slowedSpeed.name = "slowedSpeed" function slowedSpeed:Start() self.window = ActiveWindow() --set the trigger properties self:SetCollisionType(COLLISION_TRIGGER) end function slowedSpeed:Collide(entity) if entity:GetCollisionType() == COLLISION_PLAYER then inventory.slot1 = 1 end end function onEffect() slowtimer = CreateTimer(5000) ListenEvent(EVENT_TIMERTICK,slowtimer,effectTimer) myPlayer.speed = 5 end function effectTimer() slowtimer:Stop() myPlayer.speed = 10 inventory.slot1 = inventory.slot1 - 1 end It creates the effect, but stores it for later use, I created a inventory table within my player script that holds the value. inventory = {} iventory.slot1 = 0 Below is how I went about using the powerup in my player script. I first check to make sure if I have a power up available. If so, when the player presses the T key, the powerup script is executed for the set duration. -- player effects if self.window:KeyHit(KEY_T) and inventory.slot1 >= 1 then Print("Buff Active") onEffect() end Ignore the Prints, they are just there for debugging purposes. If there is at least 1 power up stored in inventory.slot 1, the onEffect() function from the powerup script is called. P.S, I'm aware that I do not need self.window = ActiveWindow() in the powerup script. Just pretend it isn't there. Edited 2 hours ago by Sweetgebus Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.