Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you set a weapon to the player programmatically? #1

Open
meszaros-lajos-gyorgy opened this issue Jul 22, 2022 · 6 comments
Open

Comments

@meszaros-lajos-gyorgy
Copy link
Collaborator

player.setweapon bone_weap puts the correct weapon on the player's back, but in combat mode the player does not use it. Furthermore the weapon cannot be unequipped.

There seems to be no command to assign a weapon to the player ( https://wiki.arx-libertatis.org/Script:Commands )

Can I attach the weapon to the player's hand or would that be always visible even when the weapon is holstered?

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

The equip command can be used, but the weapon needs to be spawned first and the equip needs to be triggered from the weapon:

spawn item weapons/bone_weap/bone_weap marker_0001
<weapon_id>.equip player

Remaining questions before the method can be marked as fully implementable into the arena custom map:

  1. how do you get the created item's id?
  2. how do you check, if the player already holds a weapon?
  3. how do you get the id of the weapon the player is holding?
  4. can you prevent unequipping a weapon?
  5. can you detect when the player unequipped a weapon and maybe get the item's id?

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

meszaros-lajos-gyorgy commented Jul 22, 2022

Answers:

  1. Using the ^last_spawned global readonly variable
  2. You don't, you need to store the ^last_spawned id in a variable
  3. when equipping a new weapon the old will be dragged and you can call destroy on it using the variable created at 2)
  4. ?
  5. ON EQUIPOUT is triggered, but the weapon id needs to be get from the variable created at 2)

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

meszaros-lajos-gyorgy commented Jul 22, 2022

The equip command can be triggered by sending an inventoryuse event. Gluing the spawning together with equipping creates this one-liner:

spawn item "weapons/sabre_meteor/sabre_meteor" player sendevent inventoryuse ~^last_spawned~ nop

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

meszaros-lajos-gyorgy commented Jul 22, 2022

another issue: can't equip the weapon, if the stats are no met (the sabre needs 8 strength)

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

meszaros-lajos-gyorgy commented Jul 23, 2022

yet another issue: if the player is in combat mode, then the weapon is not being equipped. Any other ways to trigger the equip command from within the weapon?

@meszaros-lajos-gyorgy
Copy link
Collaborator Author

This is what I have so far for the player to make sure that it remembers the previously added weapon and destroying it upon changing the weapon:

// player.asl
ON INIT {
  SET £lastEquippedWeaponId "none"
  ACCEPT
}

ON CHANGE_WEAPON {
  iflastEquippedWeaponId != "") {
    destroy £lastEquippedWeaponId
  }
  spawn item "weapons/~^$PARAM1~/~^$PARAM1~" player
  sendevent INVENTORYUSE ~^last_spawned~ nop
  set £lastEquippedWeaponId ~^last_spawned~
  ACCEPT
}

And triggering a weapon change looks like this:

// param1:weaponType = "club"
// param2:damage = 1
sendevent change_weapon player "club 1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant